P1.2

AuthorMrAf
Submission date2019-02-11 14:16:10.782442
Rating1567
Matches played258
Win rate15.5

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

Source code:

bfs_dfs =1
global previous
input =""
global arrq
code =[]
global coden
global codeo
global codec


class node(object):


    def __init__(self, object, code = "" ,nextc = []):
        self.object = object
        self.nextc = nextc
        self.code = code

def increasetree (object):
    if object.nextc == None and object.object == "head":
        object.nextc = [node("R"),node("P"),node("S")]
        object.nextc[0].code = "R"
        object.nextc[1].code = "P"
        object.nextc[2].code = "S"
        object.nextc[0].nextc =None
        object.nextc[1].nextc = None
        object.nextc[2].nextc = None
        return object
    elif object.nextc == None :
        object.nextc = [node("R"), node("P"), node("S")]
        object.nextc[0].code = object.code + "R"
        object.nextc[1].code = object.code + "P"
        object.nextc[2].code = object.code + "S"
        object.nextc[0].nextc = None
        object.nextc[1].nextc = None
        object.nextc[2].nextc = None
        return object
    else:
        for num in range(0,3):
            object.nextc[num] = increasetree(object.nextc[num])
        return object
def findop(ans):

    if(ans == "R"):
        return "P"
    if (ans == "P"):
        return "S"
    if (ans == "S"):
        return "R"
    if (ans == ""):
        return "R"
def makeoutput ():
    if input == "":
        coden = 0
        codec = 0
        codeo = ""
        previous = ""
    if input == "":
        codec = 0
        return findop(input)
    else:
        codeo = code[coden]
        if len(codeo) == codec:
            coden +=1
            codeo = code[coden]
            codec = 0
        out = codeo[codec]
        codec += 1
        return out

def BFS (object):
    if object.nextc == None and arrq:
        temp = arrq.pop(0)
        code.append(temp.object)
        BFS(temp)
        return 0
    elif object.nextc != None:
        arrq.append(object.nextc[0])
        arrq.append(object.nextc[1])
        arrq.append(object.nextc[2])
        temp = arrq.pop(0)
        code.append(temp.code)
        BFS(temp)
        return 0
    else:
        return 0

def DFS (object):

    if object.nextc == None:
        code.append(object.code)
        return 0
    elif object.object == "head":
        DFS(object.nextc[0])
        DFS(object.nextc[1])
        DFS(object.nextc[2])
        return 0
    else:
        code.append(object.code)
       # play(code, depth)
        DFS(object.nextc[0])
        #play(code, depth)
        DFS(object.nextc[1])
        #play(code, depth)
        DFS(object.nextc[2])

        return 0

tree = node("head","",None)
increasetree(tree)
increasetree(tree)
increasetree(tree)
increasetree(tree)
increasetree(tree)
if bfs_dfs == 1:
    DFS(tree)
if bfs_dfs == 0:
    BFS(tree)
output = makeoutput()
previous = input