diff options
-rw-r--r-- | robots/cursesviewer.py | 8 | ||||
-rw-r--r-- | robots/game.py | 24 |
2 files changed, 18 insertions, 14 deletions
diff --git a/robots/cursesviewer.py b/robots/cursesviewer.py index 434df47..4d94491 100644 --- a/robots/cursesviewer.py +++ b/robots/cursesviewer.py @@ -28,13 +28,13 @@ class CursesViewer: def draw_board(self, state): print(self.terminal.clear, end='') - width = len(state.board[0]) * 2 + width = len(state.board[0]) * 3 print(Box.TL + Box.H * width + Box.TR) for y, row in enumerate(state.board): output = [] for x, cell in enumerate(row): - value = ' ' + value = ' ' background = self.player_colours.get(cell['allegiance']) @@ -46,7 +46,7 @@ class CursesViewer: foreground = 'white' func = getattr(self.terminal, foreground) - value = func('<>') + value = func('<%d>') % energy if background: func = getattr(self.terminal, 'on_' + background) @@ -58,7 +58,7 @@ class CursesViewer: print(Box.BL + Box.H * width + Box.BR) def run(self): - limiter = rate_limit(10) + limiter = rate_limit(4) for state in self.game: next(limiter) diff --git a/robots/game.py b/robots/game.py index ce343e1..733068c 100644 --- a/robots/game.py +++ b/robots/game.py @@ -117,8 +117,14 @@ class Game: for whoami, bot, action in actions: x, y, energy = bot + if energy < ENERGY_BY_ACTION[action]: + action = Action.NOTHING + if action == Action.PROMOTE: - self.state.allegiances[x, y] = whoami + if self.state.allegiances.get((x, y)) != whoami: + self.state.allegiances[x, y] = whoami + else: + action = Action.NOTHING elif action != Action.NOTHING: dx, dy = DIRECTIONS[action] @@ -138,15 +144,12 @@ class Game: for name, robots in self.state.robots_by_player.items(): robots[:] = robots_by_player[name] - def get_spawn_time(self, whoami): - n_robots = len(self.players[whoami]['robots']) - if n_robots == 0: - return float('inf') - fraction_unowned = 1.0 - ( - self._painted_tiles[whoami] / - self.available_tiles - ) - return int(10 * fraction_unowned) + n_robots + def robots_gain_energy(self): + for robots in self.state.robots_by_player.values(): + robots[:] = [ + (x, y, min(Energy.MAXIMUM, energy + Energy.GAIN)) + for x, y, energy in robots + ] def __iter__(self): while not self.finished: @@ -162,5 +165,6 @@ class Game: # 3. Factories produce new robots. # 4. Combats are resolved. # 5. Each robot gains energy, up to the maximum. + self.robots_gain_energy() self.time += 1 |