Example #1
0
    def test_player_reinforces(self):
        player = GeneticPlayer()
        territory = Territory()
        territory.owner = player

        player.reinforce()
        self.assertEqual(4, territory.armies)
Example #2
0
    def test_player_has_reinforcement_for_every_continent(self):
        player = Player()
        t = Territory()
        Continent([t], bonus_value=10)
        t.owner = player

        armies = player.count_reinforcements()
        self.assertEqual(10, armies)
Example #3
0
    def test_player_has_reinforcement_for_every_three_territories(self):
        player = Player()
        for _ in range(13):
            t = Territory()
            t.owner = player

        armies = player.count_reinforcements()
        self.assertEqual(4, armies)
Example #4
0
 def _fortify_ranking(self, source: Territory, destination: Territory):
     return (source.bordering_enemies() *
             self._weights['frt_bordering_enemies'] +
             source.vantage() * self._weights['frt_army_vantage'] +
             source.number_of_connections *
             self._weights['frt_a_number_of_connections'] +
             destination.number_of_connections *
             self._weights['frt_d_number_of_connections'] +
             source.armies * self._weights['frt_a_size'] +
             destination.armies * self._weights['frt_d_size'])
Example #5
0
    def test_prob(self):
        a = Territory()
        a.reinforce(3)
        a.owner = TestPlayer((1, 4, 5))

        d = Territory()
        d.owner = TestPlayer((2, ))
        d.connect(a)

        b = Battle(a, d)
        b.resolve()

        self.assertIs(a.owner, d.owner)
Example #6
0
 def test_fortify(self):
     t = Territory()
     from_t = Territory()
     from_t.reinforce(20)
     t.fortify(from_t, 20)
     self.assertEqual(21, t.armies)
     self.assertEqual(1, from_t.armies)
Example #7
0
def south_america() -> Dict[str, Territory]:
    venezuela = Territory('Venezuela')
    peru = Territory('Peru')
    brazil = Territory('Brazil')
    argentina = Territory('Argentina')

    venezuela.connect(peru)
    venezuela.connect(brazil)

    peru.connect(brazil)
    peru.connect(argentina)

    brazil.connect(argentina)

    return locals()
Example #8
0
def asia() -> Dict[str, Territory]:
    ural = Territory('Ural')
    siberia = Territory('Siberia')
    yakutsk = Territory('Yakutsk')
    kamchatka = Territory('Kamchatka')
    irkutsk = Territory('Irkutsk')
    mongolia = Territory('Mongolia')
    japan = Territory('Japan')
    afghanistan = Territory('Afghanistan')
    china = Territory('China')
    middle_east = Territory('Middle East')
    india = Territory('India')
    siam = Territory('Siam')

    ural.connect(siberia)
    ural.connect(china)
    ural.connect(afghanistan)

    siberia.connect(yakutsk)
    siberia.connect(irkutsk)
    siberia.connect(mongolia)
    siberia.connect(china)

    yakutsk.connect(kamchatka)
    yakutsk.connect(irkutsk)

    kamchatka.connect(irkutsk)
    kamchatka.connect(mongolia)
    kamchatka.connect(japan)

    irkutsk.connect(mongolia)

    mongolia.connect(china)
    mongolia.connect(japan)

    afghanistan.connect(china)
    afghanistan.connect(india)
    afghanistan.connect(middle_east)

    china.connect(india)
    china.connect(siam)

    middle_east.connect(india)

    india.connect(siam)

    return locals()
Example #9
0
 def test_new_territory_has_no_connections(self):
     t1 = Territory()
     self.assertEqual(0, t1.number_of_connections)
Example #10
0
    def test_bordering_enemies(self):
        first_player = Player()
        second_player = Player()

        t1 = Territory()
        t2 = Territory()
        t3 = Territory()

        t1.owner = first_player
        t2.owner = first_player
        t3.owner = second_player

        t2.reinforce(1)
        t3.reinforce(2)

        t1.connect(t2)
        t1.connect(t3)

        self.assertEqual(3, t1.bordering_enemies())
Example #11
0
 def test_reinforce(self):
     t = Territory()
     t.reinforce(20)
     self.assertEqual(21, t.armies)
