-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer_move.py
More file actions
49 lines (38 loc) · 1.7 KB
/
computer_move.py
File metadata and controls
49 lines (38 loc) · 1.7 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
import copy
import time
from globals import switch_player_turn
import pygame
import globals
from main import determine_what_piece_has_been_selected
from bit_manipulation import clear_square, set_square
from debugging_functions import print_binary_as_bitboard
from move_logic import checkmate, make_move
import quiescence_minimax
from quiescence_minimax import alpha_beta_quiescence_minimax
def make_computer_move(colour):
depth = 2
if colour == 'black':
start_time = time.time()
min_eval, best_move = alpha_beta_quiescence_minimax(depth, False, float('-inf'), float('inf'))
end_time = time.time()
time_taken = end_time - start_time
print(f'Move: `{globals.half_move_counter}')
print(f'time taken: {time_taken}')
print(f'leaf nodes evaluated: {quiescence_minimax.leaf_node_count}')
else:
start_time = time.time()
min_eval, best_move = alpha_beta_quiescence_minimax(depth, True, float('-inf'), float('inf'))
end_time = time.time()
time_taken = end_time - start_time
print(f'Move: `{globals.half_move_counter}')
print(f'time taken: {time_taken}')
print(f'leaf nodes evaluated: {quiescence_minimax.leaf_node_count}')
print(
f'leaf node evaluations retrieved from transposition table: {quiescence_minimax.leaf_node_evaluations_retrieved_from_transposition_table}')
quiescence_minimax.leaf_node_count, quiescence_minimax.leaf_node_evaluations_retrieved_from_transposition_table = 0, 0 # reset counter
print('\n')
if best_move:
piece, start_index, end_index = best_move
make_move(piece, start_index, end_index)
else:
checkmate('white')