Exemplo n.º 1
0
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
Exemplo n.º 2
0
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"]
Exemplo n.º 3
0
def test_friendly_legions():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(100)
    player.assign_color("Red")
    player.pick_marker("Rd01")
    player.create_starting_legion()
    legion1 = player.markerid_to_legion["Rd01"]
    player.split_legion("Rd01", "Rd02", ["Titan", "Ogre", "Ogre", "Gargoyle"],
                        ["Angel", "Gargoyle", "Centaur", "Centaur"])
    legion2 = player.markerid_to_legion["Rd02"]
    assert player.friendly_legions() == set([legion1, legion2])
    assert player.friendly_legions(100) == set([legion1, legion2])
    assert player.friendly_legions(200) == set()
    legion1.move(8, False, None, 1)
    assert player.friendly_legions() == set([legion1, legion2])
    assert player.friendly_legions(100) == set([legion2])
    assert player.friendly_legions(8) == set([legion1])
    assert player.friendly_legions(200) == set()
    legion2.move(200, True, "Angel", 3)
    assert player.friendly_legions() == set([legion1, legion2])
    assert player.friendly_legions(100) == set()
    assert player.friendly_legions(8) == set([legion1])
    assert player.friendly_legions(200) == set([legion2])
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def test_create_starting_legion():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    try:
        player.create_starting_legion()
    except Exception:
        pass
    else:
        assert False
    player.selected_markerid = "Bu01"
    try:
        player.create_starting_legion()
    except Exception:
        pass
    else:
        assert False
    player.pick_marker("Rd01")
    player.create_starting_legion()
    player.pick_marker("Rd02")
    try:
        player.create_starting_legion()
    except Exception:
        pass
    else:
        assert False
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def test_update_finish_order_3_draws():
    now = time.time()
    game = Game.Game("g1", "ai1", now, now, 2, 6)
    game.add_player("ai2")
    game.add_player("ai3")
    game.add_player("ai4")
    game.add_player("ai5")
    game.add_player("ai6")
    ai1 = game.get_player_by_name("ai1")
    ai2 = game.get_player_by_name("ai2")
    ai3 = game.get_player_by_name("ai3")
    ai4 = game.get_player_by_name("ai4")
    ai5 = game.get_player_by_name("ai5")
    ai6 = game.get_player_by_name("ai6")
    ai1.assign_starting_tower(600)
    ai2.assign_starting_tower(500)
    ai3.assign_starting_tower(400)
    ai4.assign_starting_tower(300)
    ai5.assign_starting_tower(200)
    ai6.assign_starting_tower(100)
    ai1.assign_color("Red")
    ai2.assign_color("Blue")
    ai3.assign_color("Black")
    ai4.assign_color("Brown")
    ai5.assign_color("Green")
    ai6.assign_color("Gold")
    for player in game.players:
        player.pick_marker(player.color_abbrev + "01")
        player.create_starting_legion()
    ai3.die(ai5, False)
    ai3.markerid_to_legion = {}
    assert ai3.dead
    ai5.die(ai3, True)
    ai5.markerid_to_legion = {}
    assert ai5.dead
    game._update_finish_order(ai3, ai5)
    game._update_finish_order(ai5, ai3)
    assert game.finish_order == [(ai3, ai5)]
    ai2.die(ai6, False)
    ai2.markerid_to_legion = {}
    assert ai2.dead
    ai6.die(ai2, True)
    ai6.markerid_to_legion = {}
    assert ai6.dead
    game._update_finish_order(ai2, ai6)
    game._update_finish_order(ai6, ai2)
    assert game.finish_order == [(ai2, ai6), (ai3, ai5)]
    ai4.die(ai1, False)
    ai4.markerid_to_legion = {}
    assert ai4.dead
    ai1.die(ai4, True)
    ai1.markerid_to_legion = {}
    assert ai1.dead
    game._update_finish_order(ai4, ai1)
    game._update_finish_order(ai1, ai4)
    assert game.finish_order == [(ai4, ai1), (ai2, ai6), (ai3, ai5)]
Exemplo n.º 9
0
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"
    ]
Exemplo n.º 10
0
def test_num_creatures():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    player.pick_marker("Rd01")
    assert player.selected_markerid == "Rd01"
    player.create_starting_legion()
    assert player.num_creatures == 8
