Exemplo n.º 1
0
 def test_equality_operator(self) -> None:
     self.assertEqual(
         common.Resources(coins=10, workers=1, bridges=2, priests=4),
         common.Resources(coins=10, workers=1, bridges=2, priests=4))
     self.assertNotEqual(
         common.Resources(coins=10, workers=1, bridges=2, priests=4),
         common.Resources(coins=10, workers=1, bridges=3, priests=4))
Exemplo n.º 2
0
    def test_structure_cost(self) -> None:
        halfling = faction.Halflings()

        # Dwelling.
        self.assertEqual(
            halfling.structure_cost(common.Structure.DWELLING,
                                    adjacentEnemyStructure=False),
            common.Resources(workers=1, coins=2))
        self.assertEqual(
            halfling.structure_cost(common.Structure.DWELLING,
                                    adjacentEnemyStructure=True),
            common.Resources(workers=1, coins=2))

        # Trading post.
        self.assertEqual(
            halfling.structure_cost(common.Structure.TRADING_POST,
                                    adjacentEnemyStructure=False),
            common.Resources(workers=2, coins=6))
        self.assertEqual(
            halfling.structure_cost(common.Structure.TRADING_POST,
                                    adjacentEnemyStructure=True),
            common.Resources(workers=2, coins=3))

        # Stronghold
        self.assertEqual(
            halfling.structure_cost(common.Structure.STRONGHOLD,
                                    adjacentEnemyStructure=False),
            common.Resources(workers=4, coins=8))
        self.assertEqual(
            halfling.structure_cost(common.Structure.STRONGHOLD,
                                    adjacentEnemyStructure=True),
            common.Resources(workers=4, coins=8))

        # Temple.
        self.assertEqual(
            halfling.structure_cost(common.Structure.TEMPLE,
                                    adjacentEnemyStructure=False),
            common.Resources(workers=2, coins=5))
        self.assertEqual(
            halfling.structure_cost(common.Structure.TEMPLE,
                                    adjacentEnemyStructure=True),
            common.Resources(workers=2, coins=5))

        # Sanctuary.
        self.assertEqual(
            halfling.structure_cost(common.Structure.SANCTUARY,
                                    adjacentEnemyStructure=False),
            common.Resources(workers=4, coins=6))
        self.assertEqual(
            halfling.structure_cost(common.Structure.SANCTUARY,
                                    adjacentEnemyStructure=True),
            common.Resources(workers=4, coins=6))
Exemplo n.º 3
0
 def structure_cost(self, structure: common.Structure,
                    adjacentEnemyStructure: bool) -> common.Resources:
     if structure == common.Structure.DWELLING:
         return common.Resources(workers=1, coins=1)
     if structure == common.Structure.TRADING_POST:
         return common.Resources(workers=1,
                                 coins=2 if adjacentEnemyStructure else 4)
     if structure == common.Structure.STRONGHOLD:
         return common.Resources(workers=3, coins=6)
     if structure == common.Structure.TEMPLE:
         return common.Resources(workers=1, coins=4)
     if structure == common.Structure.SANCTUARY:
         return common.Resources(workers=3, coins=6)
     raise utils.InternalError("Unknown cost for structure: %s" % structure)
Exemplo n.º 4
0
 def test_addition_operator(self) -> None:
     self.assertEqual(
         common.Resources(workers=1) +
         common.Resources(workers=2, priests=4),
         common.Resources(workers=3, priests=4))
     self.assertEqual(
         sum((common.Resources(workers=10),
              common.Resources(workers=2, bridges=4))),
         common.Resources(workers=12, bridges=4))
     resources = common.Resources(workers=10)
     resources += common.Resources(workers=1)
     self.assertEqual(resources, common.Resources(workers=11))
