public static int IsSafeXMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters) { Color lPlayer = player.Opposite; return(((goBoard.IsLegal(parameters[0], lPlayer)) && (LibertyCountAfterMove(goBoard, lPlayer, parameters[0]) > 1)) ? TRUE : FALSE); }
// marked to be depreciated public static int FindAnySafeInOwnTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove)) { if (goBoard.IsLegal(lPoint, playerToMove)) { goBoard.PlayStone(lPoint, playerToMove, true); SafetyStatus lSafetyStatusAfter = goBoard.GetSafetyStatus(lPoint); goBoard.Undo(); // it's still safe after move, so return it if ((lSafetyStatus.IsAlive) && (lSafetyStatus.Player == playerToMove)) { return(lPoint); } } } } return(CoordinateSystem.PASS); }
// marked to be depreciated public static List <int> GetSafeMovesInOwnTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame List <int> lMoves = new List <int>(); for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove)) { if (goBoard.IsLegal(lPoint, playerToMove)) { goBoard.PlayStone(lPoint, playerToMove, true); SafetyStatus lSafetyStatusAfter = goBoard.GetSafetyStatus(lPoint); // check if still safe after move if (lSafetyStatusAfter.IsAlive) // && (lSafetyStatus.Player == playerToMove)) { lMoves.Add(lPoint); } goBoard.Undo(); } } } return(lMoves); }
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); }
// marked to be depreciated public static int FindAnyMoveInOpponentsTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove.Opposite)) if (goBoard.IsLegal(lPoint, playerToMove)) return lPoint; } return CoordinateSystem.PASS; }
// marked to be depreciated public static int FindAnyMoveInOpponentsTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove.Opposite)) { if (goBoard.IsLegal(lPoint, playerToMove)) { return(lPoint); } } } return(CoordinateSystem.PASS); }
// marked to be depreciated public static List <int> GetLegalSafeMoves(GoBoard goBoard, Color playerToMove) { List <int> lMoves = new List <int>(); for (int i = 0; i < goBoard.Coord.BoardArea; i++) { if (goBoard.IsLegal(i, playerToMove)) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(i); if (lSafetyStatus.IsUndecided || (lSafetyStatus.IsUnsurroundable && !lSafetyStatus.IsDame)) { lMoves.Add(i); } } } return(lMoves); }
public static List <int> GetMovesInOpponentsTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame List <int> lMoves = new List <int>(); for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove.Opposite)) { if (goBoard.IsLegal(lPoint, playerToMove)) { lMoves.Add(lPoint); } } } return(lMoves); }
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 static int IsLegalXMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters) { Color lPlayer = player.Opposite; return((goBoard.IsLegal(parameters[0], lPlayer)) ? TRUE : FALSE); }
// marked to be depreciated public static int FindAnySafeInOwnTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove)) if (goBoard.IsLegal(lPoint, playerToMove)) { goBoard.PlayStone(lPoint, playerToMove, true); SafetyStatus lSafetyStatusAfter = goBoard.GetSafetyStatus(lPoint); goBoard.Undo(); // it's still safe after move, so return it if ((lSafetyStatus.IsAlive) && (lSafetyStatus.Player == playerToMove)) return lPoint; } } return CoordinateSystem.PASS; }
public static int IsLegalOMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters) { return((goBoard.IsLegal(parameters[0], player)) ? TRUE : FALSE); }
// marked to be depreciated public static List<int> GetSafeMovesInOwnTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame List<int> lMoves = new List<int>(); for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove)) if (goBoard.IsLegal(lPoint, playerToMove)) { goBoard.PlayStone(lPoint, playerToMove, true); SafetyStatus lSafetyStatusAfter = goBoard.GetSafetyStatus(lPoint); // check if still safe after move if (lSafetyStatusAfter.IsAlive) // && (lSafetyStatus.Player == playerToMove)) lMoves.Add(lPoint); goBoard.Undo(); } } return lMoves; }
public static int IsLegalOMove(GoBoard goBoard, Color player, PatternFunctionParameters<int> parameters) { return (goBoard.IsLegal(parameters[0], player)) ? TRUE : FALSE; }
public static List<int> GetMovesInOpponentsTerritory(GoBoard goBoard, Color playerToMove) { // useful for force moves in endgame List<int> lMoves = new List<int>(); for (int lPoint = 0; lPoint < goBoard.Coord.BoardArea; lPoint++) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(lPoint); if ((lSafetyStatus.IsTerritory) && (lSafetyStatus.Player == playerToMove.Opposite)) if (goBoard.IsLegal(lPoint, playerToMove)) lMoves.Add(lPoint); } return lMoves; }
// marked to be depreciated public static List<int> GetLegalSafeMoves(GoBoard goBoard, Color playerToMove) { List<int> lMoves = new List<int>(); for (int i = 0; i < goBoard.Coord.BoardArea; i++) if (goBoard.IsLegal(i, playerToMove)) { SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus(i); if (lSafetyStatus.IsUndecided || (lSafetyStatus.IsUnsurroundable && !lSafetyStatus.IsDame)) lMoves.Add(i); } return lMoves; }
public static int IsLegalXMove(GoBoard goBoard, Color player, PatternFunctionParameters<int> parameters) { Color lPlayer = player.Opposite; return (goBoard.IsLegal(parameters[0], lPlayer)) ? TRUE : FALSE; }
/// <summary> /// Gets a list of legal moves. /// </summary> /// <param name="color">The color.</param> /// <returns></returns> public MoveList GetMoveList(Color playerToMove, bool forceEndGameMoves) { MoveList lMoves = new MoveList(Board.BoardSize); if (!forceEndGameMoves) { for (int lMove = 0; lMove < Board.Coord.BoardArea; lMove++) { if (Board.IsLegal(lMove, playerToMove)) { SafetyStatus lSafetyStatus = Board.GetSafetyStatus(lMove); if (lSafetyStatus.IsUndecided || (lSafetyStatus.IsUnsurroundable && !lSafetyStatus.IsDame)) { lMoves.Add(lMove); } } } lMoves.Add(CoordinateSystem.PASS); return(lMoves); } // during the very final end game - when players fill dame and capture dead stones for (int lMove = 0; lMove < Board.Coord.BoardArea; lMove++) { SafetyStatus lSafetyStatus = Board.GetSafetyStatus(lMove); if ((lSafetyStatus.IsUnsurroundable) || (lSafetyStatus.IsDame)) { if (Board.IsLegal(lMove, playerToMove)) { if (lSafetyStatus.IsUnsurroundable) { lMoves.Add(lMove); } else if (lSafetyStatus.IsDame) { lMoves.Add(lMove); } } } } if (lMoves.Count != 0) { return(lMoves); } for (int lMove = 0; lMove < Board.Coord.BoardArea; lMove++) { SafetyStatus lSafetyStatus = Board.GetSafetyStatus(lMove); if ((lSafetyStatus.IsDead) && (Board.Cells[lMove].Color == playerToMove.Opposite)) { foreach (int lMove2 in ((GoBlock)Board.Cells[lMove].Block).Liberties) { if (Board.IsLegal(lMove2, playerToMove)) { lMoves.Add(lMove2); } } } } // just in case / should still be fast lMoves.Add(CoordinateSystem.PASS); return(lMoves); }
public static int IsSafeXMove(GoBoard goBoard, Color player, PatternFunctionParameters<int> parameters) { Color lPlayer = player.Opposite; return ((goBoard.IsLegal(parameters[0], lPlayer)) && (LibertyCountAfterMove(goBoard, lPlayer, parameters[0]) > 1)) ? TRUE : FALSE; }