Exemplo n.º 11
0
def test_pick_marker():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    player.pick_marker("Bu01")
    assert player.selected_markerid is None
    player.pick_marker("Rd01")
    assert player.selected_markerid == "Rd01"
Exemplo n.º 12
0
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
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
def test_take_marker():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    try:
        player.take_marker("Bu01")
    except Exception:
        pass
    else:
        assert False
    player.take_marker("Rd01")
    assert len(player.markerids_left) == 11
Exemplo n.º 15
0
def test_can_exit_split_phase():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    player.pick_marker("Rd01")
    assert player.selected_markerid == "Rd01"
    player.create_starting_legion()
    assert len(player.markerid_to_legion) == 1
    assert not player.can_exit_split_phase

    player.split_legion("Rd01", "Rd02", ["Titan", "Ogre", "Ogre", "Gargoyle"],
                        ["Angel", "Centaur", "Centaur", "Gargoyle"])
    assert player.can_exit_split_phase
Exemplo n.º 16
0
def test_sorted_legions():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    player.pick_marker("Rd01")
    assert player.selected_markerid == "Rd01"
    player.create_starting_legion()
    assert player.can_split
    player.split_legion("Rd01", "Rd02", ["Titan", "Ogre", "Ogre", "Gargoyle"],
                        ["Angel", "Centaur", "Centaur", "Gargoyle"])
    sorted_legions = player.sorted_legions
    assert len(sorted_legions) == 2
    assert sorted_legions[0].has_titan
    assert not sorted_legions[1].has_titan
Exemplo n.º 17
0
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"
Exemplo n.º 18
0
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"]
Exemplo n.º 19
0
def test_can_exit_move_phase():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(100)
    player.assign_color("Red")
    player.pick_marker("Rd01")
    player.create_starting_legion()
    legion1 = player.markerid_to_legion["Rd01"]
    player.split_legion("Rd01", "Rd02", ["Titan", "Ogre", "Ogre", "Gargoyle"],
                        ["Angel", "Gargoyle", "Centaur", "Centaur"])
    legion2 = player.markerid_to_legion["Rd02"]
    assert not player.can_exit_move_phase
    legion1.move(8, False, None, 1)
    assert not player.can_exit_move_phase
    legion2.move(200, True, "Angel", 3)
    game.phase = Phase.MOVE
    assert player.can_exit_move_phase
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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
Exemplo n.º 22
0
    def form_game(self, playername, game_name, min_players, max_players,
                  ai_time_limit, player_time_limit, player_class, player_info):
        """Form a new game.

        Return None normally, or an error string if there's a problem.
        """
        logging.info("%s %s %s %s %s %s %s %s", playername, game_name,
                     min_players, max_players, ai_time_limit,
                     player_time_limit, player_class, player_info)
        if not game_name:
            st = "Games must be named"
            logging.warning(st)
            return st
        game_info_tuples = self.get_game_info_tuples()
        game_names = set((tup[0] for tup in game_info_tuples))
        if game_name in game_names:
            st = 'The game name "%s" is already in use' % game_name
            logging.warning(st)
            return st
        if min_players > max_players:
            st = "min_players must be <= max_players"
            logging.warning(st)
            return st
        now = time.time()
        GAME_START_DELAY = 5 * 60
        game = Game.Game(game_name,
                         playername,
                         now,
                         now + GAME_START_DELAY,
                         min_players,
                         max_players,
                         master=True,
                         ai_time_limit=ai_time_limit,
                         player_time_limit=player_time_limit,
                         player_class=player_class,
                         player_info=player_info)
        self.games.append(game)
        game.add_observer(self)
        action = Action.FormGame(playername, game.name, game.create_time,
                                 game.start_time, game.min_players,
                                 game.max_players, ai_time_limit,
                                 player_time_limit, player_class, player_info)
        self.notify(action)
