Exemplo n.º 1
0
        void HandleNextMove(Tuple <int, int> move)
        {
            if (Game.GetWinner(board) == Game.Empty)
            {
                Player currentPlayer = Player.GetPlayerFromTurn(turn, player1, player2);
                List <Tuple <int, int> > validMoves = Game.GetValidMoves(board, currentPlayer.Tile);
                if (validMoves.Count > 0 && move != null)
                {
                    if (validMoves.Contains(move))
                    {
                        Game.MakeMove(board, move, currentPlayer.Tile);
                        boardHistories.Add(board.Clone() as byte[, ]);
                        turn++;
                        RenderBoard(board);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    turn++;
                }

                if (Game.GetWinner(board) != Game.Empty)
                {
                    HandleWinner();
                }
                Player nextPlayer = Player.GetPlayerFromTurn(turn, player1, player2);
                if (nextPlayer.Mode != Player.Modes.Human)
                {
                    HandleAIMove();
                }
            }
        }