NYT

AuthorLast Universal Common Ancestor
Submission date2017-12-13 21:50:35.635290
Rating5976
Matches played325
Win rate58.46

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

Source code:

import random
#import sys

output = "S"
if input == "": # initialize variables for the first round
    rockCount = paperCount = scissorsCount = 0
    opp_moves = ""
    my_moves = ""
    moves = ["R", "P", "S"]
    moves_hash = [{},{},{},{}]    
elif input == "R":
    opp_moves = opp_moves + "R"
    rockCount += 1
elif input == "P":
    opp_moves = opp_moves + "P"
    paperCount += 1
elif input == "S":
    opp_moves = opp_moves + "S"
    scissorsCount += 1
# build the hash dictionary for moves
if (len(opp_moves) >= 2):
    if ( opp_moves[-2:] in moves_hash[0]):
        moves_hash[0][opp_moves[-2:]] += 1
    else:
        moves_hash[0][opp_moves[-2:]] = 1
if (len(opp_moves) >= 3):
    if ( opp_moves[-3:] in moves_hash[1]):
        moves_hash[1][opp_moves[-3:]] += 1
    else:
        moves_hash[1][opp_moves[-3:]] = 1
if (len(opp_moves) >= 4):
    if ( opp_moves[-4:] in moves_hash[2]):
        moves_hash[2][opp_moves[-4:]] += 1
    else:
        moves_hash[2][opp_moves[-4:]] = 1
if (len(opp_moves) >= 5):
    if ( opp_moves[-5:] in moves_hash[3]):
        moves_hash[3][opp_moves[-5:]] += 1
    else:
        moves_hash[3][opp_moves[-5:]] = 1

if (len(opp_moves) < 10):
    output = random.choice(["R","P","S"])
else:
    for i in [4,3,2,1]:        
        #last4 = opp_moves[-4:]
        last_i = opp_moves[-i:]
        #count4 = [ count(last4+"R"), count(last4+"P"), count(last4+"S")]
        max = 0
        my_next_move = ""
        if (last_i + "R") in moves_hash[i-1]:
            max = moves_hash[i-1][last_i + "R"]
            my_next_move = "P"    # opponent likely to play "R"
        if (last_i + "P") in moves_hash[i-1]:
            if (moves_hash[i-1][last_i + "P"] > max):
                max = moves_hash[i-1][last_i + "P"]
                my_next_move = "S"  # opponent likely to play "P"
        if (last_i + "S") in moves_hash[i-1]:
            if (moves_hash[i-1][last_i + "S"] > max):
                max = moves_hash[i-1][last_i + "S"]
                my_next_move = "R"  # opponent likely to play "S"
        if (my_next_move != "" and max > 0):
            output = my_next_move
            break