-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIPlayer.py
46 lines (40 loc) · 1.34 KB
/
AIPlayer.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
import PlayerFunction as pf
from AIStrategy import Strategy
from AIBoard import Board
WHITE = "O"
BLACK = "@"
CORNER = "X"
EMPTY = "-"
class Player:
def __init__(self, color):
self.board = Board(color)
self.strategy = Strategy()
self.opponent = self.board.opponent
self.player = self.board.player
self.turns = 0
def action(self,turns):
self.turns+=1
if self.turns <= 24:
action = self.strategy.placingPhase(self.board, self.player)
self.board.place(self.player, action)
else:
action = self.strategy.movingPhase(self.board, self.player)
self.board.makeMove(self.player,action[0], action[1])
'''
Shrink 还是有点迷糊。 做hardcode test没问题,但是跑别的会有问题
'''
if (turns >128 and turns <192):
self.board.size = 6
self.board.shrinkBoard(self.board.numberOfShrink())
elif (turns >= 192):
self.board.size = 4
self.board.shrinkBoard(self.board.numberOfShrink())
return action
def update(self, action):
origin = action[0]
goal = action[1]
self.turns+=1
if self.turns <= 24:
self.board.place(self.opponent, action)
else:
self.board.makeMove(self.opponent,origin,goal)