//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Play a Mankalah game with the two given players, with the firstPlayer starting. /// Returns TOP's score. /// </summary> /// <param name="playerTop">the player on the top</param> /// <param name="playerBottom">the player on the bottom</param> /// <param name="firstPlayer">the player who is starting the game</param> /// <returns>the score of the TOP player</returns> public static int PlayGame(Player playerTop, Player playerBottom, Position firstPlayer) { // Create a new game board. _board = new Board(firstPlayer); // Determine the player who starts. if (firstPlayer == Position.Top) { Console.WriteLine("Player " + playerTop.GetName() + " starts."); } else { Console.WriteLine("Player " + playerBottom.GetName() + " starts."); } // Display the current state of the game board. _board.Display(); // Continue rotating turns till the game is over. while (!_board.GameOver()) { Console.WriteLine(); // Get the player's move and output what move the player made. if (_board.WhoseMove() == Position.Top) { _move = playerTop.ChooseMove(_board); Console.WriteLine(playerTop.GetName() + " chooses move " + _move); } else { _move = playerBottom.ChooseMove(_board); Console.WriteLine(playerBottom.GetName() + " chooses move " + _move); } // Commit the move to the game state. (true = verbose, false = non-verbose) _board.MakeMove(_move, true); // Display the new state of the game board. _board.Display(); // Game is over, determine final results. if (_board.GameOver()) { if (_board.Winner() == Position.Top) { Console.WriteLine("Player " + playerTop.GetName() + " (TOP) wins " + _board.ScoreTopPlayer() + " to " + _board.ScoreBottomPlayer()); } else if (_board.Winner() == Position.Bottom) { Console.WriteLine("Player " + playerBottom.GetName() + " (BOTTOM) wins " + _board.ScoreBottomPlayer() + " to " + _board.ScoreTopPlayer()); } else { Console.WriteLine("A tie!"); } } // Game is not over, ask player to make their move. else if (_board.WhoseMove() == Position.Top) { Console.WriteLine(playerTop.GetName() + " to move."); } else { Console.WriteLine(playerBottom.GetName() + " to move."); } } // Return the final score for the match. return(_board.ScoreTopPlayer()); }