1.0

Author51@k
Submission date2012-02-29 16:22:04.179940
Rating5334
Matches played755
Win rate55.23

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

Source code:

KAMEN, SKARJE, PAPIR = 0, 1, 2

class Player:

    def __init__(self):
        self.name = "Jure Slak"
        self.history = "";
        self.count = [1, 1, 1]

    def play(self):
        return self.w_choice(zip([PAPIR,KAMEN,SKARJE],map(lambda x: float(x)/sum(self.count), self.count)))

    def other(self, sign):
        assert 0 <= sign <= 2
        self.history += str(sign);
        self.count[sign] += 1

    def __str__(self):
        return ""+\
               "Player Jure Slak\n"+\
               "History: {0}\n".format(self.history[len(self.history)-50:])+\
               "Count: K: {1}   S: {2}    P{3}\n".format(*self.count)

    def __repr__(self): return str(self)

    def w_choice(self, lst):
        import random
        n = random.uniform(0, 1)
        for item, weight in lst:
                if n < weight: break
                n -= weight
        return item

p = Player()

invleg = {'R': KAMEN, "S": SKARJE, "P": PAPIR}

if input:
    p.other(invleg[input])

output = "RSP"[p.play()]