Ejemplo n.º 1
0
    def test_rampUpFromResources(self):
        ind = PlayerIndustry(None)

        stockpile = Stockpile()
        stockpile[RESOURCE_IRON] = 5

        ind.rampUp(6, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 4)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 2)

        stockpile[RESOURCE_IRON] = 10
        ind.rampUp(6, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 10)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 5)

        stockpile[RESOURCE_IRON] = 15
        ind.rampUp(6, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 12)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 6)
Ejemplo n.º 2
0
    def test_basicProduction(self):
        ind = PlayerIndustry(None)

        castIron = PRODUCTION_RULES.PRULE_CAST_IRON
        fabricFromWool = PRODUCTION_RULES.PRULE_FABRIC_FROM_WOOL
        fabricFromCotton = PRODUCTION_RULES.PRULE_FABRIC_FROM_COTTON

        ind.incr(castIron, 5)
        ind.incr(fabricFromWool, 5)
        ind.incr(fabricFromCotton, 5)

        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 10)
        self.assertEqual(requiredMat[RESOURCE_WOOL], 10)
        self.assertEqual(requiredMat[RESOURCE_COTTON], 10)

        otherResources = [
            resource for resource in allResourceNames()
            if resource not in (RESOURCE_IRON, RESOURCE_WOOL, RESOURCE_COTTON)
        ]

        for resource in otherResources:
            self.assertEqual(requiredMat[resource], 0)

        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 5)
        self.assertEqual(produced[RESOURCE_FABRIC], 10)
Ejemplo n.º 3
0
    def test_autoAdjust(self):
        ind = PlayerIndustry(None)

        stockpile = Stockpile()
        stockpile[RESOURCE_IRON] = 10
        stockpile[RESOURCE_WOOL] = 21

        ind.autoAdjustProduction(10, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 10)
        self.assertEqual(requiredMat[RESOURCE_WOOL], 10)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 5)
        self.assertEqual(produced[RESOURCE_FABRIC], 5)

        ind.autoAdjustProduction(16, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 10)
        self.assertEqual(requiredMat[RESOURCE_WOOL], 20)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 5)
        self.assertEqual(produced[RESOURCE_FABRIC], 10)

        stockpile[RESOURCE_IRON] = 10
        stockpile[RESOURCE_WOOL] = 10
        ind.autoAdjustProduction(16, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 10)
        self.assertEqual(requiredMat[RESOURCE_WOOL], 10)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 5)
        self.assertEqual(produced[RESOURCE_FABRIC], 5)

        stockpile[RESOURCE_IRON] = 20
        stockpile[RESOURCE_WOOL] = 20
        ind.autoAdjustProduction(16, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 20)
        self.assertEqual(requiredMat[RESOURCE_WOOL], 12)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 10)
        self.assertEqual(produced[RESOURCE_FABRIC], 6)
Ejemplo n.º 4
0
    def test_capacity(self):
        ind = PlayerIndustry(None)

        stockpile = Stockpile([(RESOURCE_IRON, 10), (RESOURCE_WOOL, 21)])
        capacity = ind.maxCapacity(stockpile.toList())
        self.assertEqual(capacity[PRULE_CAST_IRON], 5)
        self.assertEqual(capacity[PRULE_FABRIC_FROM_WOOL], 10)

        castIron = PRODUCTION_RULES.PRULE_CAST_IRON
        fabricFromWool = PRODUCTION_RULES.PRULE_FABRIC_FROM_WOOL

        ind.incr(castIron, 5)
        stockpile = Stockpile([(RESOURCE_IRON, 10), (RESOURCE_WOOL, 21)])
        capacity = ind.maxCapacity(stockpile.toList())
        self.assertEqual(capacity[PRULE_CAST_IRON], 5)
        self.assertEqual(capacity[PRULE_FABRIC_FROM_WOOL], 10)

        ind.incr(fabricFromWool, 10)
        stockpile = Stockpile([(RESOURCE_IRON, 10), (RESOURCE_WOOL, 21)])
        capacity = ind.maxCapacity(stockpile.toList())
        self.assertEqual(capacity[PRULE_CAST_IRON], 5)
        self.assertEqual(capacity[PRULE_FABRIC_FROM_WOOL], 10)
Ejemplo n.º 5
0
    def test_rampDownFromResources(self):
        ind = PlayerIndustry(None)

        stockpile = Stockpile()
        stockpile[RESOURCE_IRON] = 10
        stockpile[RESOURCE_WOOL] = 20

        castIron = PRODUCTION_RULES.PRULE_CAST_IRON
        ind.incr(castIron, 10)

        ind.rampDown(10, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 10)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 5)

        stockpile[RESOURCE_IRON] = 5
        ind.rampDown(10, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 4)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 2)
Ejemplo n.º 6
0
    def test_rampUpFromLabour(self):
        ind = PlayerIndustry(None)

        stockpile = Stockpile()
        stockpile[RESOURCE_IRON] = 30

        ind.rampUp(6, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 12)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 6)

        ind.rampUp(10, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 20)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 10)

        ind.rampUp(16, stockpile.toList())
        requiredMat = ind.totalRequiredMaterials
        self.assertEqual(requiredMat[RESOURCE_IRON], 30)
        produced = ind.producedResources
        self.assertEqual(produced[RESOURCE_CAST_IRON], 15)
Ejemplo n.º 7
0
 def initAllPlayerIndustries(self):
     self.allPlayerIndustries = {}
     for player in self.players:
         industry = PlayerIndustry(player)
         self.allPlayerIndustries[player.name] = industry