-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinMaxClass.py
55 lines (45 loc) · 1.24 KB
/
MinMaxClass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# coding: utf-8
# In[ ]:
class MinMaxNode:
def __init__(self,label,rank=0):
self.label = label
self.rank = rank
self.children= []
def get_label(self):
return self.label
def get_children(self):
return self.children
def set_rank(self,newRank):
self.rank = newRank
def addChild(self,label):
c = self.checkIfChildExists(label)
if c==False:
x=MinMaxNode(label)
self.children.append(x)
return x
return c
def checkIfChildExists(self,label):
for c in self.children:
if c.label==label:
return c
return False
def __str__(self, level=0):
if level%2==0:
c="Attacker"
else:
c="Defender"
ret = "\t"*level+repr(self.label)+"("+repr(self.rank)+")-"+c+"\n"
for child in self.children:
ret += child.__str__(level+1)
ret+="\n"
return ret
def __repr__(self):
return '<tree node representation>'
def isLeaf(self):
if len(self.children)==0:
return True
return False
# In[ ]:
class MinMaxTree:
def __init__(self,label):
self.root = MinMaxNode(label)