-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathself_play.py
52 lines (40 loc) · 1.27 KB
/
self_play.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import chess
import config
from negamax import MoveSelector
from pp_board import pp_board
import os
MAX_ITER_MTD = 100
WHITE_MAX_DEPTH = 2
BLACK_MAX_DEPTH = 3
console_width = os.get_terminal_size().columns
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
def print_move(board, move_uci):
clear_screen()
color = "Black" if board.turn else "White"
other_color = "White" if board.turn else "Black"
print("\n")
print("{} does {}".format(color, move_uci).center(console_width))
print("{} to move".format(other_color).center(console_width))
str_board = pp_board(board)
str_board = "\n".join([row.center(console_width) for row in str_board.split("\n")])
print(str_board)
def make_move(board, move_selector):
move = move_selector.selectMove(board)[0]
board.push(move)
print_move(board, move.uci())
def main():
board = chess.Board()
white_move_selector = MoveSelector(MAX_ITER_MTD, WHITE_MAX_DEPTH, config.MAX_SCORE)
black_move_selector = MoveSelector(MAX_ITER_MTD, BLACK_MAX_DEPTH, config.MAX_SCORE)
clear_screen()
while True:
if board.is_game_over():
break
make_move(board, white_move_selector)
if board.is_game_over():
break
make_move(board, black_move_selector)
print(board.result().center(console_width))
if __name__ == "__main__":
main()