-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
67 lines (50 loc) · 1.38 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import chess
import config
from negamax import MoveSelector
from pp_board import pp_board
MAX_ITER_MTD = 100
MAX_DEPTH = 4
def handle_ai_move(board, move_selector):
move = move_selector.selectMove(board)[0]
print("AI does " + move.uci())
board.push(move)
print(pp_board(board))
def handle_human_move(board):
while True:
raw_move = input("Enter your move: ")
try:
move = chess.Move.from_uci(raw_move)
if move in board.legal_moves:
break
else:
print("Invalid move, please enter a valid move!")
except ValueError:
print("Invalid UCI, please enter a valid UCI move!")
board.push(move)
print(pp_board(board))
def main():
board = chess.Board()
move_selector = MoveSelector(MAX_ITER_MTD, MAX_DEPTH, config.MAX_SCORE)
color_choice = input("Do you want to play as black or white? [W/B]: ")
while color_choice is not "W" and color_choice is not "B":
color_choice = input("Invalid choice, please enter W for white or B for black: ")
print(pp_board(board))
if color_choice == "W":
while True:
if board.is_game_over():
break
handle_human_move(board)
if board.is_game_over():
break
handle_ai_move(board, move_selector)
else:
while True:
if board.is_game_over():
break
handle_ai_move(board, move_selector)
if board.is_game_over():
break
handle_human_move(board)
print(board.result())
if __name__ == "__main__":
main()