def create_society(seed_generation_size=SEED_GENERATION_SIZE, number_of_generations=NUMBER_OF_GENERATIONS, children_per_parents=CHILDREN_PER_PARENTS): agents = [] # Create the seed generation first_generation = [] while len(first_generation) < SEED_GENERATION_SIZE - 1: # Create seed generation agent agent = Agent.create_random_agent() first_generation.append(agent) generations = [first_generation] generations_created = 1 while generations_created < NUMBER_OF_GENERATIONS: # Create a generation based on the previous generation generation = create_generation( generations[generations_created - 1], CHILDREN_PER_PARENTS ) generations.append(generation) generations_created += 1 for generation in generations: agents.extend(generation) return agents
def create_society(seed_generation_size=SEED_GENERATION_SIZE, number_of_generations=NUMBER_OF_GENERATIONS, children_per_parents=CHILDREN_PER_PARENTS): agents = [] # Create the seed generation first_generation = [] while len(first_generation) < SEED_GENERATION_SIZE - 1: # Create seed generation agent agent = Agent.create_random_agent() first_generation.append(agent) generations = [first_generation] generations_created = 1 while generations_created < NUMBER_OF_GENERATIONS: # Create a generation based on the previous generation generation = create_generation(generations[generations_created - 1], CHILDREN_PER_PARENTS) generations.append(generation) generations_created += 1 for generation in generations: agents.extend(generation) return agents
if dice_roll < 3: print "%s parries into better position." % defender.name defender_advantage = defender_advantage + 1 elif dice_roll < 5: print "%s blocks the attack." % defender.name elif dice_roll < 7: print "%s blocks the attack and %s presses forward." % (defender.name, attacker.name) attacker_advantage = attacker_advantage + 1 elif dice_roll < 9: print "%s makes contact and %s shows blood." % (attacker.name, defender.name) attacker_advantage = attacker_advantage + 1 defender_health = defender_health - 1 else: print "%s wounds %s deeply." % (attacker.name, defender.name) attacker_advantage = attacker_advantage + 1 defender_health = defender_health - 2 attacker_advantage = max(attacker_advantage, 2) defender_advantage = max(defender_advantage, 2) return (attacker_advantage, defender_health, defender_advantage) if __name__ == "__main__": runs = 1 while runs > 0: runs = runs - 1 p1 = Agent.create_random_agent() p2 = Agent.create_random_agent() advantage, p1alive, p2alive = joust(p1, p2)
def test_create_random_agent(self): agent = Agent.create_random_agent() self.assertIsInstance(agent.name, basestring)
if dice_roll < 3: print "%s parries into better position." % defender.name defender_advantage = defender_advantage + 1 elif dice_roll < 5: print "%s blocks the attack." % defender.name elif dice_roll < 7: print "%s blocks the attack and %s presses forward." % ( defender.name, attacker.name) attacker_advantage = attacker_advantage + 1 elif dice_roll < 9: print "%s makes contact and %s shows blood." % ( attacker.name, defender.name) attacker_advantage = attacker_advantage + 1 defender_health = defender_health - 1 else: print "%s wounds %s deeply." % (attacker.name, defender.name) attacker_advantage = attacker_advantage + 1 defender_health = defender_health - 2 attacker_advantage = max(attacker_advantage, 2) defender_advantage = max(defender_advantage, 2) return (attacker_advantage, defender_health, defender_advantage) if __name__ == "__main__": runs = 1 while runs > 0: runs = runs - 1 p1 = Agent.create_random_agent() p2 = Agent.create_random_agent() advantage, p1alive, p2alive = joust(p1, p2)