infobot

Authortomos
Submission date2018-04-18 12:45:42.661810
Rating4406
Matches played297
Win rate43.77

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

Source code:

if input == "":
    import random
    outs = ["R", "P", "S"]
    
    hist = []
  
    rps_map = {("R", "R"): {"R": 0, "P": 0, "S": 0},
               ("R", "P"): {"R": 0, "P": 0, "S": 0},
               ("R", "S"): {"R": 0, "P": 0, "S": 0},
               ("P", "R"): {"R": 0, "P": 0, "S": 0},
               ("P", "P"): {"R": 0, "P": 0, "S": 0},
               ("P", "S"): {"R": 0, "P": 0, "S": 0},
               ("S", "R"): {"R": 0, "P": 0, "S": 0},
               ("S", "P"): {"R": 0, "P": 0, "S": 0},
               ("S", "S"): {"R": 0, "P": 0, "S": 0}
    }
    
    def best(last_pair):
        if rps_map[last_pair]["R"] > rps_map[last_pair]["P"] and rps_map[last_pair]["R"] > rps_map[last_pair]["S"]:
            return "P" # paper beats rock
        elif rps_map[last_pair]["P"] > rps_map[last_pair]["R"] and rps_map[last_pair]["P"] > rps_map[last_pair]["S"]:
            return "S" # scissors beats paper
        elif rps_map[last_pair]["S"] > rps_map[last_pair]["R"] and rps_map[last_pair]["S"] > rps_map[last_pair]["P"]:
            return "R" # rock beats scissors
        else:
            return outs[random.randint(0,2)] # Not enough data, make a random guess
    # end def best
    
    last_c = None
    last_p = None
    output = outs[random.randint(0,2)]
else:
    #print ""
    #print "Last Player Move: ", input
    #print "Last Computer Move: ", output
    #print "Second Last Player Move: ", last_c
    #print "Second Last Computer Move: ", last_p
    
    hist.append(input)
    
    if last_c is not None:
        rps_map[(last_c, last_p)][input] += 1
        output = best((last_c, last_p))
    else:
        output = outs[random.randint(0,2)]
    
    last_c = output
    last_p = input
    #if len(hist) >= 999:
    #    print ""
    #    print hist