def addMove(self, moveVector, look): self.position = Vector(self.position.x + moveVector.x, self.position.y + moveVector.y) angle = math.atan2(-1 * look.x, 1 * look.y) * 180 / math.pi x = math.cos(angle) * self.look.x - math.sin(angle) * self.look.y y = math.sin(angle) * self.look.x + math.cos(angle) * self.look.y self.look = Vector(x, y)
def follow_dir(self, dir): path = Path() real_dir = Vector() if dir.x != 0: real_dir.x = dir.x else: real_dir.y = dir.y path.addPoint(real_dir, EmptyPathTransaction()) safe_controller.execute(PathManipulator(path.generateOrder()[0], self.listen_the_queen))
def generateOrder(self, reset=False): self._generateGoOrder(self.points, Vector(), Vector(0, 1)) ret = self.path look = self.last_look self.path = list() self.last_look = Vector() if reset: look, new_actions = self.resetPosition(ret[-1].position, look) ret += new_actions return ret, look
def goNextPlace(self): path = Path() if self.progress == self.surface: left_dist = ant.lvl path.addPoint(Vector(-left_dist, 0), EmptyPathTransaction()) path.addPoint(Vector(-left_dist, 1), LookTransaction(lambda value: None)) self.progress = 0 else: path.addPoint(Vector(0, 1), LookTransaction(lambda value: None)) self.progress += 1 path, look = path.generateOrder(False) self.pathHandler = PathManipulator(path, self.updateAntLook) safe_controller.execute(self.pathHandler)
def __init__(self, sok, sko, eok, eko, end, pos=Vector(), write=True): super().__init__(CmdCost.Incantation.value, end, pos) self.sok = sok self.sko = sko self.eok = eok self.eko = eko self.write = write
def __init__(self, dir_nbr, text): dir_conv = { 0: Vector(0, 0), 1: Vector(0, 1), 2: Vector(-1, 1), 3: Vector(-1, 0), 4: Vector(-1, -1), 5: Vector(0, -1), 6: Vector(1, -1), 7: Vector(1, 0), 8: Vector(1, 1) } self.text = text self.dir = dir_conv[dir_nbr]
def __init__(self, team): self.is_queen = True self.queen = None self.team = team self.map_size = Vector() self.current_nbr = 0 self.lvl = 1 self.forked = False self.look = [] self.inventory = {} self.request = {} self._uuid = HashManager.generate()
def _alignY(self, look, src_point, dest_point): wsrc_point = Vector(0, src_point.y) wdest_point = Vector(0, dest_point.y) dir_vec = normalize( Vector(wdest_point.x - wsrc_point.x, wdest_point.y - wsrc_point.y)) nlook = normalize(look) new_look = dir_vec moves = list() if nlook.x == 0 and nlook.y == -dir_vec.y and nlook.y != 0: moves += [Cmd.Left, Cmd.Left] elif nlook.x != 0 and dir_vec.y == nlook.x: moves += [Cmd.Left] elif nlook.x != 0 and dir_vec.y == -nlook.x: moves += [Cmd.Right] else: new_look = look size = vecSize( Vector(wdest_point.x - wsrc_point.x, wdest_point.y - wsrc_point.y)) for i in range(int(size)): moves += [Cmd.Forward] return new_look, moves, Vector(src_point.x, dest_point.y)
def addConePoint(self, idx, transaction): pos = None min_val = 0 max_val = 0 deep = 0 while pos is None: if min_val <= idx <= max_val: middle = min_val + (max_val - min_val) // 2 x = idx - middle pos = Vector(x, deep) deep += 1 min_val = max_val + 1 max_val = min_val + deep * 2 self.addPoint(pos, transaction)
def listen_the_queen(self, _=None): save = None for msg in controller.msgQueue: ping = MsgProtocol.is_ping_team(msg.text) if ping and ping['sender'] == ant.queen.uuid: save = msg if save and (save.dir.x != self.last.x or save.dir.y != self.last.y): self.last = save.dir save = None if save and save.dir.x == 0 and save.dir.y == 0: self.set_requested_items() elif save: self.follow_dir(save.dir) self.last = Vector(-100, -100) else: safe_controller.execute(LookTransaction(self.listen_the_queen))
def __init__(self, item, nb, last, ok, ko, pos=Vector()): super().__init__(CmdCost.Set.value * nb, last, pos) self.item = item self.nb = nb self.ko = ko self.ok = ok
def __init__(self): self.look = Vector(0, 1) self.position = Vector(0, 0)
def resetPosition(self, position, look): new_look, actions = self._calcMove(look, position, Vector()) actions += Path.calcLookTrans(new_look, Vector(0, 1)) return new_look, actions
def __init__(self): self.path = list() self.last_look = Vector() self.points = list()
def __init__(self, ok, pos=Vector()): super().__init__(CmdCost.Right.value, ok, pos)
def __init__(self, ok, pos=Vector()): super().__init__(CmdCost.Look.Connect_nbr.value, ok, pos)
def __init__(self, msg, ok, pos=Vector()): super().__init__(CmdCost.Broadcast.value, ok, pos) self.msg = msg
def __init__(self, ok, pos=Vector()): super().__init__(CmdCost.Forward.value, ok, pos)
def __init__(self, end, pos=Vector()): super().__init__(CmdCost.Fork.value, end, pos)
def __init__(self, ok, pos=Vector()): super().__init__(CmdCost.Inventory.value, ok, pos)
def __init__(self, end, pos=Vector()): super().__init__(0, end, pos) self.transactions = list()
def __init__(self, pos=Vector()): super().__init__(0, lambda ok=None: None, pos)
def __init__(self): super().__init__("FollowQueenState") self.last = Vector(-100, -100)