Exemplo n.º 5
0
    def test_player_collect_income_phase(self) -> None:
        # Halflings start with 3 workers and 15 coins, 3/9/0 power.
        test_player = player.Player(name="test",
                                    player_faction=faction.Halflings())
        oldPower = test_player.power.copy()

        # Player has not structures. Bonus card is manually set.
        test_player.bonus_card = common.BonusCard.TRADING_POST_WORKER
        test_player.collect_phase_ii_income()
        self.assertEqual(test_player.power, oldPower)
        self.assertEqual(test_player.resources,
                         common.Resources(workers=5, coins=15))

        # Let player build dweling one of each, all for free.
        test_player.build(common.Structure.DWELLING,
                          adjacentEnemies=False,
                          free=True)
        test_player.build(common.Structure.TRADING_POST,
                          adjacentEnemies=False,
                          free=True)
        test_player.build(common.Structure.STRONGHOLD,
                          adjacentEnemies=False,
                          free=True)
        test_player.build(common.Structure.TEMPLE,
                          adjacentEnemies=False,
                          free=True)
        test_player.build(common.Structure.SANCTUARY,
                          adjacentEnemies=False,
                          free=True)

        # Collect income. Structures will provide 2 priest, 1 worker, 2 coins,
        # 3 power. An additional 1 worker is provided by default.
        # Bonus card provides additional 1 worker.
        test_player.collect_phase_ii_income()
        self.assertEqual(test_player.resources,
                         common.Resources(workers=8, priests=2, coins=17),
                         "Player resources: %s" % test_player.resources)
        self.assertEqual(
            test_player.power, {
                common.PowerBowl.I: 0,
                common.PowerBowl.II: 12,
                common.PowerBowl.III: 0
            })
Exemplo n.º 6
0
    def test_player_burn_to_build(self) -> None:
        test_player = player.Player(name="test",
                                    player_faction=faction.Halflings())

        # Halflings start with 15 coins and 3 workers, as well as 9
        # power in Bowl II and 3 power in Bowl I.
        test_player.build(common.Structure.TRADING_POST, adjacentEnemies=False)
        # After building 1 TP (not adjacent), it costs 6 coins and 2 workers.
        self.assertEqual(test_player.resources,
                         common.Resources(coins=9, workers=1))
        # The next TP can be built that is adjacent, costs 3 coins and 2 workers.
        # Player must burn 3 power to get the extra worker.
        test_player.build(common.Structure.TRADING_POST, adjacentEnemies=True)
        self.assertEqual(test_player.resources,
                         common.Resources(coins=6, workers=0))
        self.assertEqual(test_player.power, {
            common.PowerBowl.I: 6,
            common.PowerBowl.II: 3,
            common.PowerBowl.III: 0
        })
Exemplo n.º 7
0
 def test_subtraction(self) -> None:
     self.assertEqual(
         common.Resources(workers=1) -
         common.Resources(workers=1, priests=4),
         common.Resources(workers=0, priests=-4))
     resources = common.Resources(workers=10)
     resources -= common.Resources(workers=1)
     self.assertEqual(resources, common.Resources(workers=9))
Exemplo n.º 8
0
    def test_engineer_player(self) -> None:
        test_player = player.Player(name="test",
                                    player_faction=faction.Engineers())

        # Halfling configuration.
        self.assertEqual(test_player.power, {
            common.PowerBowl.I: 3,
            common.PowerBowl.II: 9,
            common.PowerBowl.III: 0
        })
        self.assertEqual(test_player.resources,
                         common.Resources(coins=10, workers=2))
        self.assertEqual(test_player.used_town_keys, {})
        self.assertEqual(test_player.victory_points, 20)
Exemplo n.º 9
0
    def test_starting_resources(self) -> None:
        engineer = faction.Engineers()

        self.assertEqual(engineer.home_terrain(), common.Terrain.MOUNTAIN)
        self.assertEqual(engineer.starting_power(), {
            common.PowerBowl.I: 3,
            common.PowerBowl.II: 9,
            common.PowerBowl.III: 0
        })
        self.assertEqual(engineer.starting_resources(),
                         common.Resources(workers=2, coins=10))
        self.assertEqual(
            {
                common.CultTrack.AIR: 0,
                common.CultTrack.WATER: 0,
                common.CultTrack.FIRE: 0,
                common.CultTrack.EARTH: 0
            }, engineer.starting_cult_positions())
        self.assertEqual(engineer.staring_shipping(), 0)
