goodstuff102

Authorseb
Submission date2019-10-16 10:28:28.011747
Rating5076
Matches played203
Win rate51.23

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

Source code:

def longestRepeatedSubstring(str): 
  
    n = len(str) 
    LCSRe = [[0 for x in range(n + 1)]  
                for y in range(n + 1)] 
  
    res = "" # To store result 
    res_length = 0 # To store length of result 
  
    # building table in bottom-up manner 
    index = 0
    for i in range(1, n + 1): 
        for j in range(i + 1, n + 1): 
              
            # (j-i) > LCSRe[i-1][j-1] to remove 
            # overlapping 
            if (str[i - 1] == str[j - 1] and
                LCSRe[i - 1][j - 1] < (j - i)): 
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
  
                # updating maximum length of the 
                # substring and updating the finishing 
                # index of the suffix 
                if (LCSRe[i][j] > res_length): 
                    res_length = LCSRe[i][j] 
                    index = max(i, index) 
                  
            else: 
                LCSRe[i][j] = 0
  
    # If we have non-empty result, then insert  
    # all characters from first character to  
    # last character of string 
    if (res_length > 0): 
        for i in range(index - res_length + 1, 
                                    index + 1): 
            res = res + str[i - 1] 
  
    return res


import random

previous = input

if previous == "":
    pattern = "RPS"


def beat(choise):
    if choise == "R":
        return "P"
    elif choise == "P":
        return "S"
    else:
        return "R"


if previous != "":
    pattern += previous

last_1000 = pattern[-25:]
sub = longestRepeatedSubstring(last_1000)
if len(sub) < 3:
    output = beat(random.choice(last_1000))
else:
    index = pattern.find(sub) + len(sub)
    if index >= len(sub):
        output = beat(random.choice(last_1000))
    else:
        output = beat(last_1000[index])