Rock Paper Scissors

Note

This is actually the hardest problem to me among all 5 final projects of the AI course.

This probably is cheating, but I learn the idea for the solution from Milk's solution.

I don't who implement the abby player, but it's really hard to beat.

Time spent here: 5h

Attempt 1

Ignore this. This is failed attempt.

Think like FCC

I was really tempted to look into the game driver code and learn about how other players is implemented, but I didn't

Since we're not supposed to look in the opponent implementations, let's think about how would FCC implement them.

Implementation ideas

For each strategy our opponent can employ, we should have a counter strategy. We will need to use random move for a while, until we have enougb data to see his strategy.

However, since this is just a game, I don't think we should try to be perfect and implement all ideas we have. We will just add enough code until we beat all the bots.

That means the code in the Solution section below doesn't grow linearly.

Attempt 2

I changed my mind. Need to look at opponent code to learn their strategy and counter it

Problem description

Assignment

For this challenge, you will create a program to play Rock, Paper, Scissors. A program that picks at random will usually win 50% of the time. To pass this challenge your program must play matches against four different bots, winning at least 60% of the games in each match.

In the file RPS.py you are provided with a function called player. The function takes an argument that is a string describing the last move of the opponent ("R", "P", or "S"). The function should return a string representing the next move for it to play ("R", "P", or "S").

A player function will receive an empty string as an argument for the first game in a match since there is no previous play.

The file RPS.py shows an example function that you will need to update. The example function is defined with two arguments (player(prev_play, opponent_history = [])). The function is never called with a second argument so that one is completely optional. The reason why the example function contains a second argument (opponent_history = []) is because that is the only way to save state between consecutive calls of the player function. You only need the opponent_history argument if you want to keep track of the opponent_history.

Hint: To defeat all four opponents, your program may need to have multiple strategies that change depending on the plays of the opponent.

Development

Do not modify RPS_game.py. Write all your code in RPS.py. For development, you can use main.py to test your code.

main.py imports the game function and bots from RPS_game.py.

To test your code, play a game with the play function. The play function takes four arguments:

play(player1, player2, num_games[, verbose])

For example, here is how you would call the function if you want player and quincy to play 1000 games against each other and you want to see the results of each game:

play(player, quincy, 1000, verbose=True)

Game driver

This is provided by FCC.

Solution

Map between a move and its counter.

Our player implementation

Test