def look_for_players(self, look): for msg in controller.msgQueue: ready = MsgProtocol.is_ready_inc(msg.text) if ready and ready["recipient"] == ant.uuid and ready[ 'sender'] in (mate.uuid for mate in mates): mates.get_mate(ready['sender']).ready = True my_log(msg.text) my_print( ready["sender"], " is ready ! {} / {}".format( len([mate for mate in mates if mate.ready]), len(mates))) #my_print("=> player on tile {}".format(look[0].count("player"))) #my_print("=> look : {}".format(look)) ok = True for mate in mates: if not mate.ready: ok = False break if look[0].count("player") == self.size and ok: my_print("Ready to incant ! ") statemachine.closure = lambda: statemachine.replace( self.replacement_state) else: msg = MsgProtocol.ping_team(ant.uuid) safe_controller.execute( BroadcastTransaction(msg, self.broadcast_team))
def wait_others(self, level=None): if level: ant.lvl = level my_print("LvL up : ", level) else: my_print("Failed to LvL up !") statemachine.closure = lambda: statemachine.pop()
def look_end(self, _): self.lap_nbr -= 1 if self.lap_nbr: transaction = LookTransaction(self.look_end) safe_controller.execute(transaction) else: my_print("Checking my mails !") statemachine.closure = lambda: statemachine.pop()
def wait_enrol_msg(self, *args): for m in controller.msgQueue: enr = MsgProtocol.is_enrolment(m.text) if enr and int(enr['level']) == ant.lvl + 1: my_print("Apply for enrolment : ", enr['sender']) self._status_stack.pop(0) msg = MsgProtocol.apply(ant.uuid, enr['sender']) safe_controller.execute(BroadcastTransaction( msg, self.wait_accept_msg), rollback=False) ant.queen = Mate(enr['sender']) return self.template()
def popped_over(self): super().popped_over() for m in controller.msgQueue: enr = MsgProtocol.is_apply(m.text) if enr and enr['recipient'] == ant.uuid: mates.add_mate(enr['sender']) my_print(enr["sender"], " joined ! {} / {}".format(len(mates), requirement[ant.lvl + 1][0] - 1)) if len(mates) == requirement[ant.lvl + 1][0] - 1: break if len(mates) < requirement[ant.lvl + 1][0] - 1: my_print("Failed to find a team lvl {}".format(ant.lvl + 1)) mates.clear() ant.is_queen = False allow_list = [m.uuid for m in mates] msg = MsgProtocol.allowed_ants(ant.uuid, allow_list) transaction = BroadcastTransaction(msg, lambda: statemachine.pop()) safe_controller.execute(transaction, rollback=False)
def set_requested_items(self): my_print("On queen position") transaction = PackedTransaction(self.wait_others) for k, v in ant.request.items(): sub_transaction = SetTransaction(k, v, lambda ok=None: None, lambda ok=None: None, lambda ok=None: None) transaction.addTransaction(sub_transaction) msg = MsgProtocol.ready_inc(ant.uuid, ant.queen.uuid) transaction.addTransaction(BroadcastTransaction(msg, lambda ok=None: None)) incant = IncantationTransaction( lambda ok=None: None, lambda ok=None: None, lambda ok=None: None, lambda ok=None: None, lambda ok=None: None, write=False ) transaction.addTransaction(incant) safe_controller.execute(transaction, floor=0)
def on_push(self, cli): super().on_push(cli) my_print("Waiting for mates...") transaction = LookTransaction(self.look_end) safe_controller.execute(transaction)
def incantationEnd(self, level=None): if level: ant.lvl = level my_print("LvL up : ", level) else: my_print("Failed to LvL up !")