def has_guards(self) -> bool: Logger.log('has_guards') base_position = CubicPosition(0, 0, 0) flag = True for z in base_position.get_all_neighbours(): if self.game_object_proxy.get_object_type( z) != GameObjectType.ARCHER: flag = False Logger.log('Not all guards') return flag
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 cross_free(self) -> bool: flag = True if self.map_proxy.is_position_occupied(CubicPosition(0, 2, -2)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(0, -2, 2)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(-2, 1, 1)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(2, -1, -1)): flag = False return flag
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), [], []))
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 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, [], []))
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, [], []))
class HexDirection(Enum): """ Direction of neighbours on hexagon grid defined with Cubic position""" UPPER = CubicPosition(0, 1, -1) RIGHT_UPPER = CubicPosition(1, 0, -1) RIGHT_LOWER = CubicPosition(1, -1, 0) LOWER = CubicPosition(0, -1, 1) LEFT_LOWER = CubicPosition(-1, 0, 1) LEFT_UPPER = CubicPosition(-1, 1, 0) @staticmethod def direction_list(): return [HexDirection.UPPER, HexDirection.RIGHT_UPPER, HexDirection.RIGHT_LOWER, HexDirection.LOWER, HexDirection.LEFT_LOWER, HexDirection.LEFT_UPPER]
def check_positions(self) -> bool: flag = True if self.map_proxy.is_position_occupied(CubicPosition(-1, 1, 0)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(-1, 0, 1)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(0, 1, -1)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(0, -1, 1)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(1, -1, 0)): flag = False if self.map_proxy.is_position_occupied(CubicPosition(1, 0, -1)): flag = False return flag
OffsetPosition(-6, 5) ]), (OffsetPosition(3, 2), [ OffsetPosition(3, 1), OffsetPosition(4, 2), OffsetPosition(4, 3), OffsetPosition(3, 3), OffsetPosition(2, 3), OffsetPosition(2, 2) ])]) def test_neighbour_offset(position, result): assert position.get_all_neighbours() == result @pytest.mark.parametrize('position,result', [ (CubicPosition(0, 0, 0), [ CubicPosition(0, 1, -1), CubicPosition(1, 0, -1), CubicPosition(1, -1, 0), CubicPosition(0, -1, 1), CubicPosition(-1, 0, 1), CubicPosition(-1, 1, 0) ]), (CubicPosition(2, -4, 2), [ CubicPosition(2, -3, 1), CubicPosition(3, -4, 1), CubicPosition(3, -5, 2), CubicPosition(2, -5, 3), CubicPosition(1, -4, 3), CubicPosition(1, -3, 2) ]),