forked from tylerxprice/hive-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
76 lines (56 loc) · 2.03 KB
/
player.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import sys
from pieces import *
class Player:
(WHITE, BLACK) = ('white', 'black')
def __init__(self, color, bot, expansions):
self.bot = bot
self.color = color
self.pieces = dict()
self.setupStartingPieces(color[0], expansions)
self.seenHiveStates = []
self.timeUsed = 0
def setupStartingPieces(self, color, expansions):
self.pieces['Q'] = QueenBeePiece(color)
self.pieces['S1'] = SpiderPiece(color, 1)
self.pieces['S2'] = SpiderPiece(color, 2)
self.pieces['B1'] = BeetlePiece(color, 1)
self.pieces['B2'] = BeetlePiece(color, 2)
self.pieces['A1'] = AntPiece(color, 1)
self.pieces['A2'] = AntPiece(color, 2)
self.pieces['A3'] = AntPiece(color, 3)
self.pieces['G1'] = GrasshopperPiece(color, 1)
self.pieces['G2'] = GrasshopperPiece(color, 2)
self.pieces['G3'] = GrasshopperPiece(color, 3)
if 'M' in expansions:
self.pieces['M'] = MosquitoPiece(color)
if 'L' in expansions:
self.pieces['L'] = LadybugPiece(color)
def getPiece(self, (color, kind, number)):
key = kind + str(number)
return self.pieces[key]
def hasPlayed(self, kind, number = ''):
key = kind + str(number)
return self.pieces[key].isPlayed()
def getNumberOfPiecesToPlay(self):
count = 0
for key, piece in self.pieces.iteritems():
if not piece.isPlayed():
count += 1
return count
def addHiveState(self, state):
self.seenHiveStates.append(state)
def removeHiveState(self):
if len(self.seenHiveStates):
self.seenHiveStates.pop()
def hasSeenThreefoldRepetition(self):
if len(self.seenHiveStates) < 5:
return False
length = len(self.seenHiveStates)
return self.seenHiveStates[length - 5] == self.seenHiveStates[length - 3] == self.seenHiveStates[length - 1]
def printPile(self):
pile = []
for key in sorted(self.pieces.keys()):
piece = self.pieces[key]
if not piece.isPlayed():
pile.append(piece.getNotation())
sys.stderr.write("%s's Pile: %s\n" % (self.color.capitalize(), ', '.join(pile)))