forked from marcusbuffett/command-line-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveNode.py
More file actions
64 lines (53 loc) · 1.9 KB
/
MoveNode.py
File metadata and controls
64 lines (53 loc) · 1.9 KB
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
55
56
57
58
59
60
61
62
63
64
from Move import Move
class MoveNode:
def __init__(self, move, children, parent):
self.move = move
self.children = children
self.parent = parent
pointAdvantage = None
depth = 1
def __str__(self):
stringRep = "Move : " + str(self.move) + \
" Point advantage : " + str(self.pointAdvantage) + \
" Checkmate : " + str(self.move.checkmate)
stringRep += "\n"
for child in self.children:
stringRep += " " * self.getDepth() * 4
stringRep += str(child)
return stringRep
def __gt__(self, other):
if self.move.checkmate and not other.move.checkmate:
return True
if not self.move.checkmate and other.move.checkmate:
return False
if self.move.checkmate and other.move.checkmate:
return False
return self.pointAdvantage > other.pointAdvantage
def __lt__(self, other):
if self.move.checkmate and not other.move.checkmate:
return False
if not self.move.checkmate and other.move.checkmate:
return True
if self.move.stalemate and other.move.stalemate:
return False
return self.pointAdvantage < other.pointAdvantage
def __eq__(self, other):
if self.move.checkmate and other.move.checkmate:
return True
return self.pointAdvantage == other.pointAdvantage
def getHighestNode(self):
highestNode = self
while True:
if highestNode.parent is not None:
highestNode = highestNode.parent
else:
return highestNode
def getDepth(self):
depth = 1
highestNode = self
while True:
if highestNode.parent is not None:
highestNode = highestNode.parent
depth += 1
else:
return depth