public PatternMap FindPatterns(GoBoard goBoard, Color playerToMove) { PatternMap lPatternMap = new PatternMap(goBoard, playerToMove); if (DFAMatrix == null) { return(lPatternMap); } for (int lOrigin = 0; lOrigin < goBoard.Coord.BoardArea; lOrigin++) { if (goBoard.GetSafetyStatus(lOrigin).IsUndecided) { if (goBoard.IsLegal(lOrigin, playerToMove)) { Coordinate lStart = new Coordinate(goBoard.Coord.GetColumn(lOrigin), goBoard.Coord.GetRow(lOrigin)); int lState = 1; Coordinate lSpiral = new Coordinate(0, 0); while (true) { Coordinate lAt = lStart + lSpiral; lSpiral.SpiralNext(); char c = '#'; if (lAt.IsOnBoard(goBoard.BoardSize)) { c = goBoard.GetColor(goBoard.Coord.At(lAt.X, lAt.Y)).ToChar(); if (playerToMove.IsBlack) { // patterns are stored in white moves next // so flip colors when is black's turn if (c == 'O') { c = 'X'; } else if (c == 'X') { c = 'O'; } } } lState = DFAMatrix.GetPatterns(lState, c, lPatternMap, lStart, lOrigin); if (lState == 0) { break; } } } } } return(lPatternMap); }
public override TriState IsGoalAccomplished() { Color lColor = Board.GetColor(BlockPosition); SafetyStatus lSafety = Board.GetSafetyStatus(BlockPosition); if (lColor == Player) { if (lSafety.IsAlive) { return(TriState.True); } if (lSafety.IsDead) { return(TriState.False); } } else if (lColor == Player.Opposite) { if (lSafety.IsAlive) { return(TriState.False); } if (lSafety.IsDead) { return(TriState.True); // well, maybe (turned into safe territory) } } else if (lColor == Color.Empty) { if (lSafety.IsTerritory && lSafety.Player == Player) { return(TriState.True); // well, maybe (turned into safe territory) } if (lSafety.IsTerritory && lSafety.Player == Player.Opposite) { return(TriState.False); } } return(TriState.Unknown); }
public static int LibertyCountAfterMove(GoBoard goBoard, Color player, int move) { if (!goBoard.GetColor(move).IsEmpty) { return(0); // invalid } if (goBoard.IsSuicide(move, player)) { return(0); } goBoard.PlayStone(move, player, true); int lLiberities = goBoard.GetBlockLibertyCount(move); goBoard.Undo(); return(lLiberities); }
public GoalSave(GoBoard goBoard, int pBlockPosition) { Board = goBoard; BlockPosition = pBlockPosition; Player = Board.GetColor(pBlockPosition); }
public PatternMap FindPatterns(GoBoard goBoard, Color playerToMove, List<int> legalMoves) { PatternMap lPatternMap = new PatternMap(goBoard, playerToMove); if (DFAMatrix == null) return lPatternMap; foreach (int lOrigin in legalMoves) { int lState = 1; Coordinate lStart = new Coordinate(goBoard.Coord.GetColumn(lOrigin), goBoard.Coord.GetRow(lOrigin)); Coordinate lSpiral = new Coordinate(0, 0); while (true) { Coordinate lAt = lStart + lSpiral; lSpiral.SpiralNext(); char c = '#'; if (lAt.IsOnBoard(goBoard.BoardSize)) { c = goBoard.GetColor(goBoard.Coord.At(lAt.X, lAt.Y)).ToChar(); if (playerToMove.IsBlack) { // patterns are stored in white moves next // so flip colors when is black's turn if (c == 'O') c = 'X'; else if (c == 'X') c = 'O'; } } lState = DFAMatrix.GetPatterns(lState, c, lPatternMap, lStart, lOrigin); if (lState == 0) break; } } return lPatternMap; }
public static int LibertyCountAfterMove(GoBoard goBoard, Color player, int move) { if (!goBoard.GetColor(move).IsEmpty) return 0; // invalid if (goBoard.IsSuicide(move, player)) return 0; goBoard.PlayStone(move, player, true); int lLiberities = goBoard.GetBlockLibertyCount(move); goBoard.Undo(); return lLiberities; }