forked from peterashwell/ants_2011
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameState.py
More file actions
60 lines (52 loc) · 1.94 KB
/
GameState.py
File metadata and controls
60 lines (52 loc) · 1.94 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
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import utils
import HillProtector
# records important data which is not a part of the ants.py program
class GameState:
def __init__(self, ants_instance):
self.num_rows = ants_instance.rows
self.num_cols = ants_instance.cols
self.turn = 0
# record turn upon which squares were last visible
self.last_visible = [[-100 for i in xrange(self.num_cols)] for j in xrange(self.num_rows)]
self.moving = set()
self.vacated = set()
sys.stderr.write('assbuck: ' + str(ants_instance.hill_list) + '\n')
# Assign ants to be hill protectors (see HillProtector.py)
# record turn upon which squares were last occupied by an opponent
#self.last_occupied = [[0 for i in num_rows] for j in num_cols]
# Called in doTurn(), does everything with gamestate
def updateAll(self, ants_instance):
if self.turn == 0: # do stuff on first turn
self.hp = HillProtector.HillProtector(ants_instance)
self.hp.updateTurn(ants_instance)
self.moving = set()
self.vacated = set()
# update all visible squares
for r in xrange(self.num_rows):
for c in xrange(self.num_cols):
if ants_instance.visible((r,c)):
self.updateVisible(r,c)
def tickTurn(self):
self.turn += 1
# Visit a square on current turn
def updateVisible(self, row, col):
#sys.stderr.write(str(self.last_visible) + '\n')
#sys.stderr.write(str(row) + ' ' + str(col) + '\n')
self.last_visible[row][col] = self.turn
def updateMoving(self, location):
self.moving.add(location)
def updateVacated(self, location):
self.vacated.add(location)
# Mark a square as having been occupied by enemy this turn
#def updateEnemy(self, row, col):
# self.last_occupied[row][col] = self.turn
def getTurn(self):
return self.turn
def movingTo(self, location):
return location in self.moving
def vacatedNow(self, location):
return location in self.vacated
# Return turns since visited for a cell
def turnsSinceVisible(self, row, col):
return self.turn - self.last_visible[row][col]