Mk4

Authoriggi
Submission date2019-02-05 12:03:38.311587
Rating5445
Matches played247
Win rate54.66

Use rpsrunner.py to play unranked matches on your computer.

Source code:

import random

if not input:
  moves = ["R", "P", "S"] # possible outputs
  beatenBy = {"R": "P", "P": "S", "S": "R"} # list of outcomes with string index
  oHistory = [] # opponent's play history
  round = 0 # number of rounds played

  move = random.choice(moves) # first play is random
else:
  oHistory.append(input)
  stats = {"R": 0, "P": 0, "S": 0}
  if round<10: # first play are random to populate the history
    move = random.choice(moves) 
  elif round<100: # find the probability of plays after the input is played
    for x in range(0, round-1): 
      if input == oHistory[x]:
        stats[oHistory[x+1]] += 1
  else: # find a set of two consecutive plays that match the last two plays and find the most likely next play
    for x in range(1, round-2): # find the probability of plays after the input is played
      if input == oHistory[x] and oHistory[round-2] == oHistory[x-1]:
        stats[oHistory[x+1]] += 1
        
    if stats["R"] > stats["S"] and stats["R"] > stats["P"]:
      move = "P" # if R is most probable play P
    elif stats["P"] > stats["S"] and stats["P"] > stats["R"]:
      move = "S" # if P is most probable play S
    else:
      move = "R" # if S is most probable play R
    
output = move
round += 1