/**
* test.cpp
*
* <#Name#>
* <#Uniqname#>
*
* EECS 183: Project 2
*
* Testing functions for your rps.cpp implementation.
* Holds the definitions of required testing functions.
* We have stubbed all required functions for you.
*/
#include <iostream>
#include <string>
using namespace std;
const int MAX_ROUNDS = 3;
void printInitialHeader();
/**
* Requires: nothing
* Modifies: cout
* Effects: Prints the menu.
* Prompts: "1) Play rock, paper, scissors"
* "2) Play rock, paper, scissors, lizard, spock"
* "3) Quit"
* "Choice --> "
*/
void printMenu();
/**
* Requires: error_number be either 1 or 2
* Modifies: cout
* Effects: If error_number is 1, prints an error message indicating
* an illegal name was entered.
* If error_number is 2, prints an error message indicating
* an illegal move was entered.
*/
void printErrorMessage(int error_number);
/**
* Requires: nothing
* Modifies: cout
* Effects: Prints out the final greeting for the program.
*/
void printCloser();
//************************************************************************
// You must implement all of the following functions. Add your
// implementations below main as indicated.
//************************************************************************
/**
* Requires: player_number is either 1 or 2
* Modifies: cout, cin
* Effects: Prompts the user to enter their name. Names entered may
* have spaces within them.
* Example: "Kermit the frog"
*
* If an empty name is given, this is invalid input, so print
* error message 1, and return a default name.
* For player 1, the default name is: Rocky
* For player 2, the default name is: Creed
* Prompt: Player [player_number], enter your name:
*/
string getName(int player_number);
/**
* Requires: nothing
* Modifies: cout, cin
* Effects: Prints the menu, and reads the input from the user.
* Checks to make sure the input is within range for the menu.
* If it is not, prints "Invalid menu choice". Continues to print
* the menu and read in input until a valid choice is entered,
* then returns the user's choice of menu options. You can assume
* a user will enter an integer, and nothing else, as their choice.
* Prompt: Invalid menu choice
*/
int getMenuChoice();
/**
* Requires: nothing
* Modifies: nothing
* Effects: Returns true if and only if move represents a valid move character:
* one of 'R', 'r', 'P', 'p', 'S', 's'. Returns false otherwise.
*/
bool isMoveGood(char move);
/**
* Requires: player_name is the name of the player being prompted for their
* move.
* Modifies: cout, cin
* Effects: Prompts the player for their move and returns it.
* This function should accept the first non-whitespace character as
* the move. If an illegal character is entered for their move, print
* error message 2 and return rock as a default. You can assume a user
* will enter a single character, and nothing else, as their move.
* Prompt: [player_name], enter your move:
*/
char getMove(string player_name);
/**
* Requires: move is the move of the player being checked for a win.
* opponent_move is the move of the opponent.
* both move and opponent_move are valid moves.
* Modifies: nothing
* Effects: Returns true if and only if the player who made move won
* according to the rules to rock-paper-scissors. Returns false
* otherwise.
*/
bool isRoundWinner(char move, char opponent_move);
/**
* Requires: winner_name is the name of the player who won the round.
* Modifies: cout
* Effects: If winner_name is empty, prints a message indicating the round
* is a draw. Otherwise, prints a congratulatory message to the
* winner.
* Prompt: This round is a draw!
* ------------- OR -------------
* [winner_name] wins the round!
*/
void announceRoundWinner(string winner_name);
/**
* Requires: p1_name and p2_name are the names of the respective players
* Modifies: nothing
* Effects: Simulates a complete round of rock-paper-scissors, which
* consists of three steps:
* 1. Get player1 move
* 2. Get player2 move
* 3. Return 0 if the round was a draw; 1 if player 1 won;
* 2 if player 2 won.
*/
int doRound(string p1_name, string p2_name);
/**
* Requires: winner_name is the name of the player who won the game.
* Modifies: cout
* Effects: If winner_name is blank, prints that the game was a draw.
* Otherwise, prints a congratulatory message to the winner.
* Prompt: No winner!
* ------------- OR -------------
* Congratulations [winner_name]!
* You won EECS 183 Rock-Paper-Scissors!
*/
void announceWinner(string winner_name);
/**
* Requires: p1_name and p2_name are the names of the respective players,
* game_type can be 1 for regular rock-paper-scissors
* or 2 for rock-paper-scissors-lizard-spock
* Modifies: cout
*
* Base Project:
* Effects: If game_type is 2, prints "Under Construction" to indicate that the
* s'more has not been implemented. Returns empty string.
* Otherwise, plays exactly three rounds of rock-paper-scissors while
* keeping track of the number of round wins for each player.
* When a round results in a draw, neither player is the winner,
* so neither player is awarded a point.
* After each round is played, the round winner (or draw) is
* announced. Returns the name of the winner or an empty string if the
* game ended in a draw.
* Prompt: Under Construction
*
* S'more Version:
* Effects: Has same functionality as base project, but also handles a
* game_type of 2. When game_type is 2, plays exactly three rounds of
* rock-paper-scissors-lizard-spock. Keeps track of round wins for
* each player and announces round winners in the same fashion as
* described above.
*/
string doGame(string p1_name, string p2_name, int game_type);
//************************************************************************
// You should have implemented the following functions in rps.cpp
//************************************************************************
bool isMoveGood(char move);
bool isRoundWinner(char move, char opponent_move);
void announceRoundWinner(string winner_name);
void announceWinner(string winner_name);
//************************************************************************
// Function declarations. Function definition is below main.
//************************************************************************
void test_isMoveGood();
void test_isRoundWinner();
void test_announceRoundWinner();
void test_announceWinner();
int main() {
// TODO: call test functions here
test_isMoveGood();
test_announceWinner();
test_announceRoundWinner();
test_announceWinner();
return 0;
}
//************************************************************************
// Put all your test function implementations below here.
// We have stubbed all required functions for you
// to recieve full points when submitting test.cpp
//************************************************************************
void test_isMoveGood() {
// TODO: implement
//Testing for Valid Moves
for (int i = 0; i<26; i++)
{
cout << isMoveGood(i + 'a') << endl;
cout << isMoveGood(i + 'A') << endl;
}
}
void test_isRoundWinner() {
// TODO: implement
char moves[6] = { 'R','r','S','s','P','p' };
for (int i = 0; i<6; i++)
{
for (int j = 0; j<6; j++)
{
cout << isRoundWinner(moves[i], moves[j]) << endl;
}
}
}
void test_announceRoundWinner() {
// TODO: implement
announceRoundWinner("xyz abc");
announceRoundWinner("Rana Tigrina");
announceRoundWinner("David Rocco") ;
announceRoundWinner("Yo Yo Yo Yo Yo") ;
announceRoundWinner("why are you doing this") ;
announceRoundWinner("") ;
announceRoundWinner("A");
}
void test_announceWinner() {
// TODO: implement
announceWinner("xyz abc") ;
announceWinner("David Rocco");
announceWinner("Rana Tigrina") ;
announceWinner("Ho Ho Ho Ho Ho") ;
announceWinner("This is so Boooooring :(") ;
announceWinner("Z") ;
announceWinner("") ;
}