Example #12
0
 def test_new_territory_belongs_to_neutral_player(self):
     t1 = Territory()
     self.assertEqual(neutral_player(), t1.owner)
Example #13
0
 def test_can_connect(self):
     t1 = Territory()
     t2 = Territory()
     t1.connect(t2)
     self.assertEqual(1, t1.number_of_connections)
     self.assertEqual(1, t2.number_of_connections)
Example #14
0
def europe() -> Dict[str, Territory]:
    russia = Territory('Russia')
    scandinavia = Territory('Scandinavia')
    northern_europe = Territory('Northern Europe')
    southern_europe = Territory('Southern Europe')
    western_europe = Territory('Western Europe')
    great_britain = Territory('Great Britain')
    iceland = Territory('Iceland')

    russia.connect(scandinavia)
    russia.connect(northern_europe)
    russia.connect(southern_europe)

    scandinavia.connect(iceland)
    scandinavia.connect(great_britain)
    scandinavia.connect(northern_europe)

    northern_europe.connect(southern_europe)
    northern_europe.connect(great_britain)
    northern_europe.connect(western_europe)

    southern_europe.connect(western_europe)

    great_britain.connect(iceland)

    return locals()
Example #15
0
 def test_new_territory_belongs_has_one_army(self):
     t1 = Territory()
     self.assertEqual(1, t1.armies)
Example #16
0
def failed_attack():
    defending = Territory()
    defending.reinforce(1)
    defender = TestPlayer((1, 4))
    defending.owner = defender

    attacking = Territory()
    attacking.reinforce(2)
    attacker = TestPlayer((4, 2))
    attacking.owner = attacker

    attacking.connect(defending)

    battle = Battle(attacking, defending)
    battle.resolve()
    return attacking, defending
Example #17
0
def successful_attack():
    defending = Territory()
    defending.reinforce(1)
    losing_player = TestPlayer((1, 1))
    defending.owner = losing_player

    attacking = Territory()
    attacking.reinforce(2)
    winning_player = TestPlayer((6, 6, 6))
    attacking.owner = winning_player

    attacking.connect(defending)

    battle = Battle(attacking, defending)
    battle.resolve()
    return attacking, defending
Example #18
0
def africa() -> Dict[str, Territory]:
    north_africa = Territory('North Africa')
    egypt = Territory('Egypt')
    east_africa = Territory('East Africa')
    congo = Territory('Congo')
    south_africa = Territory('South Africa')
    madagascar = Territory('Madagascar')

    north_africa.connect(egypt)
    north_africa.connect(east_africa)
    north_africa.connect(congo)

    egypt.connect(east_africa)

    east_africa.connect(congo)
    east_africa.connect(south_africa)
    east_africa.connect(madagascar)

    congo.connect(south_africa)

    south_africa.connect(madagascar)

    return locals()
Example #19
0
def oceania() -> Dict[str, Territory]:
    indonesia = Territory('Indonesia')
    new_guinea = Territory('New Guinea')
    western_australia = Territory('Western Australia')
    eastern_australia = Territory('Eastern Australia')

    indonesia.connect(new_guinea)
    indonesia.connect(western_australia)

    new_guinea.connect(eastern_australia)
    new_guinea.connect(western_australia)

    western_australia.connect(eastern_australia)

    return locals()
Example #20
0
def north_america() -> Dict[str, Territory]:
    alaska = Territory('Alaska')
    northwest_territory = Territory('Northwest Territory')
    greenland = Territory('Greenland')
    alberta = Territory('Alberta')
    ontario = Territory('Ontario')
    quebec = Territory('Quebec')
    western_united_states = Territory('Western United States')
    eastern_united_states = Territory('Eastern United States')
    central_america = Territory('Central America')

    alaska.connect(northwest_territory)
    alaska.connect(alberta)

    northwest_territory.connect(greenland)
    northwest_territory.connect(alberta)
    northwest_territory.connect(ontario)

    greenland.connect(ontario)
    greenland.connect(quebec)

    alberta.connect(ontario)
    alberta.connect(western_united_states)

    ontario.connect(quebec)
    ontario.connect(western_united_states)
    ontario.connect(eastern_united_states)

    western_united_states.connect(central_america)
    western_united_states.connect(eastern_united_states)

    eastern_united_states.connect(central_america)

    return locals()