Here's my question, how could I implement vectors in my program? And what does he mean by real randomness is hard to do right now so use vectors? |
We should know more about its context to give you any answer. It looks as if the author assumes you don’t know about rand() and pseudo-random numbers.
The rock-paper-scissor game, as any game with a little number of combinations, can be implemented by what are called lookup tables.
The logic is you can “inform” the program about all the possible combinations, so that it can just pick the correct one without any calculation.
If you have a look at the following table, I think you can easily guess what I’m talking about:
Rock, scissor, paper combination table:
---------------------------------------
Player 1
| rock scissor paper
Player 2 |---------------------------
rock | draw P2 wins P1 wins
scissors | P1 wins draw P2 wins
paper | P2 wins P1 wins draw |
So, if you know what’s a bi-dimensional vector, you can re-write your code removing nearly any logic. The problem is I haven’t understood if you’ve already met vectors…
Another possible interpretation of the text is: “since you don’t know what a pseudo-random number is, just provide a number of computer ‘moves’ in random order and pretend your program is playing against the user”. I mean, perhaps the author suggests creating a vector which stores, let’s say 9 moves in random order, and then use them against the user:
A vector like:
1 - rock
2 – scissors
3 – paper
4 – paper
5 – scissors
6 – rock
7 – rock
8 – paper
9 – scissors
Getting through it several times can appear to be a player who ‘thinks’ about the answer, while it’s just the same pattern which repeats.
Your code works, but it's really difficult to help you without a larger context. Or, at least, it’s really difficult for me since I’m not a native English speaker. Maybe someone else could work out more easily what the text requires.