-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveNode.py
More file actions
70 lines (59 loc) · 2.14 KB
/
MoveNode.py
File metadata and controls
70 lines (59 loc) · 2.14 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
65
66
67
68
69
70
from __future__ import annotations
from typing import Optional
from Move import Move
class MoveNode:
def __init__(
self,
move: Move,
children: list[MoveNode],
parent: Optional[MoveNode]
) -> None:
self.move = move
self.children = children
self.parent = parent
self.pointAdvantage = 0
self.depth = 1
def __str__(self) -> str:
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: object) -> bool:
if not isinstance(other, MoveNode):
return NotImplemented
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: object) -> bool:
if not isinstance(other, MoveNode):
return NotImplemented
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: object) -> bool:
if not isinstance(other, MoveNode):
return NotImplemented
if self.move.checkmate and other.move.checkmate:
return True
return self.pointAdvantage == other.pointAdvantage
def getDepth(self) -> int:
depth = 1
highestNode = self
while True:
if highestNode.parent is not None:
highestNode = highestNode.parent
depth += 1
else:
return depth