summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Ward <peteraward@gmail.com>2014-02-22 20:48:32 +1100
committerPeter Ward <peteraward@gmail.com>2014-02-22 20:48:32 +1100
commitbd3b37e4cbe324c68abde257434b0dee3257163d (patch)
treec06e2c8fca959e93572724a59c0f9e06226aaad6
parent4e6255791bc15d45624ee73d9011f2c522e583e3 (diff)
winners
-rw-r--r--robots/cursesviewer.py11
-rw-r--r--robots/game.py20
2 files changed, 28 insertions, 3 deletions
diff --git a/robots/cursesviewer.py b/robots/cursesviewer.py
index 4dbe198..b37a06a 100644
--- a/robots/cursesviewer.py
+++ b/robots/cursesviewer.py
@@ -26,7 +26,7 @@ class CursesViewer:
self.player_colours['*'] = 'white'
def draw_board(self):
- print(self.terminal.clear)
+ print(self.terminal.clear, end='')
robots = {}
for player, info in self.game.players.items():
@@ -64,9 +64,16 @@ class CursesViewer:
def run(self):
limiter = rate_limit(10)
+ self.draw_board()
while not self.game.finished:
next(limiter)
- self.draw_board()
self.game.next()
+ self.draw_board()
+
+ winners = self.game.finished
+ if winners is True:
+ print('Game ended in a draw.')
+ else:
+ print('Game won by:', ', '.join(winners))
diff --git a/robots/game.py b/robots/game.py
index 8fc507b..d87c495 100644
--- a/robots/game.py
+++ b/robots/game.py
@@ -99,7 +99,25 @@ class Game:
@property
def finished(self):
- return False
+ target = int(round(self.available_tiles * 0.5))
+
+ winners = []
+ roboteers = []
+
+ for whoami, info in self.players.items():
+ n_tiles = self._painted_tiles[whoami]
+ if n_tiles > target:
+ winners.append(whoami)
+
+ if info['robots']:
+ roboteers.append(whoami)
+
+ won = bool(winners)
+ if len(roboteers) <= 1:
+ won = True
+ winners.extend(roboteers)
+
+ return winners or won
def call_bots(self):
for whoami, bot in self.bots.items():