def place(self, unit, fuzzy):
     places = self.map_proxy.get_player_visible_tiles()
     free_place = set()
     real = GameObjectType.KNIGHT
     if unit == "KNIGHT":
         real = GameObjectType.KNIGHT
     if unit == "ARCHER":
         real = GameObjectType.ARCHER
     if unit == "MAGICIAN":
         real = GameObjectType.MAGICIAN
     edge = self.map_proxy.get_border_tiles()
     for i in places:
         if not self.map_proxy.is_position_occupied(i) and i not in edge:
             free_place.add(i)
     if fuzzy == "low":
         for i in range(2):
             self.game_control_proxy.spawn_unit(
                 SpawnInformation(self.player, real, free_place.pop(), [],
                                  []))
     if fuzzy == "medium":
         for i in range(6):
             self.game_control_proxy.spawn_unit(
                 SpawnInformation(self.player, real, free_place.pop(), [],
                                  []))
     if fuzzy == "high":
         for i in range(10):
             self.game_control_proxy.spawn_unit(
                 SpawnInformation(self.player, real, free_place.pop(), [],
                                  []))
Beispiel #2
0
def game_instance():
    game_map = MapGenerator(5, 5).generate(GAME_MAP)

    # Initialize game engine
    game_engine = GameEngine(game_map)

    map_proxy = MapProxy(game_engine)
    game_object_proxy = GameObjectProxy(game_engine)
    game_control_proxy = GameControlProxy(game_engine)
    game_uncertainty_proxy = GameUncertaintyProxy(game_engine)

    # Register defender
    defender = Player(map_proxy, game_object_proxy, game_control_proxy, game_uncertainty_proxy)
    game_engine.register_player(defender, PlayerResources(1000, 10), [])

    # Register attacker
    attacker = AIPlayer(map_proxy, game_object_proxy, game_control_proxy, game_uncertainty_proxy)
    game_engine.register_player(attacker, PlayerResources(200, 0, 0), [])

    game_engine.start(500)

    game_engine.spawn_unit(SpawnInformation(defender, GameObjectType.BASE, OffsetPosition(0, 0), [], []))
    game_engine.spawn_unit(SpawnInformation(attacker, GameObjectType.DEMON, OffsetPosition(0, -2), [], []))
    game_engine.spawn_unit(SpawnInformation(attacker, GameObjectType.DEMON, OffsetPosition(-1, -1), [], []))

    attacker.initialize()

    return map_proxy, game_object_proxy, game_control_proxy, game_uncertainty_proxy, defender, attacker, game_engine
 def pl(self):
     print("FUUUCK")
     pos = OffsetPosition(-3, -4).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT, pos, [], []))
     pos = OffsetPosition(-4, -3).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT, pos, [], []))
Beispiel #4
0
 def place_cross_ent(self):
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT,
                          CubicPosition(0, 2, -2), [], []))
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT,
                          CubicPosition(0, -2, 2), [], []))
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT,
                          CubicPosition(-2, 1, 1), [], []))
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT,
                          CubicPosition(2, -1, -1), [], []))
Beispiel #5
0
 def build_base(self, position_q: int, position_r: int):
     Logger.log('Building base')
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player,
                          GameObjectType.BASE,
                          OffsetPosition(int(position_q), int(position_r)),
                          [], []))
 def place_archer(self, free_tile):
     pos = free_tile
     vulnerable_filter = FilterFactory().attack_filter(
         AttackMostVulnerableFilter)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ARCHER, pos,
                          [vulnerable_filter], []))
def test_spawn_on_edge(game_control_proxy, defender):
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.ARCHER,
                              OffsetPosition(-1, -2), [], [])
        game_control_proxy.spawn_unit(si)

    assert 'Cannot spawn unit defender unit on the map edge.' in str(exc.value)
def test_spawn_second_base(game_control_proxy, defender):
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.BASE,
                              OffsetPosition(1, 1), [], [])
        game_control_proxy.spawn_unit(si)

    assert 'You cannot spawn additional base!' in str(exc.value)
def test_spawn_unit_occupied_position(game_control_proxy, defender, position):
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.ARCHER, position, [],
                              [])
        game_control_proxy.spawn_unit(si)

    assert 'Tile is already occupied!' in str(exc.value)
def test_spawn_unit_out_of_map(game_control_proxy, defender):
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.ARCHER,
                              OffsetPosition(0, -5), [], [])
        game_control_proxy.spawn_unit(si)

    assert 'Position is not on the map!' in str(exc.value)
def test_spawn_unit_not_visible_tile(game_control_proxy, defender):
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.ARCHER,
                              OffsetPosition(0, -2), [], [])
        game_control_proxy.spawn_unit(si)

    assert 'Attempt to spawn unit at not visible tile!' in str(exc.value)
