Mk4.2

Authoriggi
Submission date2019-02-05 13:13:06.717579
Rating4778
Matches played239
Win rate46.44

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

Source code:

import random
import math

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
  cHistory = [] # computer's play history
  round = 0 # number of rounds played

  move = random.choice(moves) # first play is random
else:
  oHistory.append(input)
  cHistory.append(move)
  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):
      if input == oHistory[x] and cHistory[round-2] == cHistory[x-1]:
        stats[oHistory[x+1]] += (math.log(x+1))**2 #applying scaling based on age of the play
        
    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