-
Notifications
You must be signed in to change notification settings - Fork 0
/
Agent.py
47 lines (28 loc) · 1.31 KB
/
Agent.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
from Tile import Tile
class Agent:
MIN_VALUE = -1000000
MAX_VALUE= 1000000
def __init__(self, game, color, max_depth):
self.game = game
self.color = color
self.max_depth = max_depth
def do_min_max(self, current_board):
move, value = self.max(current_board, self.color, 0)
return move
def max(self, current_board, current_color, depth):
if (self.game.check_terminal(current_board, current_color)):
return None, self.game.evaluate(current_board, current_color, -1000)
if (depth == self.max_depth):
return None, self.game.evaluate(current_board, current_color)
possible_moves = self.game.generate_all_possible_moves(current_board, current_color)
best_move = None
best_move_value = self.MIN_VALUE
for move in possible_moves:
temp_move, value = self.min(current_board.next_board(current_color, move), self.game.opponent(current_color), depth + 1)
if (value > best_move_value):
best_move_value = value
best_move = move
# implement alpha-beta here
return best_move, best_move_value
def min(self, current_board, current_color, depth):
NotImplemented