Author | name |
Submission date | 2019-02-12 11:12:12.113700 |
Rating | 4692 |
Matches played | 250 |
Win rate | 44.4 |
Use rpsrunner.py to play unranked matches on your computer.
bfs_dfs =1
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"
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)
DFS(object.nextc[0])
DFS(object.nextc[1])
DFS(object.nextc[2])
return 0
if not input:
arrq = []
coden = 0
codec = 0
codeo = ""
previous = ""
code = []
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)
out ="R"
elif input == previous:
out = findop(input)
else:
codeo = code[coden]
if len(codeo) == codec:
coden =coden +1
codeo = code[coden]
codec = 0
previous = input
out = codeo[codec]
codec = codec + 1
output =out