-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerAI.py
40 lines (27 loc) · 988 Bytes
/
PlayerAI.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
'''
Created on 24.10.2014
@author: Maria
'''
from BaseAI import BaseAI
import math
from Heuristic import Heuristic
from AlphaBetaPruning import AlphaBetaPruning
class PlayerAI(BaseAI):
def getMove(self, grid):
result = self.alphaBetaSearch(grid)
return result['direction']
def alphaBetaSearch(self, grid):
abp = AlphaBetaPruning()
alpha = {'score': float("-inf"), 'direction': -1 }
beta = {'score': float("inf"), 'direction': -1 }
moves = grid.getAvailableMoves()
result = {'score': float("-inf"), 'direction': -1}
depth = 3
for m in moves:
newGrid = grid.clone()
newGrid.move(m)
value = abp.minValue(newGrid, depth, alpha, beta, grid, m)
if value['score'] > result['score']:
result = value
result['direction'] = m
return result