-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
29 lines (24 loc) · 943 Bytes
/
helper.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
import os
import chess
def save_pgn(pgn_moves, white_name, black_name):
pgn = " ".join(pgn_moves)
file_path = f'./pgns/{white_name}_vs_{black_name}.pgn'
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, 'w') as file:
file.write(pgn)
print(f"PGN saved at {file_path}")
def print_top_moves(move_values,s):
move_values = sorted(move_values, key=lambda x: x[0], reverse=s.board.turn)[:5]
print("Top moves:")
for i, (value, move) in enumerate(move_values[0:3]):
move_notation = s.board.san(move)
print(f" Move {i + 1}: {move_notation} with value {value}")
def explore_leaves(s, v):
ret = []
start = time.time()
v.reset()
bval = v(s)
cval, ret = bot_minimax(s, v, 0, a=-MAXVAL, b=MAXVAL, big=True)
eta = time.time() - start
print("%.2f -> %.2f: explored %d nodes in %.3f seconds" % (bval, cval, v.count, eta))
return ret