def _init(self): self._zappy._net.connect() # Connect to the server self._getServerReply() # Welcome message log.Head(self._cmds.get()) # =========== log.Inform('Retrieving player infos...') log.Inform("Player team: " + self._zappy._player._team) self._zappy._net.send(self._zappy._player._team + '\n') # Init call self._getServerReply() # Get reply if self._cmds.qsize() < 2: self._getServerReply() reply = self._cmds.get() if (reply == "ko" or reply == "ok"): log.Fail("Cannot retrieve player infos :(", bold=True) exit(84) reply = self._cmds.get() pos_t = reply.split() self._run = True # Register player for other member of the team id = self._zappy._player._id team = self._zappy._player._team level = self._zappy._player._level log.Inform('Register player ' + str(id) + ' (' + team + ')') self._global_broadcast( self._zappy._msgManager._register(id, level, team)) # Random move at begining in order to dispatch AIs self._move_turn() self._move_forward()
def _pool_entryPoint(self): c_pool = self._pool_getCurrent() player = self._zappy._player log.Inform('Current pool for ' + str(player._id) + ' (' + str(player._level) + '): ' + ', '.join(list(map(str, c_pool)))) self._leaders[player._level - 1] = min(c_pool + [player._id]) return True
def _food_isStarving(self): food_level = self._food_get() if food_level < self._deltas['starving_critical']: self._die() elif food_level < self._deltas['starving_begin']: self._starving = True elif food_level > self._deltas['starving_end']: self._starving = False log.Inform('Player ' + str(self._zappy._player._id) + ' is' + ('' if self._starving else ' not') + ' starving (' + str(food_level) + ')') return self._starving
def _lap(self): # Check pool state self._pool_entryPoint() # If we just level up, broadcast it to the whole population self._utils_broadcast_newLevel() # Update inventory and vision self._global_entryPoint() # Prevent user for starving self._food_entryPoint() if not self._starving: self._message_entryPoint() # If player is a leader # Then check ressource, help and cast if self._pool_isPlayerALeader( self._zappy._player._level, self._zappy._player._id) and not self._starving: log.Inform('Leader actions....') if self._ressource_entryPoint() == True: log.Inform('Enough ressource to incant') if self._help_entryPoint() == True: log.Inform('Enough help to incant') self._cast_entryPoint()
def _message_setLevel(self, datas): level = int(datas[2]) team = datas[3] playerID = int(datas[4]) player = self._zappy._player if team != player._team: return False for pl in range(len(self._players)): if self._players[pl]._id == playerID: log.Inform('Set level to ' + str(level) + 'for ' + str(self._players[pl])) self._players[pl]._level = level if level == player._level: self._pool_entryPoint()
def _ressource_searchByType(self, rtype): k = 0 # Index for case ahead of the player n = 2 # coef # Check current position if self._zappy._player._cells[0].count(rtype): return None for i in range(1, self._zappy._player._level + 1): k += n # Add the coef to the ref case n += 2 s = 2 * i # Size of the row (-1) if self._zappy._player._cells[k].count(rtype): log.Inform('Found some ' + rtype + ' ahead of the player') return 'Forward' for xwing in range(1, s // 2 + 1): if self._zappy._player._cells[k - xwing].count(rtype): log.Inform(rtype + ' found to the left of the player | ' + str(k - xwing)) return 'Left' elif self._zappy._player._cells[k + xwing].count(rtype): log.Inform(rtype + ' found to the right of the player | ' + str(k + xwing)) return 'Right' return 'Random'
def _ressource_entryPoint(self): if self._starving or self._incanting: return False # Get needed ressources for level up clevel = self._zappy._player._level nr = [ 0 if t < 0 else t for t in [ self._levels[clevel - 1][x] - self._zappy._player._inventory[x] for x in range(1, 7) ] ] if sum(nr) == 0: return True log.Inform('Need some ressource (' + ', '.join(list(map(str, nr))) + ')') for x in range(len(nr)): if nr[x] > 0: mineral = self._minerals[x] target = self._ressource_searchByType(mineral) if target is None: self._ressource_take(mineral) else: self._move_smooth(target) return False
def _message_requireHelp(self, datas): if len(datas) != 6: return False dir = int(datas[0]) level = int(datas[2]) team = datas[3] leaderID = int(datas[4]) playerID = int(datas[5]) player = self._zappy._player if team != player._team or playerID != player._id: return False if self._leaders[level - 1] == player._id: return False log.Inform('I\'m comming for you!') if dir == 0: return 'use_help' commands = self._targets[dir - 1] log.Head(str(dir) + ' - ' + ', '.join(commands)) for i in commands: if i == 'Forward': self._move_forward() else: self._move_turn(i) return 'use_help'
def _message_sendMalware(self, payload): log.Inform('Sending malware as (' + payload + ')') self._global_broadcast(payload) return True