Machine Learning with Python Projects - Rock Paper Scissors

import random

def player(prev_play, opponent_history=):
“”"
The player function returns the next move based on the previous move of the opponent.

:param prev_play: The opponent's previous move ("R", "P", or "S")
:param opponent_history: The history of the opponent's moves so far.

:return: The player's next move ("R", "P", or "S")
"""

# First move, choose randomly (since there's no history yet)
if prev_play == '':
    return random.choice(['R', 'P', 'S'])

# Record the opponent's last move
opponent_history.append(prev_play)

# Counter move to beat the opponent's last play
if prev_play == 'R':
    return 'P'  # Paper beats Rock
elif prev_play == 'P':
    return 'S'  # Scissors beats Paper
elif prev_play == 'S':
    return 'R'  # Rock beats Scissors

# Default fallback (should not reach here)
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!

Please stop opening topics, ask a question if you have one?