def player(prev_play, opponent_history=[ ]):
# Initialize the strategy dictionary
strategy = {
"R": "P", # Paper beats Rock
"P": "S", # Scissors beats Paper
"S": "R" # Rock beats Scissors
}
# If it's the first game, or the opponent's previous play was not in the history, play randomly
if prev_play == "":
return random.choice(["R", "P", "S"])
# Update opponent history
opponent_history.append(prev_play)
# Implement a simple strategy based on the opponent's behavior
# For example, if the opponent played the same move twice, counter it
if len(opponent_history) >= 2 and opponent_history[-1] == opponent_history[-2]:
return strategy[opponent_history[-1]]
# If no special condition, play randomly
return random.choice(["R", "P", "S"])