Beispiel #1
0
        public int PlaySimulation()
        {
            if (_testingBoard == null)
            {
                _testingBoard = new Board();
            }
            _testingBoard.CopyStateFrom(_startingTestingBoard);
            int turnsSimulated = 0;

            while (turnsSimulated < GameParameters.GameDepth && _testingBoard.IsGameOver() == false)
            {
                turnsSimulated++;
                int  moveCount = GetAvailableMoves(_testingBoard);
                Move pass      = new Move(-1, -1); //добавить в список возможных ходов пас
                _availableMoves[moveCount++] = pass;
                _availableMoves.Shuffle(moveCount);
                for (int i = 0; i < moveCount; i++)
                {
                    if (_testingBoard.PlaceStone(_availableMoves[i]) == true)
                    {
                        break;
                    }
                }
            }
            int winner = _testingBoard.DetermineWinner();

            return(winner);
        }
Beispiel #2
0
        private int PlayRandomGame(UCTNode node)
        {
            _boardClone.CopyStateFrom(node.BoardState);
            int turnsSimulated = 0;

            while (turnsSimulated < GameParameters.GameDepth && _boardClone.IsGameOver() == false)
            {
                turnsSimulated++;
                Move m = new Move(-5, -5);
                do
                {
                    m.row    = RandomGen.Next(-1, GameParameters.BoardSize);
                    m.column = RandomGen.Next(-1, GameParameters.BoardSize);
                } while (_boardClone.PlaceStone(m) == false);
            }
            int winner = _boardClone.DetermineWinner();

            return(winner);
        }
Beispiel #3
0
        public int PlaySimulation()
        {
            if (_testingBoard == null)
            {
                _testingBoard = new Board();
            }
            _testingBoard.CopyStateFrom(_startingTestingBoard);
            int turnsSimulated = 0;

            while (turnsSimulated < GameParameters.GameDepth && _testingBoard.IsGameOver() == false)
            {
                turnsSimulated++;
                Move m = new Move(-1, -1);
                do
                {
                    m.row    = RandomGen.Next(-1, GameParameters.BoardSize);
                    m.column = RandomGen.Next(-1, GameParameters.BoardSize);
                } while (_testingBoard.PlaceStone(m) == false);
            }
            int winner = _testingBoard.DetermineWinner();

            return(winner);
        }
Beispiel #4
0
        public static void PlayGame(IPlayer blackPlayer, IPlayer whitePlayer)
        {
            gameRecord.AppendLine("(;FF[4]GM[1]SZ[9]AP[dotNetGo]");

            gameRecord.AppendLine(String.Format("PB[{0}]", blackPlayer.Name));
            gameRecord.AppendLine("HA[0]");
            gameRecord.AppendLine(String.Format("PW[{0}]", whitePlayer.Name));
            gameRecord.AppendLine("KM[6.5]");
            gameRecord.AppendLine("RU[Chinese]");
            gameRecord.AppendLine("");
            gameRecord.AppendLine("");
            Board board = new Board();

            while (board.IsGameOver() == false)
            {
                Move move;
                switch (board.ActivePlayer)
                {
                case 1:
                    move = blackPlayer.GetMove();
                    break;

                default:     //case 2:
                    move = whitePlayer.GetMove();
                    break;
                }
                if (blackPlayer.ReceiveTurn(move) == false)
                {
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                }
                if (whitePlayer.ReceiveTurn(move) == false)
                {
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                }
                if (move.row >= 0 && move.column >= 0)
                {
                    gameRecord.AppendFormat(";{0}[{1}{2}]", board.ActivePlayer == 1? "B": "W", alphabet[move.column], alphabet[move.row]);
                }
                if (board.PlaceStone(move) == false)
                {
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                }
                Console.WriteLine(board);
                //Console.ReadLine();
            }
            switch (board.State)
            {
            case Board.GameState.BlackSurrendered:
                Console.WriteLine("White won by resignation, last position:");
                break;

            case Board.GameState.WhiteSurrendered:
                Console.WriteLine("Black won by resignation, last position:");
                break;

            case Board.GameState.DoublePass:
                double blackScore, whiteScore;
                board.DetermineWinner(out blackScore, out whiteScore);
                gameRecord.AppendFormat(";RE[{0}+{1}]", blackScore > whiteScore?"B":"W", Math.Abs(blackScore - whiteScore));
                Console.WriteLine(board);
                Console.WriteLine("Turn: {0}", board.TurnNumber);
                Console.WriteLine("Black score: {0}; White score: {1}", blackScore, whiteScore);
                Console.WriteLine("last position:");
                break;
            }
            Console.WriteLine(board);
            gameRecord.Append(")");
            DateTime dt       = DateTime.Now;
            string   filename = String.Format("{0}-{1}-{2}-{3}-{4}-{5}.sgf",
                                              dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);

            File.WriteAllText(filename, gameRecord.ToString(), Encoding.UTF8);
        }
Beispiel #5
0
        public static void PlayGame(IPlayer blackPlayer, IPlayer whitePlayer)
        {
            gameRecord.AppendLine("(;FF[4]GM[1]SZ[9]AP[dotNetGo]");

            gameRecord.AppendLine(String.Format("PB[{0}]", blackPlayer.Name));
            gameRecord.AppendLine("HA[0]");
            gameRecord.AppendLine(String.Format("PW[{0}]", whitePlayer.Name));
            gameRecord.AppendLine("KM[6.5]");
            gameRecord.AppendLine("RU[Chinese]");
            gameRecord.AppendLine("");
            gameRecord.AppendLine("");
            Board board = new Board();
            while (board.IsGameOver() == false)
            {
                Move move;
                switch (board.ActivePlayer)
                {
                    case 1:
                        move = blackPlayer.GetMove();
                        break;
                    default: //case 2:
                        move = whitePlayer.GetMove();
                        break;
                }
                if (blackPlayer.ReceiveTurn(move) == false)
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                if (whitePlayer.ReceiveTurn(move) == false)
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                if (move.row >= 0 && move.column >= 0)
                    gameRecord.AppendFormat(";{0}[{1}{2}]", board.ActivePlayer == 1? "B": "W", alphabet[move.column], alphabet[move.row]);
                if (board.PlaceStone(move) == false)
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                Console.WriteLine(board);
                //Console.ReadLine();
            }
            switch (board.State)
            {
                case Board.GameState.BlackSurrendered:
                    Console.WriteLine("White won by resignation, last position:");
                    break;
                case Board.GameState.WhiteSurrendered:
                    Console.WriteLine("Black won by resignation, last position:");
                    break;
                case Board.GameState.DoublePass:
                    double blackScore, whiteScore;
                    board.DetermineWinner(out blackScore, out whiteScore);
                    gameRecord.AppendFormat(";RE[{0}+{1}]", blackScore > whiteScore?"B":"W", Math.Abs(blackScore-whiteScore));
                    Console.WriteLine(board);
                    Console.WriteLine("Turn: {0}", board.TurnNumber);
                    Console.WriteLine("Black score: {0}; White score: {1}", blackScore, whiteScore);
                    Console.WriteLine("last position:");
                    break;
            }
            Console.WriteLine(board);
            gameRecord.Append(")");
            DateTime dt = DateTime.Now;
            string filename = String.Format("{0}-{1}-{2}-{3}-{4}-{5}.sgf",
                dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
            File.WriteAllText(filename, gameRecord.ToString(), Encoding.UTF8);
        }