Beispiel #12
0
 def place_base(self):
     Logger.log('Place on 0 0 0')
     base_position = CubicPosition(0, 0, 0)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.BASE, base_position,
                          [], []))
     self.place_guard(1)
def test_spawn_different_role(game_control_proxy, defender):
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.DEMON,
                              OffsetPosition(1, 1), [], [])
        game_control_proxy.spawn_unit(si)

    assert 'Attempt to spawn unit of different role!' in str(exc.value)
 def build_base_good(self, found_good):
     # Custom log messages
     n = FilterFactory().attack_filter(AttackNearestFilter)
     Logger.log('Building base')
     base_pos = found_good
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.BASE, base_pos, [n],
                          []))
def test_spawn_insufficient_resources(game_control_proxy, defender):
    flexmock(Ent).should_receive('cost').and_return(5000)
    with pytest.raises(IllegalActionException) as exc:
        si = SpawnInformation(defender, GameObjectType.ENT,
                              OffsetPosition(1, 1), [], [])
        game_control_proxy.spawn_unit(si)

    assert 'Insufficient resources!' in str(exc.value)
Beispiel #16
0
 def build_ent(self, **kwargs):
     pos = None
     for key in ('ideal_tile', 'position_first_round',
                 'position_second_round', 'position_third_round'):
         if key in kwargs:
             pos = kwargs[key]
     Logger.log('Building ent')
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ENT, pos, [], []))
 def place_magician(self, free_sides):
     nearest_filter = FilterFactory().attack_filter(AttackNearestFilter)
     vulnerable_filter = FilterFactory().attack_filter(
         AttackMostVulnerableFilter)
     resist_filter = FilterFactory().attack_filter(AttackNoResistantFilter)
     pos = free_sides.pop()
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.MAGICIAN, pos,
                          [nearest_filter, resist_filter], []))
 def place_druid(self, free_place_from_base2):
     nearest_filter = FilterFactory().attack_filter(AttackNearestFilter)
     vulnerable_filter = FilterFactory().attack_filter(
         AttackMostVulnerableFilter)
     resist_filter = FilterFactory().attack_filter(AttackNoResistantFilter)
     pos = free_place_from_base2.pop()
     self.game_control_proxy.spawn_unit(
         SpawnInformation(
             self.player, GameObjectType.DRUID, pos,
             [nearest_filter, resist_filter, vulnerable_filter], []))
 def place_druid_minotaur(self, near_minotaur):
     nearest_filter = FilterFactory().attack_filter(AttackNearestFilter)
     vulnerable_filter = FilterFactory().attack_filter(
         AttackMostVulnerableFilter)
     resist_filter = FilterFactory().attack_filter(AttackNoResistantFilter)
     pos = near_minotaur
     self.game_control_proxy.spawn_unit(
         SpawnInformation(
             self.player, GameObjectType.DRUID, pos,
             [nearest_filter, resist_filter, vulnerable_filter], []))
Beispiel #20
0
 def place_druid_square(self):
     Logger.log('Placing druid in corner')
     x = CubicPosition(-2, 2, 0)
     troop = GameObjectType.DRUID
     if not self.map_proxy.is_position_occupied(x):
         self.game_control_proxy.spawn_unit(
             SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(-2, 0, 2)
     if not self.map_proxy.is_position_occupied(x):
         self.game_control_proxy.spawn_unit(
             SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(2, 0, -2)
     if not self.map_proxy.is_position_occupied(x):
         self.game_control_proxy.spawn_unit(
             SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(2, -2, 0)
     if not self.map_proxy.is_position_occupied(x):
         self.game_control_proxy.spawn_unit(
             SpawnInformation(self.player, troop, x, [], []))
Beispiel #21
0
 def place_extended(self):
     Logger.log('Placing extended soldiers')
     base_position = CubicPosition(0, 0, 0)
     for z in base_position.get_all_neighbours():
         for x in z.get_all_neighbours():
             if self.map_proxy.is_position_occupied(x):
                 continue
             self.game_control_proxy.spawn_unit(
                 SpawnInformation(self.player, GameObjectType.KNIGHT, x, [],
                                  []))
 def build_base(self, x, y):
     # Custom log messages
     n = FilterFactory().attack_filter(AttackNearestFilter)
     Logger.log('Building base')
     base_pos = OffsetPosition(x, y).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.BASE, base_pos, [n],
                          []))
     base_pos = OffsetPosition(-5, -5).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.MAGICIAN, base_pos,
                          [n], []))
     base_pos = OffsetPosition(-4, -5).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.MAGICIAN, base_pos,
                          [n], []))
     base_pos = OffsetPosition(-5, -4).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.MAGICIAN, base_pos,
                          [n], []))
     base_pos = OffsetPosition(-4, -3).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ARCHER, base_pos, [n],
                          []))
     base_pos = OffsetPosition(-3, -5).offset
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.ARCHER, base_pos, [n],
                          []))
