Are you looking to create a fun and interactive game using C++? This article will guide you on How To Make A Rock Paper Scissors Game In C++, offering a comprehensive, SEO-optimized approach perfect for rockscapes.net readers eager to enhance their programming skills while creating something enjoyable. You’ll learn everything from the basic game mechanics to advanced C++ coding techniques.
1. What is Rock Paper Scissors and How Does it Work in C++?
Rock Paper Scissors (RPS) is a classic hand game where two players simultaneously form one of three shapes with an outstretched hand: rock, paper, or scissors. In C++, this game is replicated using code to simulate player choices and determine a winner based on predefined rules.
The basic rules are:
- Rock crushes Scissors
- Scissors cuts Paper
- Paper covers Rock
- If both players choose the same shape, it’s a draw
Implementing this in C++ involves:
- Assigning numerical or character values to represent each choice (e.g., 0 for Rock, 1 for Paper, 2 for Scissors).
- Using random number generation for the computer’s choice.
- Employing conditional statements to compare the player’s and computer’s choices and determine the winner.
This game is a fantastic way to learn about random number generation and basic game logic in C++.
2. What are the Prerequisites for Making a Rock Paper Scissors Game in C++?
Before diving into coding your own Rock Paper Scissors game in C++, it’s essential to have a grasp of the foundational concepts. Here’s a breakdown of the prerequisites:
- Basic C++ Knowledge: Familiarity with C++ syntax, data types (int, char, bool), and variable declarations is crucial.
- Control Structures: Understanding
if
,else if
, andelse
statements is necessary for implementing game logic and decision-making. - Functions: Knowing how to define and call functions to organize code and create reusable blocks (e.g., a function to determine the winner).
- Random Number Generation: The ability to generate random numbers to simulate the computer’s choices (using
<cstdlib>
and<ctime>
). - Input/Output Operations: Using
cin
andcout
to take input from the player and display game results.
Having these skills will make the development process smoother and more enjoyable.
3. What Header Files are Needed for a Rock Paper Scissors Game in C++?
To create a Rock Paper Scissors game in C++, you’ll need to include certain header files that provide access to necessary functions and libraries. These include:
<iostream>
: For input and output operations, allowing the program to interact with the user via the console.<cstdlib>
: Provides functions for random number generation, such asrand()
andsrand()
.<ctime>
: Used to seed the random number generator with the current time, ensuring different random sequences each time the game is played.<string>
: Enables the use of string objects, making it easier to handle text-based input and output for player choices and game messages.<algorithm>
: Contains functions liketransform
for string manipulation.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <algorithm>
These header files are essential for handling user input, generating computer moves, and displaying results.
4. How Do You Generate a Computer Move in C++ for Rock Paper Scissors?
Generating a computer move in C++ for Rock Paper Scissors involves using random number generation to simulate the computer’s choice. Here’s how you can do it:
- Include Header Files: Include
<cstdlib>
for random number generation and<ctime>
to seed the random number generator. - Seed the Random Number Generator: Use
srand(time(0))
at the beginning of yourmain()
function to ensure the random numbers are different each time the program runs. - Generate a Random Number: Use
rand() % 3
to generate a random number between 0 and 2. Each number represents a move: 0 for Rock, 1 for Paper, and 2 for Scissors. - Assign the Move: Create a function that takes the random number and returns the corresponding move as a character or string.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
std::string getComputerMove() {
int move = rand() % 3;
if (move == 0) return "Rock";
if (move == 1) return "Paper";
return "Scissors";
}
int main() {
srand(time(0)); // Seed the random number generator
std::string computerMove = getComputerMove();
std::cout << "Computer chose: " << computerMove << std::endl;
return 0;
}
This code ensures the computer makes a random and unpredictable move each game.
5. How Can You Get Player Input in C++ for Rock Paper Scissors?
To get player input in C++ for Rock Paper Scissors, you’ll use std::cin
to read the player’s choice from the console. Here’s a simple approach:
- Prompt the Player: Display a message asking the player to enter their choice (e.g., ‘r’ for rock, ‘p’ for paper, ‘s’ for scissors).
- Read Input: Use
std::cin
to read the player’s input into a character or string variable. - Validate Input: Check if the input is valid (e.g., ‘r’, ‘p’, or ‘s’). If not, display an error message and ask the player to try again.
- Convert Input (Optional): Convert the input to a standardized format (e.g., uppercase or lowercase) for easier comparison.
#include <iostream>
#include <string>
#include <algorithm>
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, or scissors): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower); // Convert to lowercase
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors") {
return playerMove;
} else {
std::cout << "Invalid input. Please try again.n";
}
}
}
int main() {
std::string playerMove = getPlayerMove();
std::cout << "You chose: " << playerMove << std::endl;
return 0;
}
This code ensures that the player provides valid input before the game proceeds.
6. How Do You Determine the Winner in a Rock Paper Scissors Game Using C++?
Determining the winner in a Rock Paper Scissors game involves comparing the player’s move with the computer’s move using conditional statements. Here’s how you can implement the logic:
- Create a Function: Define a function that takes the player’s move and the computer’s move as input.
- Compare Moves: Use
if
,else if
, andelse
statements to compare the moves and determine the winner based on the game’s rules. - Return Result: Return a value indicating the result (e.g., 1 for player win, -1 for computer win, 0 for a draw).
#include <iostream>
#include <string>
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && computerMove == "scissors") ||
(playerMove == "paper" && computerMove == "rock") ||
(playerMove == "scissors" && computerMove == "paper")) {
return 1; // Player wins
} else {
return -1; // Computer wins
}
}
int main() {
std::string playerMove = "rock"; // Example player move
std::string computerMove = "scissors"; // Example computer move
int result = determineWinner(playerMove, computerMove);
if (result == 0) {
std::cout << "It's a draw!n";
} else if (result == 1) {
std::cout << "You win!n";
} else {
std::cout << "Computer wins!n";
}
return 0;
}
This function encapsulates the game’s core logic, making it easy to use and maintain.
7. Can You Show a Simple C++ Code for Rock Paper Scissors Game?
Here’s a simple C++ code implementation for the Rock Paper Scissors game:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <algorithm>
// Function to generate computer's move
std::string getComputerMove() {
int move = rand() % 3;
if (move == 0) return "rock";
if (move == 1) return "paper";
return "scissors";
}
// Function to get player's move
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, or scissors): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower);
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors") {
return playerMove;
} else {
std::cout << "Invalid input. Please try again.n";
}
}
}
// Function to determine the winner
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && computerMove == "scissors") ||
(playerMove == "paper" && computerMove == "rock") ||
(playerMove == "scissors" && computerMove == "paper")) {
return 1; // Player wins
} else {
return -1; // Computer wins
}
}
int main() {
srand(time(0)); // Seed random number generator
std::string playerMove = getPlayerMove();
std::string computerMove = getComputerMove();
std::cout << "You chose: " << playerMove << std::endl;
std::cout << "Computer chose: " << computerMove << std::endl;
int result = determineWinner(playerMove, computerMove);
if (result == 0) {
std::cout << "It's a draw!n";
} else if (result == 1) {
std::cout << "You win!n";
} else {
std::cout << "Computer wins!n";
}
return 0;
}
This code provides a functional Rock Paper Scissors game that you can compile and run in any C++ environment.
8. What Are Some Ways to Enhance the Rock Paper Scissors Game in C++?
To make your Rock Paper Scissors game more engaging, consider these enhancements:
- Multiple Rounds: Implement a loop to play multiple rounds, keeping track of the score.
- Best of N: Modify the game to play until one player wins a certain number of rounds (e.g., best of 3 or 5).
- User Interface: Instead of text-based input, create a simple graphical user interface (GUI) using libraries like SDL or SFML.
- AI Improvement: Implement a basic AI that learns from the player’s moves and adjusts its strategy accordingly.
- Advanced Moves: Add more moves beyond rock, paper, and scissors (e.g., lizard, Spock) to make the game more complex, as inspired by “The Big Bang Theory.”
- Scoreboard: Display a scoreboard showing the number of wins, losses, and draws.
- Input Validation: Enhance input validation to handle unexpected input gracefully.
By adding these features, you can create a more polished and entertaining game.
9. How Can You Implement Multiple Rounds in C++ Rock Paper Scissors?
To implement multiple rounds in your Rock Paper Scissors game, you can use a loop that continues until a certain condition is met (e.g., a specific number of rounds played or a player reaches a certain score). Here’s how:
- Initialize Variables: Declare variables to keep track of the number of rounds played, player score, and computer score.
- Create a Loop: Use a
for
orwhile
loop to repeat the game logic for each round. - Update Scores: Inside the loop, after each round, update the player and computer scores based on the game’s outcome.
- Display Scores: Display the current scores after each round.
- Check for End Condition: After each round, check if the game should end (e.g., if a player has won a certain number of rounds).
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <algorithm>
// Function to generate computer's move
std::string getComputerMove() {
int move = rand() % 3;
if (move == 0) return "rock";
if (move == 1) return "paper";
return "scissors";
}
// Function to get player's move
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, or scissors): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower);
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors") {
return playerMove;
} else {
std::cout << "Invalid input. Please try again.n";
}
}
}
// Function to determine the winner
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && computerMove == "scissors") ||
(playerMove == "paper" && computerMove == "rock") ||
(playerMove == "scissors" && computerMove == "paper")) {
return 1; // Player wins
} else {
return -1; // Computer wins
}
}
int main() {
srand(time(0)); // Seed random number generator
int rounds = 3;
int playerScore = 0;
int computerScore = 0;
for (int i = 0; i < rounds; ++i) {
std::cout << "Round " << i + 1 << ":n";
std::string playerMove = getPlayerMove();
std::string computerMove = getComputerMove();
std::cout << "You chose: " << playerMove << std::endl;
std::cout << "Computer chose: " << computerMove << std::endl;
int result = determineWinner(playerMove, computerMove);
if (result == 0) {
std::cout << "It's a draw!n";
} else if (result == 1) {
std::cout << "You win this round!n";
playerScore++;
} else {
std::cout << "Computer wins this round!n";
computerScore++;
}
std::cout << "Score - Player: " << playerScore << ", Computer: " << computerScore << "nn";
}
std::cout << "Final Score - Player: " << playerScore << ", Computer: " << computerScore << std::endl;
if (playerScore > computerScore) {
std::cout << "Congratulations! You won the game!n";
} else if (playerScore < computerScore) {
std::cout << "Computer won the game!n";
} else {
std::cout << "The game is a draw!n";
}
return 0;
}
This code will play three rounds, keep track of the scores, and announce the final winner.
10. How Can You Add a Scoreboard to Your C++ Rock Paper Scissors Game?
Adding a scoreboard to your C++ Rock Paper Scissors game enhances the user experience by displaying the current scores and game statistics. Here’s how you can implement it:
- Initialize Variables: Declare variables to store the player’s wins, computer’s wins, and draws.
- Update Scores: After each round, update the appropriate score variable based on the game’s outcome.
- Display Scoreboard: Create a function to display the scoreboard, showing the current scores for the player, computer, and draws.
- Call the Function: Call the display function after each round to update the scoreboard.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <algorithm>
// Function to generate computer's move
std::string getComputerMove() {
int move = rand() % 3;
if (move == 0) return "rock";
if (move == 1) return "paper";
return "scissors";
}
// Function to get player's move
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, or scissors): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower);
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors") {
return playerMove;
} else {
std::cout << "Invalid input. Please try again.n";
}
}
}
// Function to determine the winner
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && computerMove == "scissors") ||
(playerMove == "paper" && computerMove == "rock") ||
(playerMove == "scissors" && computerMove == "paper")) {
return 1; // Player wins
} else {
return -1; // Computer wins
}
}
// Function to display the scoreboard
void displayScoreboard(int playerScore, int computerScore, int draws) {
std::cout << "----------------------n";
std::cout << " SCOREBOARD n";
std::cout << "----------------------n";
std::cout << "Player: " << playerScore << "n";
std::cout << "Computer: " << computerScore << "n";
std::cout << "Draws: " << draws << "n";
std::cout << "----------------------nn";
}
int main() {
srand(time(0)); // Seed random number generator
int rounds = 3;
int playerScore = 0;
int computerScore = 0;
int draws = 0;
for (int i = 0; i < rounds; ++i) {
std::cout << "Round " << i + 1 << ":n";
std::string playerMove = getPlayerMove();
std::string computerMove = getComputerMove();
std::cout << "You chose: " << playerMove << std::endl;
std::cout << "Computer chose: " << computerMove << std::endl;
int result = determineWinner(playerMove, computerMove);
if (result == 0) {
std::cout << "It's a draw!n";
draws++;
} else if (result == 1) {
std::cout << "You win this round!n";
playerScore++;
} else {
std::cout << "Computer wins this round!n";
computerScore++;
}
displayScoreboard(playerScore, computerScore, draws);
}
std::cout << "Final Score - Player: " << playerScore << ", Computer: " << computerScore << ", Draws: " << draws << std::endl;
if (playerScore > computerScore) {
std::cout << "Congratulations! You won the game!n";
} else if (playerScore < computerScore) {
std::cout << "Computer won the game!n";
} else {
std::cout << "The game is a draw!n";
}
return 0;
}
This code provides a clear and concise scoreboard, enhancing the overall game experience.
11. How Can You Improve the AI in Your C++ Rock Paper Scissors Game?
Improving the AI in your C++ Rock Paper Scissors game can make it more challenging and engaging. Here are several strategies:
- Random AI: The simplest AI randomly chooses rock, paper, or scissors each round.
- Frequency Analysis: Track how often the player chooses each move (rock, paper, scissors). The AI can then choose the move that beats the player’s most frequent choice.
- Pattern Recognition: Look for patterns in the player’s moves. For example, if the player often chooses rock after choosing scissors, the AI can anticipate this and choose paper.
- Counter-Move Strategy: If the player has just chosen rock, the AI can choose paper in the next round, anticipating that the player might switch to scissors.
- Mixed Strategy: Combine different strategies randomly to make the AI less predictable.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
std::string getComputerMove(const std::vector<std::string>& playerMoves) {
if (playerMoves.empty()) {
// If no moves have been played yet, choose randomly
int move = rand() % 3;
if (move == 0) return "rock";
if (move == 1) return "paper";
return "scissors";
} else {
// Implement a simple frequency analysis
int rockCount = 0, paperCount = 0, scissorsCount = 0;
for (const auto& move : playerMoves) {
if (move == "rock") rockCount++;
if (move == "paper") paperCount++;
if (move == "scissors") scissorsCount++;
}
// Choose the move that beats the most frequent player move
if (rockCount >= paperCount && rockCount >= scissorsCount) {
return "paper"; // Paper beats rock
} else if (paperCount >= rockCount && paperCount >= scissorsCount) {
return "scissors"; // Scissors beat paper
} else {
return "rock"; // Rock beats scissors
}
}
}
int main() {
srand(time(0));
std::vector<std::string> playerMoves;
// Example usage:
std::string computerMove = getComputerMove(playerMoves);
// After getting player move, add it to the vector:
playerMoves.push_back("rock"); // Example player move
return 0;
}
By implementing these strategies, you can create an AI that provides a more challenging and enjoyable gaming experience.
12. How Can You Handle Invalid Input in C++ Rock Paper Scissors?
Handling invalid input is crucial for creating a robust and user-friendly Rock Paper Scissors game. Here’s how you can manage it effectively:
- Input Validation: Use a loop to continuously prompt the player for input until a valid choice is entered.
- Check for Valid Choices: Validate the input against the accepted choices (e.g., “rock”, “paper”, “scissors”).
- Display Error Message: If the input is invalid, display a clear and informative error message to guide the player.
- Clear Input Buffer: After an invalid input, clear the input buffer to prevent issues with subsequent input attempts.
#include <iostream>
#include <string>
#include <algorithm>
#include <limits> // Required for clearing the input buffer
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, or scissors): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower);
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors") {
return playerMove;
} else {
std::cout << "Invalid input. Please enter rock, paper, or scissors.n";
std::cin.clear(); // Clear error flags
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n'); // Ignore the rest of the line
}
}
}
int main() {
std::string playerMove = getPlayerMove();
std::cout << "You chose: " << playerMove << std::endl;
return 0;
}
This code ensures that the player is prompted until they enter a valid move, enhancing the game’s usability.
13. What Are Some Creative Ways to Present the Results in C++ Rock Paper Scissors?
Presenting the results of your Rock Paper Scissors game creatively can enhance the user experience. Here are a few ideas:
- ASCII Art: Use ASCII art to visually represent the player’s and computer’s moves.
- Descriptive Messages: Instead of simply saying “You win” or “Computer wins,” provide more descriptive messages that explain why the player won or lost.
- Animated Output: Use simple animations or delays to create a sense of anticipation before revealing the results.
- Sound Effects: Add sound effects to accompany the moves and results.
- Color-Coded Output: Use different colors to highlight the player’s move, the computer’s move, and the result.
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
// Function to generate computer's move
std::string getComputerMove() {
int move = rand() % 3;
if (move == 0) return "rock";
if (move == 1) return "paper";
return "scissors";
}
// Function to determine the winner
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && computerMove == "scissors") ||
(playerMove == "paper" && computerMove == "rock") ||
(playerMove == "scissors" && computerMove == "paper")) {
return 1; // Player wins
} else {
return -1; // Computer wins
}
}
// Function to display results with descriptive messages
void displayResults(const std::string& playerMove, const std::string& computerMove, int result) {
std::cout << "You chose: " << playerMove << "n";
std::cout << "Computer chose: " << computerMove << "n";
if (result == 0) {
std::cout << "It's a draw! Both players chose " << playerMove << ".n";
} else if (result == 1) {
std::cout << "You win! " << playerMove << " beats " << computerMove << ".n";
} else {
std::cout << "Computer wins! " << computerMove << " beats " << playerMove << ".n";
}
}
int main() {
srand(time(0));
std::string playerMove = "rock"; // Example player move
std::string computerMove = getComputerMove();
int result = determineWinner(playerMove, computerMove);
displayResults(playerMove, computerMove, result);
return 0;
}
By incorporating these creative presentation techniques, you can transform a simple text-based game into a more engaging and visually appealing experience.
14. How Can You Convert The Game into a Function in C++?
Converting the Rock Paper Scissors game into a function in C++ helps in organizing the code and making it reusable. Here’s how you can encapsulate the game logic into a function:
- Define the Function: Create a function that contains the entire game logic, including getting player input, generating computer moves, determining the winner, and displaying the results.
- Pass Parameters: If necessary, pass parameters to the function, such as the number of rounds to play or the player’s name.
- Return Value: The function can return a value indicating the overall result of the game (e.g., 1 for player win, -1 for computer win, 0 for a draw) or void if you only want to display the results within the function.
- Call the Function: Call the function from the
main()
function to start the game.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <algorithm>
// Function to generate computer's move
std::string getComputerMove() {
int move = rand() % 3;
if (move == 0) return "rock";
if (move == 1) return "paper";
return "scissors";
}
// Function to get player's move
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, or scissors): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower);
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors") {
return playerMove;
} else {
std::cout << "Invalid input. Please try again.n";
}
}
}
// Function to determine the winner
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && computerMove == "scissors") ||
(playerMove == "paper" && computerMove == "rock") ||
(playerMove == "scissors" && computerMove == "paper")) {
return 1; // Player wins
} else {
return -1; // Computer wins
}
}
// Function to play the Rock Paper Scissors game
int playRockPaperScissors() {
std::string playerMove = getPlayerMove();
std::string computerMove = getComputerMove();
std::cout << "You chose: " << playerMove << std::endl;
std::cout << "Computer chose: " << computerMove << std::endl;
int result = determineWinner(playerMove, computerMove);
if (result == 0) {
std::cout << "It's a draw!n";
} else if (result == 1) {
std::cout << "You win!n";
} else {
std::cout << "Computer wins!n";
}
return result;
}
int main() {
srand(time(0)); // Seed random number generator
int gameResult = playRockPaperScissors();
if (gameResult == 1) {
std::cout << "Congratulations! You won the game!n";
} else if (gameResult == -1) {
std::cout << "Computer won the game!n";
} else {
std::cout << "The game is a draw!n";
}
return 0;
}
This modular approach makes your code cleaner, easier to understand, and more maintainable.
15. What is the Rock, Paper, and Scissor Game Complexity?
The Rock Paper Scissors game has a straightforward complexity profile:
- Time Complexity: O(1) – The time complexity is constant because the game logic involves a fixed number of comparisons regardless of the input size. The computer’s move generation and winner determination take the same amount of time each round.
- Space Complexity: O(1) – The space complexity is also constant because the game uses a fixed amount of memory to store the player’s move, computer’s move, and the result.
This simplicity makes Rock Paper Scissors an excellent choice for learning basic programming concepts.
16. What is a Rock Paper Scissors Lizard Spock Game in C++?
Rock Paper Scissors Lizard Spock is an expansion of the classic game, introducing two additional choices: Lizard and Spock. This version adds complexity and more strategic possibilities. The rules are as follows:
- Scissors cuts Paper
- Paper covers Rock
- Rock crushes Lizard
- Lizard poisons Spock
- Spock smashes Scissors
- Scissors decapitates Lizard
- Lizard eats Paper
- Paper disproves Spock
- Spock vaporizes Rock
- Rock crushes Scissors
Implementing this in C++ involves expanding the move options and updating the win conditions.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <algorithm>
#include <vector>
// Function to generate computer's move
std::string getComputerMove() {
int move = rand() % 5;
std::vector<std::string> choices = {"rock", "paper", "scissors", "lizard", "spock"};
return choices[move];
}
// Function to get player's move
std::string getPlayerMove() {
std::string playerMove;
while (true) {
std::cout << "Enter your move (rock, paper, scissors, lizard, spock): ";
std::cin >> playerMove;
std::transform(playerMove.begin(), playerMove.end(), playerMove.begin(), ::tolower);
if (playerMove == "rock" || playerMove == "paper" || playerMove == "scissors" || playerMove == "lizard" || playerMove == "spock") {
return playerMove;
} else {
std::cout << "Invalid input. Please try again.n";
}
}
}
// Function to determine the winner
int determineWinner(const std::string& playerMove, const std::string& computerMove) {
if (playerMove == computerMove) {
return 0; // Draw
} else if ((playerMove == "rock" && (computerMove == "scissors" || computerMove == "lizard")) ||
(playerMove == "paper" && (computerMove == "rock" || computerMove == "spock")) ||
(playerMove == "scissors" && (computerMove == "paper"