def test_monopoly(self): agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() goldResource = GoldResource(1000) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() encounter.monopoly(passiveAgents=diggers, goldResource=goldResource) assert goldResource.getQuantity() == 1000 - totalDiggingPower goldResource = GoldResource(1) for digger in diggers: digger.setGold(0) diggers[0].strength = 10000000 encounter.monopoly(passiveAgents=diggers, goldResource=goldResource) self.assertEqual(1, diggers[0].getGold())
def test_competition(self): agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() goldResource = GoldResource(1000) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() encounter.competition(passiveAgents=diggers, goldResource=goldResource) assert goldResource.getQuantity() == 1000 - totalDiggingPower goldResource = GoldResource(100) oldGoldValues = {} for digger in diggers: oldGoldValues[digger] = digger.getGold() encounter.competition(passiveAgents=diggers, goldResource=goldResource) for digger in oldGoldValues.keys(): oldGoldValue = oldGoldValues[digger] assert digger.getGold() - oldGoldValue <= digger.getMaxGoldPerTurn( )
def test_philanthropy(self): agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() goldResource = GoldResource(1000) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() encounter.philanthropy(passiveAgents=diggers, goldResource=goldResource) assert goldResource.getQuantity() == 1000 - totalDiggingPower
def test_priorityDigging(self): agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() goldResource = GoldResource(1000) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() totalAmountCollected = encounter.priorityDigging(diggers, goldResource) assert goldResource.getQuantity( ) == 1000 - totalDiggingPower or goldResource.getQuantity() == 0 assert totalAmountCollected < totalDiggingPower goldResource = GoldResource(1) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(100)) lastAgent = diggers[len(diggers) - 1] originalLastAgentGold = lastAgent.getGold() encounter.priorityDigging(diggers, goldResource) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() assert goldResource.getQuantity() == 0 assert lastAgent.getGold() == originalLastAgentGold
def test_collaboration(self): agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() goldResource = GoldResource(1000) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() encounter.collaboration(passiveAgents=diggers, goldResource=goldResource) print(f"current in resource: {goldResource.getQuantity()}") print(f"total lost: {totalDiggingPower}") assert goldResource.getQuantity() == 1000 - totalDiggingPower
def test_collectiveDigging(self): agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() goldResource = GoldResource(1000) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() _ = encounter.collectiveDigging(diggers, goldResource) assert goldResource.getQuantity() == 1000 - totalDiggingPower goldResource = GoldResource(1) diggers = agentFactory.copyAgents(agentFactory.buildDiggers(9)) encounter.priorityDigging(diggers, goldResource) totalDiggingPower = 0 for digger in diggers: totalDiggingPower += digger.getDiggingRate() assert goldResource.getQuantity() == 0
def createGoldResources(self): self.resources = [] self.resources.append(GoldResource(2)) pass
def test_simulateMultipleEncounters(self): # TODO continue agentFactory = GHAgentFactory() encounter = GoldHunterEncounter() originalGoldQuantity = 1000 goldResource = GoldResource(originalGoldQuantity) diggers = agentFactory.buildDiggers(5) robbers = agentFactory.buildRobbers(4) # single passive encounter allEncounterResults = encounter.simulateMultipleEncounters( [encounter.collaboration], passiveAgents=diggers, goldResource=goldResource) for encounterResults in allEncounterResults: self.assertIsNotNone(encounterResults.get(goldResource)) for digger in diggers: self.assertIsNotNone(encounterResults.get(digger)) self.assertEqual(originalGoldQuantity, goldResource.getQuantity()) # all passive encounters allEncounterResults = encounter.simulateMultipleEncounters( encounter.passiveEncounters, passiveAgents=diggers, goldResource=goldResource) for encounterResults in allEncounterResults: self.assertIsNotNone(encounterResults.get(goldResource)) for digger in diggers: self.assertIsNotNone(encounterResults.get(digger)) self.assertEqual(originalGoldQuantity, goldResource.getQuantity()) # single robbing encounter allEncounterResults = encounter.simulateMultipleEncounters( [encounter.intimidation], passiveAgents=diggers, aggressiveAgents=robbers) for encounterResults in allEncounterResults: for digger in diggers: self.assertIsNotNone(encounterResults.get(digger)) for robber in robbers: self.assertIsNotNone(encounterResults.get(robber)) # all robbing encounters allEncounterResults = encounter.simulateMultipleEncounters( encounter.robbingEncounters, passiveAgents=diggers, aggressiveAgents=robbers) for encounterResults in allEncounterResults: for digger in diggers: self.assertIsNotNone(encounterResults.get(digger)) for robber in robbers: self.assertIsNotNone(encounterResults.get(robber)) # single aggressive encounter allEncounterResults = encounter.simulateMultipleEncounters( [encounter.combat], aggressiveAgents=robbers) for encounterResults in allEncounterResults: for robber in robbers: self.assertIsNotNone(encounterResults.get(robber)) # all aggressive encounters allEncounterResults = encounter.simulateMultipleEncounters( encounter.aggressiveEncounters, aggressiveAgents=robbers) for encounterResults in allEncounterResults: for robber in robbers: self.assertIsNotNone(encounterResults.get(robber)) pass
def createGoldResources(self, count=5): for _ in range(count): self.resources.append(GoldResource(500)) pass