Skip to content

Commit

Permalink
Add Game.any_humans
Browse files Browse the repository at this point in the history
  • Loading branch information
dripton committed Aug 21, 2012
1 parent 1663dff commit 9e3c1bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 8 additions & 0 deletions slugathon/game/Game.py
Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions slugathon/net/Server.py
Expand Up @@ -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)
Expand Down

0 comments on commit 9e3c1bc

Please sign in to comment.