def test_reveal_creatures(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion( player, "Rd01", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) legion.reveal_creatures(["Ogre"]) assert legion.creature_names == ["Ogre", "Unknown", "Unknown", "Unknown"] legion.reveal_creatures(["Ogre", "Ogre"]) assert legion.creature_names == ["Ogre", "Ogre", "Unknown", "Unknown"] legion.reveal_creatures(["Ogre", "Ogre", "Troll"]) assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Unknown"] legion.reveal_creatures(["Troll"]) assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Unknown"] legion.reveal_creatures(["Troll", "Troll"]) assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Troll"] legion.add_creature_by_name("Ranger") legion.reveal_creatures(["Troll", "Troll", "Ranger"]) assert legion.creature_names == [ "Ogre", "Ogre", "Ranger", "Troll", "Troll" ] legion = Legion.Legion( player, "Rd01", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) legion.reveal_creatures(["Centaur", "Centaur", "Lion"]) assert legion.creature_names == ["Centaur", "Centaur", "Lion", "Unknown"]
def test_reveal_creatures(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) legion.reveal_creatures(["Ogre"]) assert legion.creature_names == ["Ogre", "Unknown", "Unknown", "Unknown"] legion.reveal_creatures(["Ogre", "Ogre"]) assert legion.creature_names == ["Ogre", "Ogre", "Unknown", "Unknown"] legion.reveal_creatures(["Ogre", "Ogre", "Troll"]) assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Unknown"] legion.reveal_creatures(["Troll"]) assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Unknown"] legion.reveal_creatures(["Troll", "Troll"]) assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Troll"] legion.add_creature_by_name("Ranger") legion.reveal_creatures(["Troll", "Troll", "Ranger"]) assert legion.creature_names == ["Ogre", "Ogre", "Ranger", "Troll", "Troll"] legion = Legion.Legion(player, "Rd01", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) legion.reveal_creatures(["Centaur", "Centaur", "Lion"]) assert legion.creature_names == ["Centaur", "Centaur", "Lion", "Unknown"]
def test_available_recruits_and_recruiters(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) caretaker = Caretaker.Caretaker() assert legion.available_recruits_and_recruiters("Marsh", caretaker) == [] assert legion.available_recruits_and_recruiters("Desert", caretaker) == [] assert legion.available_recruits_and_recruiters("Plains", caretaker) == [ ("Centaur", "Centaur"), ("Lion", "Centaur", "Centaur")] assert legion.available_recruits_and_recruiters("Brush", caretaker) == [ ("Gargoyle", "Gargoyle")] assert legion.available_recruits_and_recruiters("Tower", caretaker) == [ ("Ogre",), ("Centaur",), ("Gargoyle",), ("Warlock", "Titan")] caretaker.counts["Centaur"] = 0 assert legion.available_recruits_and_recruiters("Plains", caretaker) == [ ("Lion", "Centaur", "Centaur")] legion2 = Legion.Legion(player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Gargoyle", "Gargoyle"]), 1) assert legion2.available_recruits_and_recruiters("Tower", caretaker) == [ ("Ogre",), ("Gargoyle",), ("Warlock", "Titan"), ("Guardian", "Gargoyle", "Gargoyle", "Gargoyle")] assert legion2.available_recruits_and_recruiters("Brush", caretaker) == [ ("Gargoyle", "Gargoyle"), ("Cyclops", "Gargoyle", "Gargoyle")] legion3 = Legion.Legion(player, "Rd03", Creature.n2c(["Colossus"]), 1) assert legion3.available_recruits_and_recruiters("Tundra", caretaker) == [ ("Troll", "Colossus"), ("Warbear", "Colossus"), ("Giant", "Colossus"), ("Colossus", "Colossus")] assert legion3.available_recruits_and_recruiters("Mountains", caretaker) == [ ("Lion", "Colossus"), ("Minotaur", "Colossus"), ("Dragon", "Colossus"), ("Colossus", "Colossus")] assert legion3.available_recruits_and_recruiters("Marsh", caretaker) == [] legion4 = Legion.Legion(player, "Rd04", Creature.n2c(["Behemoth", "Cyclops", "Cyclops", "Cyclops"]), 1) assert legion4.available_recruits_and_recruiters("Brush", caretaker) == [ ("Gargoyle", "Cyclops"), ("Cyclops", "Cyclops"), ("Gorgon", "Cyclops", "Cyclops")] logging.info(legion4.available_recruits_and_recruiters("Jungle", caretaker)) assert legion4.available_recruits_and_recruiters("Jungle", caretaker) == [ ("Gargoyle", "Cyclops"), ("Gargoyle", "Behemoth"), ("Cyclops", "Cyclops"), ("Cyclops", "Behemoth"), ("Behemoth", "Cyclops", "Cyclops", "Cyclops"), ("Behemoth", "Behemoth"), ]
def split_legion(self, parent_markerid, child_markerid, parent_creature_names, child_creature_names): logging.info("%s %s %s %s", parent_markerid, child_markerid, parent_creature_names, child_creature_names) parent = self.markerid_to_legion.get(parent_markerid) if parent is None: return if child_markerid not in self.markerids_left: raise AssertionError("illegal marker") if ( Counter(parent_creature_names) + Counter(child_creature_names) != Counter(parent.creature_names) and Counter(parent_creature_names) + Counter(child_creature_names) != Counter({"Unknown": len(parent)}) ): raise AssertionError("wrong creatures", "parent.creature_names", parent.creature_names, "parent_creature_names", parent_creature_names, "child_creature_names", child_creature_names) new_legion1 = Legion.Legion(self, parent_markerid, Creature.n2c(parent_creature_names), parent.hexlabel) new_legion2 = Legion.Legion(self, child_markerid, Creature.n2c(child_creature_names), parent.hexlabel) if not parent.is_legal_split(new_legion1, new_legion2): raise AssertionError("illegal split") del new_legion1 parent.creatures = Creature.n2c(parent_creature_names) for creature in parent.creatures: creature.legion = parent self.take_marker(child_markerid) new_legion2.add_observer(self.game) self.markerid_to_legion[child_markerid] = new_legion2 del parent # One action for our player with creature names action = Action.SplitLegion(self.game.name, self.name, parent_markerid, child_markerid, parent_creature_names, child_creature_names) logging.info(action) self.notify(action, names=[self.name]) # Another action for everyone (including our player, who will # ignore it as a duplicate) without creature names. action = Action.SplitLegion(self.game.name, self.name, parent_markerid, child_markerid, len(parent_creature_names) * ["Unknown"], len(child_creature_names) * ["Unknown"]) logging.info(action) self.notify(action)
def test_any_summonable(): creatures = Creature.n2c(["Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_summonable creatures = Creature.n2c(["Angel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_summonable creatures = Creature.n2c(["Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert not legion.any_summonable
def test_is_legal_split(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) parent = Legion.Legion(player, "Rd01", creatures, 1) child1 = Legion.Legion(player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Ogre"]), 1) child2 = Legion.Legion( player, "Rd03", Creature.n2c(["Angel", "Gargoyle", "Centaur", "Centaur"]), 1) assert parent.is_legal_split(child1, child2) assert not parent.is_legal_split(child1, child1) parent2 = Legion.Legion( player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Troll", "Centaur"]), 1) child3 = Legion.Legion( player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Troll"]), 1) child4 = Legion.Legion(player, "Rd03", Creature.n2c(["Centaur"]), 1) assert not parent2.is_legal_split(child3, child4) child5 = Legion.Legion( player, "Rd01", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) child6 = Legion.Legion( player, "Rd03", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) assert parent.is_legal_split(child5, child6)
def split_legion(self, parent_markerid, child_markerid, parent_creature_names, child_creature_names): logging.info("%s %s %s %s", parent_markerid, child_markerid, parent_creature_names, child_creature_names) parent = self.markerid_to_legion.get(parent_markerid) if parent is None: return if child_markerid not in self.markerids_left: raise AssertionError("illegal marker") if (bag(parent.creature_names) != bag(parent_creature_names).union( bag(child_creature_names)) and bag(parent_creature_names).union(bag(child_creature_names)) != bag({"Unknown": len(parent)})): raise AssertionError("wrong creatures", "parent.creature_names", parent.creature_names, "parent_creature_names", parent_creature_names, "child_creature_names", child_creature_names) new_legion1 = Legion.Legion(self, parent_markerid, Creature.n2c(parent_creature_names), parent.hexlabel) new_legion2 = Legion.Legion(self, child_markerid, Creature.n2c(child_creature_names), parent.hexlabel) if not parent.is_legal_split(new_legion1, new_legion2): raise AssertionError("illegal split") del new_legion1 parent.creatures = Creature.n2c(parent_creature_names) for creature in parent.creatures: creature.legion = parent self.take_marker(child_markerid) new_legion2.add_observer(self.game) self.markerid_to_legion[child_markerid] = new_legion2 del parent # One action for our player with creature names action = Action.SplitLegion(self.game.name, self.name, parent_markerid, child_markerid, parent_creature_names, child_creature_names) logging.info(action) self.notify(action, names=[self.name]) # Another action for everyone (including our player, who will # ignore it as a duplicate) without creature names. action = Action.SplitLegion(self.game.name, self.name, parent_markerid, child_markerid, len(parent_creature_names) * ["Unknown"], len(child_creature_names) * ["Unknown"]) logging.info(action) self.notify(action)
def test_score(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.score == 120
def test_add_creature_by_name(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert len(legion) == 8 try: legion.add_creature_by_name("Cyclops") except ValueError: pass else: assert False legion.remove_creature_by_name("Gargoyle") assert len(legion) == 7 try: legion.add_creature_by_name("Cyclops") except ValueError: pass else: assert False assert "Gargoyle" in legion.creature_names legion.remove_creature_by_name("Gargoyle") assert len(legion) == 6 assert "Gargoyle" not in legion.creature_names legion.add_creature_by_name("Troll") assert len(legion) == 7 assert "Troll" in legion.creature_names
def test_remove_creature_by_name(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert len(legion) == 8 legion.remove_creature_by_name("Gargoyle") assert len(legion) == 7 assert "Gargoyle" in legion.creature_names legion.remove_creature_by_name("Gargoyle") assert len(legion) == 6 assert "Gargoyle" not in legion.creature_names try: legion.remove_creature_by_name("Gargoyle") except ValueError: pass else: assert False legion.remove_creature_by_name("Ogre") legion.remove_creature_by_name("Ogre") legion.remove_creature_by_name("Centaur") legion.remove_creature_by_name("Centaur") legion.remove_creature_by_name("Titan") assert len(legion) == 1 assert legion legion.remove_creature_by_name("Angel") assert len(legion) == 0 assert legion
def test_any_summonable(): creatures = Creature.n2c([ "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur" ]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_summonable creatures = Creature.n2c([ "Angel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur" ]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_summonable creatures = Creature.n2c( ["Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert not legion.any_summonable
def test_picname(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.picname == "Cross" legion = Legion.Legion( player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.picname == "Eagle" legion = Legion.Legion( player, "Gr12", Creature.n2c(["Gargoyle", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.picname == "Ourobouros"
def update_creatures(self, game): """Update creatures in game from self.aps.""" for legion in game.all_legions(): markerid = legion.markerid node = self.aps.get_leaf(markerid) if node and node.creature_names != legion.creature_names: legion.creatures = Creature.n2c(node.creature_names) for creature in legion.creatures: creature.legion = legion
def test_creature_names(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.creature_names == ["Angel", "Centaur", "Centaur", "Gargoyle", "Gargoyle", "Ogre", "Ogre", "Titan"]
def test_sorted_creatures(): creatures = Creature.n2c(["Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"]) legion = Legion.Legion(None, "Rd01", creatures, 1) li = legion.sorted_creatures assert len(li) == len(creatures) == len(legion) names = [creature.name for creature in li] assert names == ["Archangel", "Serpent", "Ranger", "Minotaur", "Gargoyle", "Centaur", "Ogre"]
def test_picname(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.picname == "Cross" legion = Legion.Legion(player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.picname == "Eagle" legion = Legion.Legion(player, "Gr12", Creature.n2c(["Gargoyle", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.picname == "Ourobouros"
def test_creature_names(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.creature_names == [ "Angel", "Centaur", "Centaur", "Gargoyle", "Gargoyle", "Ogre", "Ogre", "Titan" ]
def test_num_lords(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.num_lords == 2 assert not legion.can_flee legion = Legion.Legion( player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.num_lords == 1 assert not legion.can_flee legion = Legion.Legion( player, "Rd02", Creature.n2c(["Gargoyle", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.num_lords == 0 assert legion.can_flee
def test_unknown(): creatures = Creature.n2c(["Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert not legion.any_unknown assert legion.all_known assert not legion.all_unknown creatures = Creature.n2c(["Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Unknown"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_unknown assert not legion.all_known assert not legion.all_unknown creatures = Creature.n2c(8 * ["Unknown"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_unknown assert not legion.all_known assert legion.all_unknown
def test_find_creature(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.find_creature("Titan", "DEFENDER") is None for creature in legion.creatures: creature.hexlabel = "DEFENDER" assert legion.find_creature("Titan", "DEFENDER") is not None assert legion.find_creature("Ogre", "DEFENDER") is not None assert legion.find_creature("Titan", "ATTACKER") is None assert legion.find_creature("Ogre", "ATTACKER") is None
def test_num_lords(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) assert legion.num_lords == 2 assert not legion.can_flee legion = Legion.Legion(player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.num_lords == 1 assert not legion.can_flee legion = Legion.Legion(player, "Rd02", Creature.n2c(["Gargoyle", "Gargoyle", "Centaur", "Centaur"]), 1) assert legion.num_lords == 0 assert legion.can_flee
def test_sorted_creatures(): creatures = Creature.n2c([ "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur" ]) legion = Legion.Legion(None, "Rd01", creatures, 1) li = legion.sorted_creatures assert len(li) == len(creatures) == len(legion) names = [creature.name for creature in li] assert names == [ "Archangel", "Serpent", "Ranger", "Minotaur", "Gargoyle", "Centaur", "Ogre" ]
def test_unknown(): creatures = Creature.n2c([ "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur" ]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert not legion.any_unknown assert legion.all_known assert not legion.all_unknown creatures = Creature.n2c([ "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Unknown" ]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_unknown assert not legion.all_known assert not legion.all_unknown creatures = Creature.n2c(8 * ["Unknown"]) legion = Legion.Legion(None, "Rd01", creatures, 1) assert legion.any_unknown assert not legion.all_known assert legion.all_unknown
def test_could_recruit(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion( player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) caretaker = Caretaker.Caretaker() assert not legion.could_recruit("Marsh", caretaker) assert not legion.could_recruit("Desert", caretaker) assert legion.could_recruit("Plains", caretaker) assert legion.could_recruit("Brush", caretaker) assert legion.could_recruit("Tower", caretaker)
def test_could_recruit(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) caretaker = Caretaker.Caretaker() assert not legion.could_recruit("Marsh", caretaker) assert not legion.could_recruit("Desert", caretaker) assert legion.could_recruit("Plains", caretaker) assert legion.could_recruit("Brush", caretaker) assert legion.could_recruit("Tower", caretaker)
def test_available_recruits(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion( player, "Rd02", Creature.n2c(["Titan", "Lion", "Gargoyle", "Centaur", "Centaur"]), 1) caretaker = Caretaker.Caretaker() assert legion.available_recruits("Marsh", caretaker) == [] assert legion.available_recruits("Desert", caretaker) == ["Lion"] assert legion.available_recruits("Plains", caretaker) == ["Centaur", "Lion"] assert legion.available_recruits("Brush", caretaker) == ["Gargoyle"] assert legion.available_recruits( "Tower", caretaker) == ["Ogre", "Centaur", "Gargoyle", "Warlock"]
def test_combat_value(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd01", creatures, 1) # No terrain legion.hexlabel = None assert legion.terrain_combat_value == legion.combat_value # Plains legion.hexlabel = 1 assert legion.terrain_combat_value == legion.combat_value # Woods legion.hexlabel = 2 assert legion.terrain_combat_value == legion.combat_value # Brush legion.hexlabel = 3 assert legion.terrain_combat_value > legion.combat_value # Hills legion.hexlabel = 4 assert legion.terrain_combat_value > legion.combat_value # Jungle legion.hexlabel = 5 assert legion.terrain_combat_value > legion.combat_value # Desert legion.hexlabel = 7 assert legion.terrain_combat_value == legion.combat_value # Marsh legion.hexlabel = 8 assert legion.terrain_combat_value > legion.combat_value # Swamp legion.hexlabel = 14 assert legion.terrain_combat_value > legion.combat_value # Tower legion.hexlabel = 100 assert legion.terrain_combat_value > legion.combat_value # Mountains legion.hexlabel = 1000 assert legion.terrain_combat_value == legion.combat_value # Tundra legion.hexlabel = 2000 assert legion.terrain_combat_value == legion.combat_value
def test_can_summon(): now = time.time() game = Game.Game("g1", "p1", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player1 = Player.Player("p1", game, 0) player1.assign_color("Red") game.players.append(player1) legion1 = Legion.Legion(player1, "Rd01", creatures, 1) player1.markerid_to_legion[legion1.markerid] = legion1 assert not legion1.can_summon player1.split_legion("Rd01", "Rd02", ["Titan", "Centaur", "Ogre", "Gargoyle"], ["Angel", "Centaur", "Ogre", "Gargoyle"]) assert legion1.can_summon legion2 = player1.markerid_to_legion["Rd02"] legion2.move(2, False, None, 1) assert legion1.can_summon assert not legion2.can_summon
def test_is_legal_split(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player = Player.Player("p0", game, 0) parent = Legion.Legion(player, "Rd01", creatures, 1) child1 = Legion.Legion(player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Ogre"]), 1) child2 = Legion.Legion(player, "Rd03", Creature.n2c(["Angel", "Gargoyle", "Centaur", "Centaur"]), 1) assert parent.is_legal_split(child1, child2) assert not parent.is_legal_split(child1, child1) parent2 = Legion.Legion(player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Troll", "Centaur"]), 1) child3 = Legion.Legion(player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Troll"]), 1) child4 = Legion.Legion(player, "Rd03", Creature.n2c(["Centaur"]), 1) assert not parent2.is_legal_split(child3, child4) child5 = Legion.Legion(player, "Rd01", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) child6 = Legion.Legion(player, "Rd03", Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1) assert parent.is_legal_split(child5, child6)
def test_engaged(): now = time.time() game = Game.Game("g1", "p1", now, now, 2, 6) creatures = Creature.n2c(creaturedata.starting_creature_names) player1 = Player.Player("p1", game, 0) player1.color = "Red" game.players.append(player1) legion1 = Legion.Legion(player1, "Rd01", creatures, 1) player1.markerid_to_legion[legion1.markerid] = legion1 player2 = Player.Player("p2", game, 1) player2.color = "Blue" game.players.append(player2) legion2 = Legion.Legion(player2, "Bu01", creatures, 2) player2.markerid_to_legion[legion2.markerid] = legion2 assert not legion1.engaged assert not legion2.engaged legion2.move(1, False, None, 1) assert legion1.engaged assert legion2.engaged
def test_available_recruits(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion(player, "Rd02", Creature.n2c(["Titan", "Lion", "Gargoyle", "Centaur", "Centaur"]), 1) caretaker = Caretaker.Caretaker() assert legion.available_recruits("Marsh", caretaker) == [] assert legion.available_recruits("Desert", caretaker) == ["Lion"] assert legion.available_recruits("Plains", caretaker) == ["Centaur", "Lion"] assert legion.available_recruits("Brush", caretaker) == ["Gargoyle"] assert legion.available_recruits("Tower", caretaker) == ["Ogre", "Centaur", "Gargoyle", "Warlock"]
if __name__ == "__main__": import time from slugathon.game import Creature, Legion, Player, Game now = time.time() game_name = "Game1" attacker_playername = "Roar!" game = Game.Game("g1", attacker_playername, now, now, 2, 6) attacker_player = Player.Player(attacker_playername, game, 0) attacker_player.color = "Black" attacker_creature_names = ["Titan", "Colossus", "Serpent", "Hydra", "Archangel", "Angel", "Unicorn"] attacker_creatures = Creature.n2c(attacker_creature_names) attacker_legion = Legion.Legion(attacker_player, "Bk01", attacker_creatures, 1) defender_playername = "Eek!" defender_player = Player.Player(defender_playername, game, 0) defender_player.color = "Gold" defender_creature_names = ["Ogre", "Centaur", "Gargoyle"] defender_creatures = Creature.n2c(defender_creature_names) defender_legion = Legion.Legion(defender_player, "Rd01", defender_creatures, 1) def my_callback(*args): logging.info("callback %s", args) reactor.stop()
def forget_creatures(self): """Make all creatures Unknown.""" self.creatures = Creature.n2c(len(self) * ["Unknown"]) for creature in self.creatures: creature.legion = self
chit.recruiter_names)) self.destroy() def cb_cancel(self, widget, response_id): """The cancel button was pressed, so exit""" self.deferred.callback((self.legion, None, None)) self.destroy() if __name__ == "__main__": import time from slugathon.game import Legion, Player, Game from slugathon.util import guiutils creature_names = ["Titan", "Dragon", "Dragon", "Minotaur", "Minotaur"] creatures = Creature.n2c(creature_names) def my_callback((legion, creature, recruiter_names)): logging.info("%s recruited %s %s", legion, creature, recruiter_names) guiutils.exit() now = time.time() playername = "p0" game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player(playername, game, 0) player.color = "Red" legion = Legion.Legion(player, "Rd01", creatures, 1) legion.hexlabel = 1000 masterhex = game.board.hexes[legion.hexlabel] mterrain = masterhex.terrain pickrecruit, def1 = new(playername, legion, mterrain, game.caretaker, None)
(self.legion, chit.recruit, chit.recruiter_names)) self.destroy() def cb_cancel(self, widget, response_id): """The cancel button was pressed, so exit""" self.deferred.callback((self.legion, None, None)) self.destroy() if __name__ == "__main__": import time from slugathon.game import Legion, Player, Game from slugathon.util import guiutils creature_names = ["Titan", "Dragon", "Dragon", "Minotaur", "Minotaur"] creatures = Creature.n2c(creature_names) def my_callback((legion, creature, recruiter_names)): logging.info("%s recruited %s %s", legion, creature, recruiter_names) guiutils.exit() now = time.time() playername = "p0" game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player(playername, game, 0) player.color = "Red" legion = Legion.Legion(player, "Rd01", creatures, 1) legion.hexlabel = 1000 masterhex = game.board.hexes[legion.hexlabel] mterrain = masterhex.terrain pickrecruit, def1 = new(playername, legion, mterrain, game.caretaker, None)
if __name__ == "__main__": import time from slugathon.game import Creature, Legion, Player, Game now = time.time() attacker_playername = "Roar!" game = Game.Game("g1", attacker_playername, now, now, 2, 6) attacker_player = Player.Player(attacker_playername, game, 0) attacker_player.color = "Black" attacker_creature_names = [ "Titan", "Colossus", "Serpent", "Hydra", "Archangel", "Angel", "Unicorn" ] attacker_creatures = Creature.n2c(attacker_creature_names) attacker_legion = Legion.Legion(attacker_player, "Bk01", attacker_creatures, 1) defender_playername = "Eek!" defender_player = Player.Player(defender_playername, game, 0) defender_player.color = "Gold" defender_creature_names = ["Ogre", "Centaur", "Gargoyle"] defender_creatures = Creature.n2c(defender_creature_names) defender_legion = Legion.Legion(defender_player, "Rd01", defender_creatures, 1) def my_callback((attacker, defender, fled)): logging.info("fled is %s", fled) reactor.stop()
isinstance(action, Action.StartManeuverBattlePhase) or isinstance(action, Action.StartStrikeBattlePhase) or isinstance(action, Action.StartCounterstrikeBattlePhase) or isinstance(action, Action.StartReinforceBattlePhase)): self._init_battle() if __name__ == "__main__": import time from slugathon.util import guiutils from slugathon.game import Game, Player, Creature from slugathon.data import creaturedata now = time.time() playername = "p1" creatures = Creature.n2c(creaturedata.starting_creature_names) game = Game.Game("g1", "Player 1", now, now, 2, 6) player1 = game.players[0] player1.assign_starting_tower(600) player1.assign_color("Red") player1.pick_marker("Rd01") player1.create_starting_legion() game.active_player = player1 player2 = Player.Player("Player 2", game, 1) player2.assign_starting_tower(500) player2.assign_color("Blue") player2.pick_marker("Bu02") player2.create_starting_legion() game.players.append(player2)
def test_available_recruits_and_recruiters(): now = time.time() game = Game.Game("g1", "p0", now, now, 2, 6) player = Player.Player("p0", game, 0) legion = Legion.Legion( player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1) caretaker = Caretaker.Caretaker() assert legion.available_recruits_and_recruiters("Marsh", caretaker) == [] assert legion.available_recruits_and_recruiters("Desert", caretaker) == [] assert legion.available_recruits_and_recruiters("Plains", caretaker) == [ ("Centaur", "Centaur"), ("Lion", "Centaur", "Centaur") ] assert legion.available_recruits_and_recruiters("Brush", caretaker) == [ ("Gargoyle", "Gargoyle") ] assert legion.available_recruits_and_recruiters("Tower", caretaker) == [ ("Ogre", ), ("Centaur", ), ("Gargoyle", ), ("Warlock", "Titan") ] caretaker.counts["Centaur"] = 0 assert legion.available_recruits_and_recruiters("Plains", caretaker) == [ ("Lion", "Centaur", "Centaur") ] legion2 = Legion.Legion( player, "Rd02", Creature.n2c(["Titan", "Gargoyle", "Gargoyle", "Gargoyle"]), 1) assert legion2.available_recruits_and_recruiters("Tower", caretaker) == [ ("Ogre", ), ("Gargoyle", ), ("Warlock", "Titan"), ("Guardian", "Gargoyle", "Gargoyle", "Gargoyle") ] assert legion2.available_recruits_and_recruiters("Brush", caretaker) == [ ("Gargoyle", "Gargoyle"), ("Cyclops", "Gargoyle", "Gargoyle") ] legion3 = Legion.Legion(player, "Rd03", Creature.n2c(["Colossus"]), 1) assert legion3.available_recruits_and_recruiters("Tundra", caretaker) == [ ("Troll", "Colossus"), ("Warbear", "Colossus"), ("Giant", "Colossus"), ("Colossus", "Colossus") ] assert legion3.available_recruits_and_recruiters( "Mountains", caretaker) == [("Lion", "Colossus"), ("Minotaur", "Colossus"), ("Dragon", "Colossus"), ("Colossus", "Colossus")] assert legion3.available_recruits_and_recruiters("Marsh", caretaker) == [] legion4 = Legion.Legion( player, "Rd04", Creature.n2c(["Behemoth", "Cyclops", "Cyclops", "Cyclops"]), 1) assert legion4.available_recruits_and_recruiters("Brush", caretaker) == [ ("Gargoyle", "Cyclops"), ("Cyclops", "Cyclops"), ("Gorgon", "Cyclops", "Cyclops") ] logging.info(legion4.available_recruits_and_recruiters( "Jungle", caretaker)) assert legion4.available_recruits_and_recruiters("Jungle", caretaker) == [ ("Gargoyle", "Cyclops"), ("Gargoyle", "Behemoth"), ("Cyclops", "Cyclops"), ("Cyclops", "Behemoth"), ("Behemoth", "Cyclops", "Cyclops", "Cyclops"), ("Behemoth", "Behemoth"), ]