Avoiding Losing

AuthorkAworu
Submission date2019-05-14 10:05:18.524158
Rating5725
Matches played202
Win rate58.42

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

Source code:

#!/usr/bin/env python

# A bot focused on not losing rather than winning.

import math
import random

if input == "":
    r, p, s = 0, 0, 0
    output = random.choice("RPS")
else:
    r *= 0.92
    p *= 0.92
    s *= 0.92
    r += 0.2 if output == "R" and input == "P" else 0
    p += 0.2 if output == "P" and input == "S" else 0
    s += 0.2 if output == "S" and input == "R" else 0
    n = random.random() * (math.exp(r) + math.exp(p) + math.exp(s))
    if n < math.exp(r):
        output = random.choice("PS")
    elif n < (math.exp(r) + math.exp(p)):
        output = random.choice("RS")
    else:
        output = random.choice("RP")