-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
70 lines (58 loc) · 2.31 KB
/
Copy pathbot.py
File metadata and controls
70 lines (58 loc) · 2.31 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 boardwrapper import BoardWrapper
import chess
from movetree import MoveTreeNode
from endgame import EndgamePredictor
import threading
import sys
from table import TTable
class Bot():
def __init__(self, piececolor: str, fen = chess.STARTING_FEN):
self.e = EndgamePredictor()
self.board = BoardWrapper(self.e, chess.Board(fen))
self.piececolor = piececolor
if (self.piececolor == "white"):
self.piececolor = chess.WHITE
else:
self.piececolor = chess.BLACK
self.time_event = threading.Event()
self.table = TTable()
#updates board representing game state and returns move to make, if applicable
def updateboard(self, moves: str):
self.board = self.board.updateboard(moves)
#return None if the latest update has created a draw by repetition and ended the game
#return True if the game is still continuing
if (self.board.isrepetition()):
return None
return True
#resets board, then makes every move in the provided move string
#for testing purposes, for inputting an arbitrary position
def updateboardall(self, moves: str):
self.board = self.board.updateboardall(moves)
#check if it is the bot's turn to play, if so, return move
if (self.board.isrepetition()):
return None
return True
#Gets any legal move, without logic
#To be changed
def getmove(self):
#return move if it is the bot's turn to play]
#else, ignore
if (self.board.getturn() == self.piececolor):
tree = MoveTreeNode(self.board, 0, 4, self.piececolor, self.e, self.table)
self.time_event.clear()
timer_thread = threading.Timer(15, self.timer,kwargs={'event': self.time_event})
timer_thread.start()
move = tree.getbestmove(self.time_event)
self.table = tree.TTable
return move
else:
return None
def getboard(self):
return self.board.getboard()
#gets a heuristic evaluation of the board
def shalloweval(self):
return self.board.shalloweval(self.piececolor)
def timer(self, event : threading.Event):
event.set()
print('event SET')
sys.exit()