This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_AI_move.py
51 lines (43 loc) · 1.47 KB
/
test_AI_move.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
import numpy as np
import time # timer
from agent.GWFrank_func.minimax import minimax
from agent.GWFrank_func.make_move import makeMove
from agent.GWFrank_func.available_spot import getAvailableSpot
def printBoard(obs):
for i in range(8):
for j in range(8):
if obs[i*8+j] == 0:
print('_', end='')
if obs[i*8+j] == 1:
print('O', end='')
if obs[i*8+j] == -1:
print('X', end='')
print('')
board = [0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, -1, 0, 0, 0,
0, 0, 0, -1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]
start = time.time() # timer
color = -1
nomovecount = 0
colorName = {1: 'white', -1: 'black'}
while nomovecount <= 2:
move, value = minimax(board, color, 5, -float('inf'), float('inf'))
try:
print(f"{colorName[color]} move in {(move%8, move//8)} with value {value}") # print
# print(f"available spots : {getAvailableSpot(board, color)}") # print
board = makeMove(board, move, color)
nomovecount = 0
printBoard(board) # print
print("="*20) # print
except:
nomovecount += 1
pass
color = -color
end = time.time() # timer
print(f"a game takes {end-start:.3f}s") # timer
print("board sum : ", sum(board))