예제 #1
0
        public State Play()
        {
            bool boardFullGameOver = false;

            //Game will continue until either the board is full, no more valid moves can be made, or if one player runs out of pieces.
            //Winner is then decided.
            while (!boardFullGameOver)
            {
                PlayerTurn(_player1);

                if (_board.IsGameOver())
                {
                    boardFullGameOver = true;
                    break;
                }
                else if (!_board.AnyPlayerPiecesRemaining(_player2))
                {
                    Console.WriteLine("\nPlayer 2 is out of pieces. Game Over!");
                    break;
                }

                PlayerTurn(_player2);

                if (_board.IsGameOver())
                {
                    boardFullGameOver = true;
                }
                else if (!_board.AnyPlayerPiecesRemaining(_player1))
                {
                    Console.WriteLine("\nPlayer 1 is out of pieces. Game Over!");
                    break;
                }
                else if (!(_board.IsAnyMovePossible(_player1) || _board.IsAnyMovePossible(_player2)))
                {
                    Console.WriteLine("\nNo more valid moves possible. Game Over!");
                    break;
                }
            }

            if (boardFullGameOver)
            {
                Console.WriteLine("\nGame Over!");
            }

            return(_board.TallyWinner());
        }