示例#1
0
    public bool takeTurn(RandomPlayer rando)
    {
        bool iWon         = false;
        bool turnComplete = false;

        while (turnComplete == false)
        {
            System.Tuple <int, int> randosMove = rando.GetMove(gameBoard);
            Debug.Log("randosMove: " + randosMove);

            turnComplete = gameBoard.MarkSquare(randosMove.Item1, randosMove.Item2, rando.assignedMark);

            Debug.Log(gameBoard.squares[0, 0] + ", " + gameBoard.squares[1, 0] + ", " + gameBoard.squares[2, 0]);
            Debug.Log(gameBoard.squares[0, 1] + ", " + gameBoard.squares[1, 1] + ", " + gameBoard.squares[2, 1]);
            Debug.Log(gameBoard.squares[0, 2] + ", " + gameBoard.squares[1, 2] + ", " + gameBoard.squares[2, 2]);

            if (turnComplete == true)
            {
                iWon = winningMove(randosMove.Item1, randosMove.Item2);
            }
        }

        return(iWon);
    }
示例#2
0
        private static void RunGame()
        {
            Process p = StartAiPlayer();

            string line = p.StandardOutput.ReadLine();
            DisplayMessageGreen(string.Format("running player: {0}", line));
            string config = string.Format("{0} {1} {2} 0 {3}", Game.ROWS, Game.COLUMNS, Game.PIECES_TO_WIN, Game.TIME_LIMIT);
            DisplayMessageGreen(string.Format("game config: {0}", config));
            p.StandardInput.WriteLine(config);

            Game game = new Game();
            GameEvaluator evaluator = new GameEvaluator();
            RandomPlayer player2 = new RandomPlayer();
            GameStates gameState = GameStates.InProgress;

            while (gameState == GameStates.InProgress)
            {
                // read the move from player
                line = p.StandardOutput.ReadLine();
                DisplayMessageGreen(string.Format("move from player: {0}", line));

                // tie the move to the game state and evaluate
                game.AcceptMove(Game.ME, int.Parse(line.Trim()));
                gameState = evaluator.EvaluateGame(game);
                if (gameState != GameStates.InProgress)
                {
                    HandleEndGame(gameState, p);
                    break;
                }

                // get random player's move
                int move2 = player2.GetMove(game);

                game.AcceptMove(Game.OPPONENT, move2);
                gameState = evaluator.EvaluateGame(game);
                if (gameState != GameStates.InProgress)
                {
                    HandleEndGame(gameState, p);
                    break;
                }

                DisplayMessageGreen(string.Format("sending move: {0}", move2));
                p.StandardInput.WriteLine(move2);
            }

            p.WaitForExit();
        }