Description
How about new game rules? The original game has a fairly small choice of options.
The extended version of the game makes it hard to draw. Now, your program should accept alternative lists of options, like Rock, Paper, Scissors, Lizard, Spock, and so on. You can take the following options (don't take their relations into account; we'll speak about them further on):
In this stage, before the game starts, users can choose the options. After entering the name, they should provide a list of the options separated by a comma. For example:
rock,paper,scissors,lizard,spockIf users input an empty line, start the game with default options: rock, paper, and scissors.
Once the game options are defined, output Okay, let's start.
Regardless of the chosen options, your program, obviously, should identify which option beats which. You can use the following algorithm.
Let's imagine that the following options are involved in the game "Rock Fire Scissors Sponge Paper Air Water". Order is important.
Let us represent this line as a closed circle:
First, every option produces a draw when opposed to itself.
If Rock opposed Rock - it's a draw.
Secondly, every option beats half of the other options and is defeated by another half.
For "Rock":
The first half of the options after Rock are Fire Scissors and Sponge (Rock beat it). Another half (after first half) - Paper, Air and Water are defeated Rock.
For "Fire":
The first half of the options after Fire are Scissors, Sponge and Paper (Fire beat it). Another half (after first half) - Air, Water and Rock are defeated Fire.
And so on
How to determine which options are stronger or weaker? Take the list of options provided by the user and pick the option that you want to know the relationships of. Take all other options from the user's list. Add them to the list of options that precede the chosen option. Now, you have another list of options that don't include the user's option with a different order of elements inside. First are the options that follow the chosen one in the original list; then, there are the ones that precede it. So, in this "new" list, the first half of the options defeat the "chosen" option, and the second half is beaten by it.
Once again, never mind the "links" between the options in the picture above. They are only for illustration purposes
For example, the user's list of options is rock,paper,scissors,lizard,spock. You want to know what options are weaker than lizard. By looking at the list spock,rock,paper,scissors you realize that spock and rock beat lizard. Paper and scissors are defeated by it. For spock, it'll be almost the same, but it'll get beaten by rock and paper, and prevail over scissors and lizard.
Of course, this is not the most efficient way to determine which option prevails over which. You are welcome to try to develop other methods of tackling this problem.
Objectives
Your program should:
Output a line
Enter your name:. Users enter their names on the same line (not the one following the output);Read the input with the username and output
Hello, <name>;Read rating.txt and check whether it contains an entry with the current username. If yes, use the score specified in the file as a starting point. If not, start the score from
0;Read the input with the list of options for the game (options are separated by comma). If the input is an empty line, play with the default options;
Output a line
Okay, let's start;Play the game by the rules defined in the previous stages and read the user's input;
If the input is
!exit, outputBye!and stop the game;If the input is the name of the option, then pick a random option and output a line with the result of the game in the following format (
<option>is the name of the option chosen by the program):Loss:
Sorry, but the computer chose <option>Draw:
There is a draw (<option>)Win:
Well done. The computer chose <option> and failed
For each draw, add
50points to the score. For each user's win, add100to their score. In case of a loss, don't change the score;If input corresponds to anything else, output
Invalid input;Restart the game (with the same options defined before the start of the game).
Examples
The greater-than symbol followed by a space (> ) represents the user input. Note that it's not part of the input.
Example 1:
Enter your name: > Tim
Hello, Tim
> rock,gun,lightning,devil,dragon,water,air,paper,sponge,wolf,tree,human,snake,scissors,fire
Okay, let's start
> rock
Sorry, but the computer chose air
> !rating
Your rating: 0
> rock
Well done. The computer chose sponge and failed
> !rating
Your rating: 100
> !exit
Bye!Example 2:
Enter your name: > Tim
Hello, Tim
>
Okay, let's start
> rock
Well done. The computer chose scissors and failed
> paper
Well done. The computer chose rock and failed
> paper
There is a draw (paper)
> scissors
Sorry, but the computer chose rock
> !exit
Bye!