-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
48 lines (40 loc) · 1.2 KB
/
test.py
File metadata and controls
48 lines (40 loc) · 1.2 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
48
from referee.game import PlayerColor, Action, PlaceAction, Coord
from agent.board import Board
from agent.program import Agent as minimax
import math
BOARD_N = 11
mini = minimax(PlayerColor.RED)
a = '''
r r r . b b . r r b b
r r r b b b r r r r .
r r r r b . b r r . r
. . r r r b b b b r r
. . . . . . . . . . .
r b b b . r b b . r r
r . b b b r r b b r r
. . b . r r r . b . b
b b b . r r . . b b b
. r . r r . r b b b b
. r r r b b r r . b b
'''
a = a.replace(" ", "").strip("\n").split("\n")
red = set()
blue = set()
for i in range(BOARD_N):
for j in range(BOARD_N):
if a[i][j] == 'r':
red.add(Coord(i, j))
elif a[i][j] == 'b':
blue.add(Coord(i, j))
board = Board(red, blue, PlayerColor.BLUE)
board.turn_count = 147
# putting turn count to be 0 or 1 here doesnt work because they have different generate_moves()
print(board.render())
valid_moves_dict: dict[int, set[PlaceAction]] = {}
valid_moves_dict[hash(mini.board)] = mini.board.generate_all_moves()
depth = 4
print("minimax depth =", depth)
eval, action = mini.minimax_ab(board, depth, -math.inf, math.inf, valid_moves_dict)
board.apply_action(action)
print("minimax eval = ", eval)
print(board.render())