// 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 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 static void GamePlayTest(int tests, bool withUndo, bool withSolver)
        {
            GoBoard    lGoBoard    = new GoBoard(19);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();

            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.GAME_1993_ZHONG_JIALIN_HANE_YASUMASA_1);
            lSGFCollection.RetrieveGame(lGameRecord, 0);

            SimpleTimer lSimpleTimer = new SimpleTimer();

            for (int i = 0; i < tests; i++)
            {
                GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, true);
                //lGameRecord.Apply(lGoBoard, true);

                if (withSolver)
                {
                    int lSafePoints = lGoBoard.CountSafePoints(Color.Black);
                    lSafePoints += lGoBoard.CountSafePoints(Color.White);
                }

                if (withUndo)
                {
                    while (lGoBoard.CanUndo())
                    {
                        lGoBoard.Undo();
                    }
                }
            }

            lSimpleTimer.Stop();

            Console.Write("19x19 Game [ ");
            Console.Write((withUndo ? "+Undo " : ""));
            Console.Write((withSolver ? "+Solver " : ""));
            Console.Write("] # " + tests.ToString() + " times. ");
            Console.Write("Elapsed: " + lSimpleTimer.MilliSecondsElapsed.ToString() + " ms ");
            Console.WriteLine("Avg.: " + (lSimpleTimer.MilliSecondsElapsed / tests).ToString() + " ms ");

            return;
        }
Example #5
0
        public static void GamePlayTest(int tests, bool withUndo, bool withSolver)
        {
            GoBoard lGoBoard = new GoBoard(19);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();
            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.GAME_1993_ZHONG_JIALIN_HANE_YASUMASA_1);
            lSGFCollection.RetrieveGame(lGameRecord, 0);

            SimpleTimer lSimpleTimer = new SimpleTimer();

            for (int i = 0; i < tests; i++)
            {
                GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, true);
                //lGameRecord.Apply(lGoBoard, true);

                if (withSolver)
                {
                    int lSafePoints = lGoBoard.CountSafePoints(Color.Black);
                    lSafePoints += lGoBoard.CountSafePoints(Color.White);
                }

                if (withUndo)
                    while (lGoBoard.CanUndo())
                        lGoBoard.Undo();
            }

            lSimpleTimer.Stop();

            Console.Write("19x19 Game [ ");
            Console.Write((withUndo ? "+Undo " : ""));
            Console.Write((withSolver ? "+Solver " : ""));
            Console.Write("] # "+tests.ToString()+" times. ");
            Console.Write("Elapsed: " + lSimpleTimer.MilliSecondsElapsed.ToString() + " ms ");
            Console.WriteLine("Avg.: " + (lSimpleTimer.MilliSecondsElapsed / tests).ToString() + " ms ");

            return;
        }
Example #6
0
        // 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;
        }
Example #7
0
        // 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;
        }
Example #8
0
        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;
        }