I’m working on the Rock Paper Scissors Lizard Spock project, and am too lazy to write out all the conditions. I wanted to create a nested array of int
s to tell who kills what, where the proper name of a guess is replaced by an integer. In Javascript, nested arrays are easy:
let defeats = [
// rock (with an index of 0) defeats scissors (2) and lizard (3)
[2, 3],
// paper
[0, 4],
// scissors
[1, 3],
// lizard
[1, 4],
// spock
[0, 2],
];
an array like that would make checking the outcome easy:
if(computerGuess == userGuess) {
std::cout << "draw!\n";
} else if(computerGuess == defeats[userGuess][0] || computerGuess == defeats[userGuess][1]) {
// if there is something like 'defeats[userGuess].includes(computerGuess)' that would also be helpful
std::cout << "you win!\n";
} else {
std::cout << "computer wins!\n";
}
How could I get this same result with a C++ vector? Or is there a better way?
Thanks