def test_player_reinforces(self): player = GeneticPlayer() territory = Territory() territory.owner = player player.reinforce() self.assertEqual(4, territory.armies)
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)
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)
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'])
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)
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)
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()
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()
def test_new_territory_has_no_connections(self): t1 = Territory() self.assertEqual(0, t1.number_of_connections)
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())
def test_reinforce(self): t = Territory() t.reinforce(20) self.assertEqual(21, t.armies)
def test_new_territory_belongs_to_neutral_player(self): t1 = Territory() self.assertEqual(neutral_player(), t1.owner)
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)
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()
def test_new_territory_belongs_has_one_army(self): t1 = Territory() self.assertEqual(1, t1.armies)
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
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
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()
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()
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()