RPSbot2

AuthorJmo
Submission date2018-03-08 18:32:55.333170
Rating4899
Matches played302
Win rate50.33

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([[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()