Rock Paper Scissors

import random

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"])

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.