-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
executable file
·77 lines (64 loc) · 2.08 KB
/
runner.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
68
69
70
71
72
73
74
75
76
77
from logging import error
import chess, chess.pgn
import chessAI as ai
# import cProfile
# import pstats
import time
# from pstats import SortKey
DEPTH = 2
def main():
# initiate classical chess board
board = chess.Board()
cvc(board)
def cvc(board: chess.Board):
game = chess.pgn.Game()
node = game
game_start = time.time()
tt = ai.TranspositionTable()
while not board.is_game_over():
move_start = time.time()
move = ai.ai_move(board, DEPTH, tt)
board.push(move)
print(board.fen())
node = node.add_variation(move)
print(game)
print(f'seconds taken: {time.time() - move_start}')
print(f'eval: {ai.calc_eval(board)}\n')
print(f'total time: {time.time() - game_start}')
# when done print result
print(board.result())
def pvc(board: chess.Board):
game = chess.pgn.Game()
node = game
tt = ai.TranspositionTable()
player_color = input("pick (white or black): ").lower()
if player_color == "white":
player_color = chess.WHITE
elif player_color == "black":
player_color = chess.BLACK
else:
print("Error: invalid choice")
quit()
while not board.is_game_over():
print(f'eval: {ai.calc_eval(board)}\n')
if board.turn == player_color:
move = chess.Move.from_uci(input("your move: "))
if move in board.legal_moves:
board.push(move)
node = node.add_variation(move)
else:
move = ai.ai_move(board, DEPTH, tt)
board.push(move)
node = node.add_variation(move)
print("AI's move: " + chess.Move.uci(move))
print(board.result())
# def runTime(function):
# cProfile.run(f'{function}', 'output.dat')
# with open('output_time.txt', 'w') as f:
# p = pstats.Stats('output.dat', stream=f)
# p.sort_stats('time').print_stats()
# with open('output_calls.txt', 'w') as f:
# p = pstats.Stats('output.dat', stream=f)
# p.sort_stats('calls').print_stats()
if __name__ == "__main__":
main()