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