-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·41 lines (30 loc) · 832 Bytes
/
main.py
File metadata and controls
executable file
·41 lines (30 loc) · 832 Bytes
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
import chess
import chess.svg
import utils
from Node import Node
import tqdm
import pickle
# initialize board state
board = chess.Board("3k4/2n2B2/1KP5/2B2p2/5b1p/7P/8/8 b - - 0 0")
# make game tree
rootVal = utils.evaluate_board(board)
root = Node(board,'root',rootVal)
print(board)
#TODO: Fix bug that adds infinite move loops.
def makeTree(node,n):
legal_moves = node.board.legal_moves
if n == 0:
print("End of N")
return
for move in legal_moves:
newBoard = node.board.copy()
newBoard.push(move)
newVal = utils.evaluate_board(newBoard)
newNode = Node(newBoard, move, newVal)
node.add_child(newNode)
makeTree(newNode,n-1)
makeTree(root,4)
pickle_out = open("root.pickle","wb")
pickle.dump(root, pickle_out)
pickle_out.close()
root.peek_path()