Exemplo n.º 10
0
    def test_starting_resources(self) -> None:
        halfling = faction.Halflings()

        self.assertEqual(halfling.home_terrain(), common.Terrain.PLAIN)
        self.assertEqual(halfling.starting_power(), {
            common.PowerBowl.I: 3,
            common.PowerBowl.II: 9,
            common.PowerBowl.III: 0
        })
        self.assertEqual(halfling.starting_resources(),
                         common.Resources(workers=3, coins=15))
        self.assertEqual(
            {
                common.CultTrack.EARTH: 1,
                common.CultTrack.AIR: 1,
                common.CultTrack.WATER: 0,
                common.CultTrack.FIRE: 0
            }, halfling.starting_cult_positions())
        self.assertEqual(halfling.staring_shipping(), 0)
Exemplo n.º 11
0
    def test_player_build_dwellings(self) -> None:
        test_player = player.Player(name="test",
                                    player_faction=faction.Halflings())
        old_power = test_player.power.copy()

        # Halflings start with 15 coins and 3 workers, as well as 9
        # power in Bowl II and 3 power in Bowl I.
        test_player.build(common.Structure.DWELLING, adjacentEnemies=True)
        test_player.build(common.Structure.DWELLING, adjacentEnemies=True)
        # After building 2 dwellings, they should have 11 coin, 1 worker.
        self.assertEqual(test_player.resources,
                         common.Resources(coins=11, workers=1))
        # And they did not burn any power.
        self.assertEqual(test_player.power, old_power)
        # But they have two less Dwellings.
        self.assertEqual(
            test_player.structures[common.Structure.DWELLING],
            faction.Faction.TOTAL_STRUCTURES[common.Structure.DWELLING] - 2)
        self.assertEqual(
            test_player.built_structures[common.Structure.DWELLING], 2)
Exemplo n.º 12
0
    def test_player_collect_income_from_favorite_tiles(self) -> None:
        test_player = player.Player(name="test",
                                    player_faction=faction.Halflings())
        # Set bonus card and favor tiles.
        test_player.bonus_card = common.BonusCard.PRIEST
        test_player.favor_tiles = [
            common.FavorTile.POWER4_AIR2, common.FavorTile.COIN3_FIRE
        ]

        # Player receives 1 worker income (default for no structures).
        # Player receives 1 priest for bonus card.
        # Player receives 4 power and 3 coin for favor tiles.
        # New income should be 4 worker, 1 priest, 18 coin, 0/11/1
        test_player.collect_phase_ii_income()
        self.assertEqual(test_player.resources,
                         common.Resources(workers=4, priests=1, coins=18),
                         "Player resources %s. " % test_player.resources)
        self.assertEqual(
            test_player.power, {
                common.PowerBowl.I: 0,
                common.PowerBowl.II: 11,
                common.PowerBowl.III: 1
            })
Exemplo n.º 13
0
 def starting_resources(self) -> common.Resources:
     return common.Resources(workers=2, priests=0, coins=10, bridges=0)
Exemplo n.º 14
0
 def test_validation(self) -> None:
     self.assertTrue(common.Resources().is_valid())
     self.assertTrue(
         common.Resources(coins=1, workers=1, bridges=1,
                          priests=1).is_valid())
     self.assertFalse(common.Resources(coins=-1).is_valid())
Exemplo n.º 15
0
 def test_force_valid(self) -> None:
     invalidResources = common.Resources(coins=-1)
     self.assertFalse(invalidResources.is_valid())
     invalidResources.force_valid()
     self.assertTrue(invalidResources.is_valid())