Exemplo n.º 23
0
 def setup_method(self, method):
     now = time.time()
     self.game = game = Game.Game("g1", "p0", now, now, 2, 6)
     game.add_player("p1")
     player0 = game.players[0]
     player1 = game.players[1]
     player0.assign_starting_tower(200)
     player1.assign_starting_tower(100)
     game.sort_players()
     game.started = True
     game.assign_color("p1", "Blue")
     game.assign_color("p0", "Red")
     game.assign_first_marker("p1", "Bu01")
     game.assign_first_marker("p0", "Rd01")
     player0.pick_marker("Rd02")
     player0.split_legion("Rd01", "Rd02",
                          ["Titan", "Centaur", "Centaur", "Gargoyle"],
                          ["Angel", "Ogre", "Ogre", "Gargoyle"])
     player0.done_with_splits()
Exemplo n.º 24
0
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
Exemplo n.º 25
0
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
Exemplo n.º 26
0
 def add_game(self, game_info_tuple):
     (name, create_time, start_time, min_players, max_players, playernames,
      started, finish_time, winner_names, loser_names) = game_info_tuple
     owner = playernames[0]
     game = Game.Game(name,
                      owner,
                      create_time,
                      start_time,
                      min_players,
                      max_players,
                      started=started,
                      finish_time=finish_time)
     self.add_observer(game)
     for playername in playernames[1:]:
         game.add_player(playername)
     if winner_names:
         logging.debug(winner_names)
         # XXX Hack
         game._winner_names = winner_names
         game._loser_names = loser_names
     self.games.append(game)
Exemplo n.º 27
0
 def add_game(self, game_info_tuple):
     logging.info("add_game %s", game_info_tuple)
     (name, create_time, start_time, min_players, max_players, playernames,
      started, finish_time, winner_names, loser_names) = game_info_tuple
     owner = playernames[0]
     game = Game.Game(name,
                      owner,
                      create_time,
                      start_time,
                      min_players,
                      max_players,
                      started=started,
                      finish_time=finish_time)
     self.add_observer(game)
     for playername in playernames[1:]:
         game.add_player(playername)
     self.games.append(game)
     if not game.finish_time and (not self.game_name
                                  or game.name == self.game_name):
         def1 = self.user.callRemote("join_game", game.name, self.aiclass,
                                     self.ai.player_info)
         def1.addErrback(self.failure)
Exemplo n.º 28
0
def test_teleported():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    player.pick_marker("Rd01")
    assert player.selected_markerid == "Rd01"
    player.create_starting_legion()
    assert player.num_creatures == 8
    assert not player.teleported
    player.split_legion("Rd01", "Rd02", ["Titan", "Ogre", "Ogre", "Gargoyle"],
                        ["Angel", "Gargoyle", "Centaur", "Centaur"])
    legion1 = player.markerid_to_legion["Rd01"]
    legion2 = player.markerid_to_legion["Rd02"]
    legion1.move(8, False, None, 1)
    assert not player.teleported
    legion2.move(200, True, "Angel", 3)
    assert player.teleported
    legion2.undo_move()
    assert not player.teleported
Exemplo n.º 29
0
def test_titan_power():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)
    player.assign_starting_tower(600)
    player.assign_color("Red")
    assert len(player.markerids_left) == 12
    player.pick_marker("Rd01")
    assert player.selected_markerid == "Rd01"
    player.create_starting_legion()
    legion = player.markerid_to_legion["Rd01"]
    for creature in legion.creatures:
        if creature.name == "Titan":
            titan = creature
    assert player.score == 0
    assert titan.power == 6
    assert titan.is_titan
    player.score = 99
    assert titan.power == 6
    player.score = 100
    assert titan.power == 7
    player.score = 10000
    assert titan.power == 106
Exemplo n.º 30
0
        self.show_all()

    def cb_click(self, widget, event):
        color = widget.get_label()
        self.deferred.callback((self.game, color))
        self.destroy()

    def cb_destroy(self, widget):
        if not self.deferred.called:
            self.deferred.callback((self.game, None))


if __name__ == "__main__":
    import time
    from slugathon.game import Game
    from slugathon.util import guiutils

    def my_callback((game, color)):
        logging.info("picked %s", color)
        guiutils.exit()

    now = time.time()
    playername = "test user"
    game = Game.Game("test game", playername, now, now, 2, 6)
    colors_left = colors[:]
    colors_left.remove("Black")
    pickcolor, def1 = new(playername, game, colors_left, None)
    def1.addCallback(my_callback)
    pickcolor.connect("destroy", guiutils.exit)
    gtk.main()