G & V test 1

AuthorGabe and Vikrant
Submission date2017-12-14 08:23:39.429440
Rating3158
Matches played308
Win rate32.79

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

Source code:

import random

moves = ""
for i in range(len(input)):
    moves = moves + input  

if len(moves) < 11:
    output = random.choice(["R", "R", "S", "P", "P", "P"])
else:
    prediction()



    def prediction():
        rockcount = 0
        papercount = 0
        scissorscount = 0

        for i in range(len(moves)):
            if moves[i] == "P":
                papercount += 1
            else:
                papercount += 0

        for g in range(len(moves)):
            if moves[g] == "S":
                scissorscount += 1
            else:
                scissorscount += 0

        for k in range(len(moves)):
            if moves[k] == "R":
                rockcount += 1
            else:
                rockcount += 0

        if last4(moves) == 0:

            if last3(moves) == 0:

                if last2(moves) == 0:
                    if rockcount > scissorscount and rockcount > papercount:
                        output = "P"
                    elif scissorscount > rockcount and scissorscount > papercount:
                        output = "R"
                    elif papercount > rockcount and papercount > scissorscount:
                        output = "S"
                    elif rockcount == papercount and rockcount > scissorscount:
                        output = "P"
                    elif rockcount == scissorscount and rockcount > papercount:
                        output = "R"
                    elif scissorscount == papercount and scissorscount > rockcount:
                        output = "S"
                    else:
                        output = random.choice(["R", "S", "P"])

                elif last2(moves) == "P":
                    output = "S"
                elif last2(moves) == "R":
                    output = "P"
                elif last2(moves) == "S":
                    output = "R"
                else:
                    output = random.choice(["R", "P", "S"])

            elif last3(moves) == "P":
                output = "S"
            elif last3(moves) == "R":
                output = "P"
            elif last3(moves) == "S":
                output = "R"
            else:
                output = random.choice(["R", "P", "S"])

        elif last4(moves) == "P":
            output = "S"
        elif last4(moves) == "R":
            output = "P"
        elif last4(moves) == "S":
            output = "R"
        else:
            output = random.choice(["R", "P", "S"])





    def last2(str):
        if len(str[0:-1]) <= 1:
            return 0
        else:
            if str[0:2] == str[-2:]:
                return str[2]
            else:
                return last2(str[1:])


    def last3(str):
        if len(str[0:-1]) <= 1:
            return 0
        else:
            if str[0:3] == str[-3:]:
                return str[3]
            else:
                return last3(str[1:])


    def last4(str):
        if len(str[0:-1]) <= 1:
            return 0
        else:
            if str[0:4] == str[-4:]:
                return str[4]
            else:
                return last4(str[1:])