Permalink
Browse files

Add Game.any_humans

  • Loading branch information...
1 parent 1663dff commit 9e3c1bcb8fbc9e601d2698a4a4cf6178e848d52d @dripton committed Aug 21, 2012
Showing with 9 additions and 6 deletions.
  1. +8 −0 slugathon/game/Game.py
  2. +1 −6 slugathon/net/Server.py
View
@@ -162,6 +162,14 @@ def playernames(self):
def num_players(self):
return len(self.players)
+ @property
+ def any_humans(self):
+ """Return True if any of this game's players are human."""
+ for player in self.players:
+ if player.player_class == "Human":
+ return True
+ return False
+
def get_player_by_name(self, name):
for player in self.players:
if player.name == name:
View
@@ -240,14 +240,9 @@ def _spawn_ais(self, game):
game.name, game.min_players, game.num_players, num_ais)
logging.debug("%s player_ids %s", game.name, sorted(player_ids))
ainames = []
- any_humans = False
- for player in game.players:
- if player.player_class == "Human":
- any_humans = True
- break
for unused in xrange(num_ais):
player_id = self.results.get_weighted_random_player_id(
- excludes=player_ids, highest_mu=any_humans)
+ excludes=player_ids, highest_mu=game.any_humans)
player_ids.add(player_id)
ainame = "ai%d" % player_id
ainames.append(ainame)

0 comments on commit 9e3c1bc

Please sign in to comment.