import type { CoreState , EnemyAi } from '../components/Game/Game.jsx' ; type Step = 1 | 2 | 3 | 4 ; type BrzAiState = { step : Step ; displayPiece : 'S' | 'Z' ; seenWells : number [ ] [ ] ; } ; export const brzAi = ( currentCoreState , currentAiState , getNextCoreStates ) : [ string , BrzAiState ] => { if ( currentAiState === undefined ) { currentAiState = { step : 1 , displayPiece : 'S' , seenWells : [ ] } ; } let nextAiState ; if ( currentAiState . step === 1 ) { const cycleDetected = currentAiState . seenWells . some ( seenWell => seenWell . every ( ( row , y ) => row === currentCoreState . well [ y ] ) ) ; if ( cycleDetected ) { nextAiState = { step : 2 , displayPiece : 'Z' , seenWells : [ ... currentAiState . seenWells , currentCoreState . well ] } ; } else { nextAiState = { step : 1 , displayPiece : 'S' , seenWells : [ ... currentAiState . seenWells , currentCoreState . well ] } ; } } else if ( currentAiState . step === 2 ) { nextAiState = { step : 3 , displayPiece : 'Z' , seenWells : [ ] } ; } else if ( currentAiState . step === 3 ) { const cycleDetected = currentAiState . seenWells . some ( seenWell => seenWell . every ( ( row , y ) => row === currentCoreState . well [ y ] ) ) ; if ( cycleDetected ) { nextAiState = { step : 4 , displayPiece : 'S' , seenWells : [ ... currentAiState . seenWells , currentCoreState . well ] } ; } else { nextAiState = { step : 3 , displayPiece : 'Z' , seenWells : [ ... currentAiState . seenWells , currentCoreState . well ] } ; } } else { nextAiState = { step : 1 , displayPiece : 'S' , seenWells : [ ] } ; } return [ currentAiState . displayPiece , nextAiState ] ; } ;