Author | hjj |
Submission date | 2019-02-11 18:15:09.124276 |
Rating | 3632 |
Matches played | 263 |
Win rate | 33.46 |
Use rpsrunner.py to play unranked matches on your computer.
bfs_dfs =1
global previous
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 BFS (object):
if object.nextc == None and arrq:
temp = arrq.pop(0)
code.append(temp.code)
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
if not input:
arrq = []
coden = 0
codec = 0
codeo = ""
previous = ""
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)
print(code)
codeo = code[coden]
if len(codeo) == codec:
coden =coden +1
codeo = code[coden]
codec = 0
output = codeo[codec]
codec = codec + 1
previous = input