myTester123

AuthorJmo
Submission date2018-03-08 18:30:08.150280
Rating4257
Matches played308
Win rate45.13

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

Source code:

import random

choices = [];
total = 0

def generateRandom():
    result = random.randrange(0, 3, 1)
    resultName = ""

    if result == 0:
        resultName = "R"
    if result == 1:
        resultName = "P"
    if result == 2:
        resultName = "S"

    return resultName

def generateNonRandom():
    a = np.matrix([[.25, .6, .15], [.15, .25, .6], [.6, .15, .25]])
    #a = np.matrix([[0, 1, 0], [0, 0, 1], [1, 0, 0]])
    b = findRatio(choices)
    probabilities = np.squeeze(np.asarray(a*b))
    
    result = np.random.choice([0, 1, 2], p =probabilities)
    resultName = ""
    
    if result == 0:
        resultName = "R"
    if result == 1:
        resultName = "P"
    if result == 2:
        resultName = "S"
    
    return resultName

def findRatio(arr):
    length = len(arr)
    rock = 0.0
    paper = 0.0
    scissors = 0.0

    for i in range(length-5, length):
        if arr[i] == "R":
            rock += 1
        if arr[i] == "S":
            scissors += 1
        if arr[i] == "P":
            paper += 1

    return np.matrix([[rock/5], [paper/5], [scissors/5]])

choices.append(input)
if total < 6:
    output = generateRandom()
else:
    output = generateNonRandom()