Beispiel #23
0
 def place_guard(self, z: int):
     Logger.log('Placing guards')
     troop = GameObjectType.ARCHER
     if z == 1:
         troop = GameObjectType.ARCHER
     if z == 2:
         troop = GameObjectType.KNIGHT
     if z == 3:
         troop = GameObjectType.DRUID
     x = CubicPosition(-1, 1, 0)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(-1, 0, 1)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(0, -1, 1)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(0, 1, -1)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(1, -1, 0)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, troop, x, [], []))
     x = CubicPosition(1, 0, -1)
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, troop, x, [], []))
Beispiel #24
0
 def build_magician(self, allowed, **kwargs):
     pos = None
     for key in ('ideal_tile', 'position_first_round',
                 'position_second_round', 'position_third_round', 'pos'):
         if key in kwargs:
             pos = kwargs[key]
     if allowed == 0 or not isinstance(pos, OffsetPosition):
         pass
     else:
         Logger.log('Building magician')
         self.game_control_proxy.spawn_unit(
             SpawnInformation(self.player, GameObjectType.MAGICIAN, pos, [],
                              []))
Beispiel #25
0
    def __create_spawn_info(self, resources: int, planned: List[SpawnInformation]) -> SpawnInformation:
        attackers = [attacker for attacker in self.__attackers if attacker.price <= resources]
        game_object = self.spawn_random.choice(attackers)

        planned_positions = [x.position for x in planned]

        free_border_tiles = [tile for tile in self.__border_tiles if
                             self.game_object_proxy.get_object_type(
                                 tile) == GameObjectType.NONE and tile not in planned_positions]

        position = self.spawn_random.choice(tuple(free_border_tiles))
        return SpawnInformation(self, game_object, position, self.unit_filters[game_object][0],
                                self.unit_filters[game_object][1])
    def build(self, unit, free_tile):
        print(unit)
        print("####BUILD")
        real = 0
        if unit == "KNIGHT":
            real = GameObjectType.KNIGHT
        if unit == "ARCHER":
            real = GameObjectType.ARCHER
        if unit == "MAGICIAN":
            real = GameObjectType.MAGICIAN

        for i in free_tile:
            self.game_control_proxy.spawn_unit(
                SpawnInformation(self.player, real, i, [], []))
Beispiel #27
0
    def build_base(self, position_q: int, position_r: int):
        # Custom log messages
        Logger.log('Building base')

        empty_filter = FilterFactory().attack_filter(EmptyAttackFilter)
        dummy_filter = FilterFactory().attack_filter(DummyAttackFilter,
                                                     'Base attacking')

        # Create instance of default filter
        strongest_filter = FilterFactory().attack_filter(AttackStrongestFilter)

        self.game_control_proxy.spawn_unit(
            SpawnInformation(self.player, GameObjectType.BASE,
                             OffsetPosition(int(position_q), int(position_r)),
                             [], []))
Beispiel #28
0
 def build_druid(self, allowed, **kwargs):
     pos = None
     print("build druid nmb", allowed)
     for key in ('ideal_tile', 'position_first_round',
                 'position_second_round', 'position_third_round'):
         if key in kwargs:
             pos = kwargs[key]
     if allowed == 0:
         print("not allowed to build druid")
         pass
     else:
         Logger.log('Building druid')
         self.game_control_proxy.spawn_unit(
             SpawnInformation(self.player, GameObjectType.DRUID, pos, [],
                              []))
 def restore_guard(self, unit, free_tile):
     nearest_filter = FilterFactory().attack_filter(AttackNearestFilter)
     resist_filter = FilterFactory().attack_filter(AttackNoResistantFilter)
     guard = GameObjectType.KNIGHT
     if unit == "KNIGHT":
         guard = GameObjectType.KNIGHT
     if unit == "ARCHER":
         guard = GameObjectType.ARCHER
     if unit == "DRUID":
         guard = GameObjectType.DRUID
     if unit == "MAGICIAN":
         guard = GameObjectType.MAGICIAN
     if unit == "ENT":
         guard = GameObjectType.ENT
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, guard, free_tile,
                          [nearest_filter, resist_filter], []))
     print("Restore guard ", unit)
Beispiel #30
0
 def build_magician(self, position_q: int, position_r: int):
     Logger.log('Building magician')
     self.game_control_proxy.spawn_unit(
         SpawnInformation(self.player, GameObjectType.MAGICIAN,
                          OffsetPosition(int(position_q), int(position_r)),
                          [], []))