def play_base(self): self.log("*********BASE**********") self.log("Vie: {}".format(self.life())) self.log("MineralStorage: {}".format(self.mineralStorage())) # change state randomly (kikoolol powa !!!) s = [aiwar.DEFAULT, aiwar.LIGHT, aiwar.DARK] self.state(random.choice(s)) n = self.neighbours() # refuel friend ships for i in n: if isinstance(i, aiwar.MiningShip) and self.isFriend( i) and self.distanceTo(i) <= aiwar.BASE_REFUEL_RADIUS(): self.log("je fais le plein de mon ami") self.refuel(aiwar.MININGSHIP_START_FUEL(), i) # create new MiningShip if self.mineralStorage() > aiwar.BASE_MININGSHIP_PRICE( ) and random.randint(1, 20) == 1: self.createMiningShip() # communiquer avec les copains for i in n: if (isinstance(i, aiwar.Base) or isinstance(i, aiwar.MiningShip)) and self.isFriend( i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # si on connait la position du mineral posMineralSelf = (self.getMemoryFloat(2), self.getMemoryFloat(3)) if posMineralSelf != (0.0, 0.0): #envoi de la position du mineral s'il ne la connait pas posMineralCopain = (self.getMemoryFloat(2, i), self.getMemoryFloat(3, i)) if posMineralCopain == (0.0, 0.0): self.setMemoryFloat(2, posMineralSelf[0], i) self.setMemoryFloat(3, posMineralSelf[1], i) self.log( "J'ai donne la position de mon minerais a mon copain")
def play_fighter_test(self): logger.error( "" ) logger.error( "********FIGHTER******** : (%s, %s)", int(self.pos()[0]), int(self.pos()[1]) ) logger.error( "Vie: %s\t-\tFuel: %s\t-\tMissiles: %s", self.life(), self.fuel(), self.missiles() ) n = getSortedNeighbours(self) logMyFighterMemory(self) # Ordre des actions : # 0 - Panne de fuel => effacer toutes les cibles # 1 - Memoriser une cible + position BASE # 2 - Visualiser une cible pour tirer # 3 - Rejoindre la cible memoire # 4 - Retourner a la base # ====== PHASE 0 ====== if self.life()<aiwar.FIGHTER_MOVE_CONSO(): self.setMemoryFloat(0, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID/CONST_Y_DIVIDE) self.setMemoryFloat(1, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID/CONST_Y_DIVIDE) # ====== PHASE 1 ====== # S'il existe un ennemi1 localise dans BASE, je go le combattre me = getMyFighterMemory(self) # Chercher une cible dans mon entourage for i in n: if isinstance(i, aiwar.Base) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS() and self.isFriend(i): friend = getFriendBaseMemory(self, i) if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # Enregistrer la position self.setMemoryFloat(0, self.getMemoryFloat(0,i)) # Decaller le 2eme ennemi dans la memoire de l'ami self.setMemoryFloat(0, self.getMemoryFloat(1,i), i) self.setMemoryFloat(1, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID/CONST_Y_DIVIDE, i) if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # Enregistrer la position self.setMemoryFloat(1, self.getMemoryFloat(0,i)) # Decaller le 2eme ennemi dans la memoire de l'ami self.setMemoryFloat(0, self.getMemoryFloat(1,i), i) self.setMemoryFloat(1, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID/CONST_Y_DIVIDE, i) # Enregistrer position BASE px,py = basePos = i.pos() self.setMemoryFloat(3, int(px) + int(py) / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyFighterMemory(self) for i in n: if isinstance(i, aiwar.Fighter) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS() and self.isFriend(i): friend = getFriendFighterMemory(self, i) if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and me[1] != friend[0]: # Enregistrer la position self.setMemoryFloat(0, self.getMemoryFloat(0,i)) elif me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and me[0] != friend[0]: # Enregistrer la position self.setMemoryFloat(1, self.getMemoryFloat(0,i)) # Mettre a jour mon "Me" me = getMyFighterMemory(self) # ====== PHASE 2 ====== # Ordre des cibles : # 1 - BASE # 2 - FIGHTER # 3 - MININGSHIP for i in n: if isinstance(i, aiwar.Base) and not self.isFriend(i): logger.error( "++++++Ennemy BASE: %s", self.distanceTo(i) ) if self.missiles() > 0: logger.error( "++++++Ennemy BASE: BOOM dans ta face !" ) # Tirer sans condition sur la BASE self.launchMissile(i) # Decaller l'ennemi 0 en 1 si l'emplacement 1 est libre if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): self.setMemoryFloat(1, self.getMemoryFloat(0)) # Enregistrer la position pour le poursuivre px,py = Pos = i.pos() self.setMemoryFloat(0, int(px) + int(py) / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyFighterMemory(self) else: logger.error( "++++++Ennemy BASE: Plus de munitions ! :'(" ) cpt_ship = 0 for i in n: if isinstance(i, aiwar.Fighter) and not self.isFriend(i): cpt_ship +=1 for i in n: if isinstance(i, aiwar.Fighter) and not self.isFriend(i): logger.error( "++++Ennemy FIGHTER: %s", self.distanceTo(i) ) if self.missiles() > 0: logger.error( "++++Ennemy FIGHTER: Attrape ca !" ) # Tirer 1 fighter sur 3 if random.randint(1, 3*cpt_ship) == 1: self.launchMissile(i) # On fait un pas en arriere pour sortir de la zone visible de l'ennemi # Si ca peut eviter de se prendre un missile ... :c) self.rotateTo(i) if random.randint(1, 2) == 1: self.rotateOf(90) else: self.rotateOf(-90) self.move() # Decaller l'ennemi 0 en 1 si l'emplacement 1 est libre if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): self.setMemoryFloat(1, self.getMemoryFloat(0)) # Enregistrer la position pour le poursuivre px,py = Pos = i.pos() self.setMemoryFloat(0, int(px) + int(py) / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyFighterMemory(self) else: logger.error( "++++Ennemy FIGHTER: Plus de munitions ! :'(" ) cpt_ship = 0 for i in n: if isinstance(i, aiwar.MiningShip) and not self.isFriend(i): cpt_ship +=1 for i in n: if isinstance(i, aiwar.MiningShip) and not self.isFriend(i): logger.error( "++Ennemy MININGSHIP: %s", self.distanceTo(i) ) if self.missiles() > 0: logger.error( "++Ennemy MININGSHIP: N'y vois rien de personnel, je fais mon job." ) # Tirer 1 MiningShip sur 8 if random.randint(1, 8*cpt_ship) == 1: self.launchMissile(i) # Decaller l'ennemi 0 en 1 si l'emplacement 1 est libre if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): self.setMemoryFloat(1, self.getMemoryFloat(0)) # Enregistrer la position pour le poursuivre px,py = Pos = i.pos() self.setMemoryFloat(0, int(px) + int(py) / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyFighterMemory(self) else: logger.error( "++Ennemy MININGSHIP: Plus de munitions ! :'(" ) # ====== PHASE 3 ====== # Initialiser ma cible if me[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # S'il ne reste plus de missiles, rentrer a la maison if self.missiles() <= 0: # Plus de missiles, retourner a la base self.rotateTo(me[3]) self.move() # Se deplacer tant qu'on est loin de la cible elif self.distanceTo(me[0]) > (aiwar.FIGHTER_DETECTION_RADIUS()/10): self.rotateTo(me[0]) self.move() # Proche de la cible avec des missiles => elle n'est plus là. Passer à la cible suivante. else: # Decaller l'ennemi 1 en 0 self.setMemoryFloat(0, self.getMemoryFloat(1)) # Effacer la cible decaller pour ne pas avoir de doublon self.setMemoryFloat(1, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE)
def play_miningship_1(self): logger.error( "" ) logger.error( "*******MININGSHIP****** : (%s, %s)", int(self.pos()[0]), int(self.pos()[1]) ) logger.error( "Vie: %s\t-\tfuel: %s\t-\tmineralStorage: %s", self.life() , self.fuel(), self.mineralStorage() ) n = getSortedNeighbours(self) logMyMiningShipMemory(self) me = getMyMiningShipMemory(self) # recherche de la base amie baseConnue = False basePos = me[3] if basePos != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.error( "je connais ma base" ) baseConnue = True else: logger.info( "je ne connais pas ma base" ) for i in n: if isinstance(i, aiwar.Base) and self.isFriend(i): logger.error( "base trouvee" ) px, py = basePos = i.pos() self.setMemoryFloat(3, int(px) + int(py) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) baseConnue = True break # Fuir si un ennemi devient visible logger.info( "Fuir si un ennemi devient visible : debut" ) ennemiEnVue = False ennemiPos = me[2] if ennemiPos != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.error( "j'ai un ennemi en memoire" ) ennemiEnVue = True logger.info( "Fuir si un ennemi devient visible : fin" ) # Remettre a jour la liste en fonction de l'importance de ce qui est visible. logger.info( "Remettre a jour la liste en fonction de l'importance de ce qui est visible : debut" ) for i in n: if isinstance(i, aiwar.MiningShip) and not self.isFriend(i): px,py = ennemiPos = i.pos() logger.error( "++Ennemy MININGSHIP spoted: distance=%s\tx=%s\ty=%s",self.distanceTo(i),px,py) self.setMemoryFloat(2, int(px) + int(py) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) ennemiEnVue = True for i in n: if isinstance(i, aiwar.Fighter) and not self.isFriend(i): logger.error( "++++Ennemy FIGHTER spoted: %s", self.distanceTo(i) ) px,py = ennemiPos = i.pos() self.setMemoryFloat(2, int(px) + int(py) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) ennemiEnVue = True for i in n: if isinstance(i, aiwar.Base) and not self.isFriend(i): logger.error( "++++++Ennemy BASE spoted: %s", self.distanceTo(i) ) px,py = ennemiPos = i.pos() self.setMemoryFloat(2, int(px) + int(py) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) ennemiEnVue = True logger.info( "Remettre a jour la liste en fonction de l'importance de ce qui est visible : fin" ) # communiquer avec les copains me = getMyMiningShipMemory(self) # Copier Friend.0=>Me.1 / Friend.1=>Me.0 / Friend.2=>Me.2 logger.info( "Copier memoire MiningShip : debut" ) for i in n: if isinstance(i, aiwar.MiningShip) and self.isFriend(i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # Me.0 if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[0]" ) friend = getFriendMiningShipMemory(self, i) logger.info( "Copier memoire Minier : getFriendMiningShipMemory" ) if friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[1]: logger.info( "Copier memoire Minier : Friens[1]=>Me[0]" ) logger.error( "Poto minier ([0]<=copy mine)" ) self.setMemoryFloat(0, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) elif friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[1]: logger.info( "Copier memoire Minier : Friens[0]=>Me[0]" ) logger.error( "Poto minier ([0]<=copy mine)" ) self.setMemoryFloat(0, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Me.1 if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[1]" ) friend = getFriendMiningShipMemory(self, i) if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[0]: logger.info( "Copier memoire Minier : Friens[0]=>Me[1]" ) logger.error( "Poto minier ([1]<=copy mine)" ) self.setMemoryFloat(1, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) elif friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[0]: logger.info( "Copier memoire Minier : Friens[1]=>Me[1]" ) logger.error( "Poto minier ([1]<=copy mine)" ) self.setMemoryFloat(1, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Me.2 if me[2] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[2]" ) friend = getFriendMiningShipMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Friens[2]=>Me[2]" ) logger.error( "Poto minier (Copy ENNEMY)" ) self.setMemoryFloat(2, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) logger.error( "++Ennemy MININGSHIP (copy): x=%s, y=%s",friend[2][0],friend[2][1]) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Me.3 if me[3] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[3]" ) friend = getFriendMiningShipMemory(self, i) if friend[3] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Friens[3]=>Me[3]" ) logger.error( "Poto minier (Copy BASE)" ) self.setMemoryFloat(3, int(friend[3][0]) + int(friend[3][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) logger.info( "Copier memoire MiningShip : fin" ) logger.info( "Copier memoire Fighter : debut" ) for i in n: if isinstance(i, aiwar.Fighter) and self.isFriend(i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # Me.0 if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[1]: logger.error( "Poto policier ([0]<=copy mine)" ) self.setMemoryFloat(0, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Me.1 if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[0]: logger.error( "Poto policier ([1]<=copy mine)" ) self.setMemoryFloat(1, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Effacer son "Ennemy" s'il est dans un FIGHTER croisé # Qui m'a croisé et qui s'éloigne de moi (donc plus proche de l'ennemi) # Et dont l'ennemi est le meme avec une precision de MININGSHIP_DETECTION_RADIUS()/4 # Me.2 if me[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if me[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) \ and ( friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) \ and in_circle( friend[0][0], friend[0][1], aiwar.MININGSHIP_DETECTION_RADIUS()/4, me[2][0], me[2][1]) \ or friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) \ and in_circle( friend[1][0], friend[1][1], aiwar.MININGSHIP_DETECTION_RADIUS()/4, me[2][0], me[2][1]) ) \ and not ship_isBack(self, i): # Effacer l'ennemi de ma memoire self.setMemoryFloat(2, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # #Ne pas enregistrer les ennemis de la base ou des fighters # # Me.2 # if me[2] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # friend = getFriendFighterMemory(self, i) # if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # logger.error( "Poto policier" ) # self.setMemoryFloat(2, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # # Mettre a jour mon "Me" # me = getMyMiningShipMemory(self) # # Me.3 # if me[3] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # friend = getFriendFighterMemory(self, i) # if friend[3] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # logger.error( "Poto policier" ) # self.setMemoryFloat(3, int(friend[3][0]) + int(friend[3][1]) / CONST_Y_DIVIDE ) # # Mettre a jour mon "Me" # me = getMyMiningShipMemory(self) # logger.info( "Copier memoire Fighter : fin" ) logger.info( "Copier memoire Base : debut" ) for i in n: if isinstance(i, aiwar.Base) and self.isFriend(i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # Me.0 if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Base : me[0]" ) friend = getFriendBaseMemory(self, i) logger.info( "Copier memoire Base : getFriendBaseMemory" ) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[1]: logger.info( "Copier memoire Base : Base[2]=>Me[0]" ) logger.error( "Poto rose") self.setMemoryFloat(0, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) elif friend[3] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[3] != me[1]: logger.info( "Copier memoire Base : Base[3]=>Me[0]" ) logger.error( "Poto rose") self.setMemoryFloat(0, int(friend[3][0]) + int(friend[3][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) elif friend[4] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[4] != me[1]: logger.info( "Copier memoire Base : Base[4]=>Me[0]" ) logger.error( "Poto rose") self.setMemoryFloat(0, int(friend[4][0]) + int(friend[4][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Me.1 if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Base : me[1]" ) friend = getFriendBaseMemory(self, i) if friend[4] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[4] != me[0]: logger.info( "Copier memoire Base : Base[4]=>Me[1]" ) logger.error( "Poto rose") self.setMemoryFloat(1, int(friend[4][0]) + int(friend[4][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) elif friend[3] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[3] != me[0]: logger.info( "Copier memoire Base : Base[3]=>Me[1]" ) logger.error( "Poto rose") self.setMemoryFloat(1, int(friend[3][0]) + int(friend[3][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) elif friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[0]: logger.info( "Copier memoire Base : Base[2]=>Me[1]" ) logger.error( "Poto rose") self.setMemoryFloat(1, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Effacer son "Ennemy" s'il est dans la BASE croisée # Me.2 if me[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if me[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) \ and ( friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) \ and in_circle( friend[0][0], friend[0][1], aiwar.MININGSHIP_DETECTION_RADIUS()/4, me[2][0], me[2][1]) \ or friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) \ and in_circle( friend[1][0], friend[1][1], aiwar.MININGSHIP_DETECTION_RADIUS()/4, me[2][0], me[2][1]) ): #if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] == me[2]: # Effacer l'ennemi de ma memoire self.setMemoryFloat(2, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # # Ne pas enregistrer les ennemis de la base ou des fighters # # Me.2 # if me[2] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # logger.info( "Copier memoire Base : me[3]" ) # friend = getFriendBaseMemory(self, i) # if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # logger.error( "Poto rose") # self.setMemoryFloat(2, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # # Mettre a jour mon "Me" # me = getMyMiningShipMemory(self) # elif friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): # logger.error( "Poto rose") # self.setMemoryFloat(2, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # # Mettre a jour mon "Me" # me = getMyMiningShipMemory(self) logger.info( "Copier memoire Base : fin" ) # rentrer a la base ? logger.info( "rentrer a la base ? : debut" ) if self.mineralStorage() == aiwar.MININGSHIP_MAX_MINERAL_STORAGE() or self.fuel() < ( self.distanceTo(basePos) if baseConnue else 170 ) or ennemiEnVue: if baseConnue or ennemiEnVue: if baseConnue: logger.error( "je rentre a la base" ) if ennemiEnVue: logger.error( "je fuis a la base" ) self.rotateTo(basePos) # Se deplacer tant qu'on est loin de la cible if self.distanceTo(basePos) > (aiwar.MININGSHIP_MINING_RADIUS()/4): self.move() # base en vue et assez proche pour donner le minerai ? for i in n: if isinstance(i, aiwar.Base) and self.isFriend(i): if self.distanceTo(i) < aiwar.MININGSHIP_MINING_RADIUS(): logger.error( "je donne mon minerai a ma base" ) self.pushMineral(i, self.mineralStorage()) break if baseConnue: logger.info( "Fin de traitement MiningShip (rapporter minerais)." ) if ennemiEnVue: logger.info( "Fin de traitement MiningShip (sauve qui peut !)." ) return else: logger.error( "je cherche ma base" ) random_move(self) logger.info( "Fin de traitement MiningShip (recherche base)." ) return logger.info( "rentrer a la base ? : fin" ) # recherche de minerais visible logger.info( "recherche de minerais visible : debut" ) for i in n: if isinstance(i, aiwar.Mineral): mpx,mpy = minPos = i.pos() # Me.0 if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and minPos!= me[1]: logger.error( "je sauvegarde la position du minerai" ) self.setMemoryFloat(0, int(mpx) + int(mpy) / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) # Me.1 if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and minPos!= me[0]: logger.error( "je sauvegarde la position du minerai" ) self.setMemoryFloat(1, int(mpx) + int(mpy) / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) logger.error( "je vais au minerais visible" ) self.rotateTo(minPos) # Se deplacer tant qu'on est loin de la cible if self.distanceTo(minPos) > (aiwar.MININGSHIP_MINING_RADIUS()/2): self.move() if self.distanceTo(i) < aiwar.MININGSHIP_MINING_RADIUS(): logger.error( "je mine" ) self.extract(i) logger.info( "Fin de traitement MiningShip (mineral visible)." ) return logger.info( "recherche de minerais visible : fin" ) # recherche de minerai connu logger.info( "recherche de minerais connu : debut" ) if me[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.error( "je connais un minerai 0" ) # on aurait du voir le minerai -> il est vide if self.distanceTo(me[0]) < aiwar.MININGSHIP_DETECTION_RADIUS(): # reset de la position self.setMemoryFloat(0, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) else: logger.error( "je vais au minerais connus 0" ) self.rotateTo(me[0]) # Se deplacer tant qu'on est loin de la cible if self.distanceTo(me[0]) > (aiwar.MININGSHIP_MINING_RADIUS()/2): self.move() logger.info( "Fin de traitement MiningShip (mineral 0 memoire)." ) return elif me[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.error( "je connais un minerai 1" ) if self.distanceTo(me[1]) < aiwar.MININGSHIP_DETECTION_RADIUS(): # on aurait du voir le minerai -> il est vide # reset de la position self.setMemoryFloat(1, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE) # Mettre a jour mon "Me" me = getMyMiningShipMemory(self) else: logger.error( "je vais au minerais connus 1" ) self.rotateTo(me[1]) # Se deplacer tant qu'on est loin de la cible if self.distanceTo(me[1]) > (aiwar.MININGSHIP_MINING_RADIUS()/2): self.move() logger.info( "Fin de traitement MiningShip (mineral 1 memoire)." ) return logger.info( "recherche de minerais connu : fin" ) logger.info( "Fin de traitement MiningShip." )
def play_base_test(self): logger.error( "#################################################################" ) logger.error( "" ) logger.error( "*********BASE********** : (%s, %s)", int(self.pos()[0]), int(self.pos()[1]) ) logger.error( "Vie: %s\t-\tmineralStorage: %s", self.life(), self.mineralStorage() ) logMyBaseMemory(self) me = getMyBaseMemory(self) # Definir la position opposee a la BASE px,py = basePos = self.pos() # X position px_cible=CONST_WORLD_SIZE_X - px # Y position py_cible=CONST_WORLD_SIZE_Y - py # Initialiser la direction a prendre pour decouvrir la carte posMineralSelf = me[2] if posMineralSelf == (CONST_MINERAL_VOID, CONST_MINERAL_VOID): logger.error( "Voici ma position: X=%s - Y=%s", px, py ) # Ajouter l'information ESTIMEE # CONST_MINERAL_ESTIMATE #ADU ADU ADU ADU #ADU ADU ADU ADU #ADU ADU ADU ADU # Enregister la position cible - MiningShip self.setMemoryFloat( 2, int(px_cible) + int(py_cible)/CONST_Y_DIVIDE ) # Enregister la position cible - Fighter self.setMemoryFloat( 0, int(px_cible) + int(py_cible)/CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) logger.error( "J'initialise la trajectoire a explorer: X=%s - Y=%s", px_cible, py_cible ) n = self.neighbours() # Remettre a jour la liste ENNEMY en fonction de l'importance de ce qui est visible. logger.info( "Remettre a jour la liste en fonction de l'importance de ce qui est visible : debut" ) for i in n: if ( isinstance(i, aiwar.MiningShip) \ or isinstance(i, aiwar.Fighter) \ or isinstance(i, aiwar.Base) ) \ and not self.isFriend(i): px,py = ennemiPos = i.pos() logger.error( "++Ennemi spoted near BASE : distance=%s\tx=%s\ty=%s",int(self.distanceTo(i)),int(px),int(py)) self.setMemoryFloat(0, int(px) + int(py) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) logMyBaseMemory(self) # S'il existe un ennemi1 localise, creer un guerrier if me[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and self.mineralStorage() > aiwar.BASE_FIGHTER_PRICE() or self.mineralStorage()!=0 and random.randint( 1, 1+int(5*aiwar.BASE_FIGHTER_PRICE()/self.mineralStorage()) ) == 1: logger.error( "Je fabrique un guerrier" ) self.createFighter() # Initialiser la seconde cible avec "Position opposée BASE" +/- 45 degres fighter_optional_target( (px_cible, py_cible) , self) if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): self.setMemoryFloat(0, me[1][0] + me[1][1] / CONST_Y_DIVIDE ) fighter_optional_target( (px_cible, py_cible) , self) logMyBaseMemory(self) # remissile friend ships for i in n: if isinstance(i, aiwar.Fighter) and self.isFriend(i) and self.distanceTo(i) <= aiwar.BASE_GIVE_MISSILE_RADIUS(): logger.error( "je fais le plein de MISSILES mon ami" ) self.giveMissiles(aiwar.FIGHTER_MAX_MISSILE(), i) # refuel friend ships for i in n: if isinstance(i, aiwar.MiningShip) and self.isFriend(i) and self.distanceTo(i) <= aiwar.BASE_REFUEL_RADIUS(): logger.error( "je fais le plein de FUEL de mon ami" ) self.refuel(aiwar.MININGSHIP_START_FUEL(), i) # create new MiningShip if self.mineralStorage() > (2*aiwar.BASE_FIGHTER_PRICE()) and random.randint( 1, 1+ int(5*aiwar.BASE_MININGSHIP_PRICE()/self.mineralStorage()) ) == 1: logger.error( "Je fabrique un mineur" ) self.createMiningShip() # Initialiser la seconde mine avec "Position opposée BASE" +/- 45 degres miningship_optional_target( (px_cible, py_cible) , self) logMyBaseMemory(self) # communiquer avec les copains me = getMyBaseMemory(self) # Copier Friend.0=>Me.1 / Friend.1=>Me.0 / Friend.2=>Me.2 logger.info( "Copier memoire MiningShip : debut" ) for i in n: if isinstance(i, aiwar.MiningShip) and self.isFriend(i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # Me.0 if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[0]" ) friend = getFriendMiningShipMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[1]: logger.info( "Copier memoire Minier : Friends[2]=>Me[0]" ) logger.error( "Poto minier" ) self.setMemoryFloat(0, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.1 if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[1]" ) friend = getFriendMiningShipMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[0]: logger.info( "Copier memoire Minier : Friends[2]=>Me[1]" ) logger.error( "Poto minier" ) self.setMemoryFloat(1, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.2 if me[2] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[2]" ) friend = getFriendMiningShipMemory(self, i) logger.info( "Copier memoire Minier : getFriendMiningShipMemory" ) if friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[3] and friend[1] != me[4]: logger.info( "Copier memoire Minier : Friends[1]=>Me[2]" ) logger.error( "Poto minier" ) self.setMemoryFloat(2, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) elif friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[3] and friend[1] != me[4]: logger.info( "Copier memoire Minier : Friends[0]=>Me[2]" ) logger.error( "Poto minier" ) self.setMemoryFloat(2, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.3 if me[3] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[3]" ) friend = getFriendMiningShipMemory(self, i) if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[2] and friend[0] != me[4]: logger.info( "Copier memoire Minier : Friends[0]=>Me[3]" ) logger.error( "Poto minier" ) self.setMemoryFloat(3, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) elif friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[2] and friend[0] != me[4]: logger.info( "Copier memoire Minier : Friends[1]=>Me[3]" ) logger.error( "Poto minier" ) self.setMemoryFloat(3, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.4 if me[4] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): logger.info( "Copier memoire Minier : Me[4]" ) friend = getFriendMiningShipMemory(self, i) logger.info( "Copier memoire Minier : getFriendMiningShipMemory" ) if friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[3] and friend[1] != me[2]: logger.info( "Copier memoire Minier : Friends[1]=>Me[4]" ) logger.error( "Poto minier" ) self.setMemoryFloat(4, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) elif friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[3] and friend[1] != me[2]: logger.info( "Copier memoire Minier : Friends[0]=>Me[4]" ) logger.error( "Poto minier" ) self.setMemoryFloat(4, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) logger.info( "Copier memoire MiningShip : fin" ) logger.info( "Copier memoire Fighter : debut" ) for i in n: if isinstance(i, aiwar.Fighter) and self.isFriend(i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # Me.0 # Copie du guerrier seulement s'il revient vers nous if me[0] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and ship_isBack(self, i): friend = getFriendFighterMemory(self, i) if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[1]: logger.error( "Poto policier" ) self.setMemoryFloat(0, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) elif friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[1]: logger.error( "Poto policier" ) self.setMemoryFloat(0, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.1 # Copie du guerrier seulement s'il revient vers nous if me[1] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and ship_isBack(self, i): friend = getFriendFighterMemory(self, i) if friend[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[0] != me[0]: logger.error( "Poto policier" ) self.setMemoryFloat(1, int(friend[0][0]) + int(friend[0][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) elif friend[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[1] != me[0]: logger.error( "Poto policier" ) self.setMemoryFloat(1, int(friend[1][0]) + int(friend[1][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.2 if me[2] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[3] and friend[2] != me[4]: logger.error( "Poto policier" ) self.setMemoryFloat(2, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.3 if me[3] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[2] and friend[2] != me[4]: logger.error( "Poto policier" ) self.setMemoryFloat(3, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) # Me.4 if me[4] == (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID): friend = getFriendFighterMemory(self, i) if friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != me[3] and friend[2] != me[2]: logger.error( "Poto policier" ) self.setMemoryFloat(4, int(friend[2][0]) + int(friend[2][1]) / CONST_Y_DIVIDE ) # Mettre a jour mon "Me" me = getMyBaseMemory(self) logger.info( "Copier memoire Fighter : fin" ) # Effacer de tous les miniers, les ennemis deja enregistrés logger.info( "Effacer Ennemi de la memoire MiningShip : debut" ) for i in n: if isinstance(i, aiwar.MiningShip) and self.isFriend(i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): friend = getFriendMiningShipMemory(self, i) if me[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and in_circle( friend[2][0], friend[2][1], aiwar.MININGSHIP_DETECTION_RADIUS()/4, me[0][0], me[0][1]): #if me[0] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] == me[0]: # Effacer l'ennemi de la memoire du minier self.setMemoryFloat(2, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE, i ) if me[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and in_circle( friend[2][0], friend[2][1], aiwar.MININGSHIP_DETECTION_RADIUS()/4, me[1][0], me[1][1]): #if me[1] != (CONST_ENNEMY_VOID, CONST_ENNEMY_VOID) and friend[2] == me[1]: # Effacer l'ennemi de la memoire du minier self.setMemoryFloat(2, CONST_ENNEMY_VOID + CONST_ENNEMY_VOID / CONST_Y_DIVIDE, i ) logger.info( "Effacer Ennemi de la memoire MiningShip : fin" )
def play_miningship(self): self.log("*******MININGSHIP******") self.log("Vie: {}".format(self.life())) self.log("MineralStorage: {}".format(self.mineralStorage())) self.log("Fuel: {}".format(self.fuel())) n = self.neighbours() # recherche de la base amie baseConnue = False basePos = (self.getMemoryFloat(0), self.getMemoryFloat(1)) if basePos != (0.0, 0.0): self.log("je connais ma base") baseConnue = True else: for i in n: if isinstance(i, aiwar.Base) and self.isFriend(i): self.log("base trouvee") px, py = basePos = i.pos() self.setMemoryFloat(0, px) self.setMemoryFloat(1, py) baseConnue = True break # communiquer avec les copains for i in n: if (isinstance(i, aiwar.Base) or isinstance(i, aiwar.MiningShip)) and self.isFriend( i) and self.distanceTo(i) <= aiwar.COMMUNICATION_RADIUS(): # si on connait la position du mineral posMineralSelf = (self.getMemoryFloat(2), self.getMemoryFloat(3)) if posMineralSelf != (0.0, 0.0): #envoi de la position du mineral s'il ne la connait pas posMineralCopain = (self.getMemoryFloat(2, i), self.getMemoryFloat(3, i)) if posMineralCopain == (0.0, 0.0): self.setMemoryFloat(2, posMineralSelf[0], i) self.setMemoryFloat(3, posMineralSelf[1], i) self.log( "J'ai donne la position de mon minerais a mon copain") # rentrer a la base ? if self.mineralStorage() == aiwar.MININGSHIP_MAX_MINERAL_STORAGE( ) or self.fuel() < (self.distanceTo(basePos) if baseConnue else 170): if baseConnue: self.log("je rentre a la base") self.state(aiwar.DARK) self.rotateTo(basePos) self.move() # base en vue et assez proche pour donner le minerai ? for i in n: if isinstance(i, aiwar.Base) and self.isFriend(i): if self.distanceTo(i) <= aiwar.MININGSHIP_MINING_RADIUS(): self.log("je donne mon minerai a ma base") self.pushMineral(i, self.mineralStorage()) break return else: self.log("je cherche ma base") random_move(self) return # recherche de minerais visible for i in n: if isinstance(i, aiwar.Mineral): self.log("je sauvegarde la position du minerai") mpx, mpy = i.pos() self.setMemoryFloat(2, mpx) self.setMemoryFloat(3, mpy) self.log("je vais au minerais visible") self.state(aiwar.DEFAULT) self.rotateTo(i) self.move() if self.distanceTo(i) <= (aiwar.MININGSHIP_MINING_RADIUS() - 1): self.log("je mine") self.state(aiwar.LIGHT) self.extract(i) return # recherche de minerai connu minPos = (self.getMemoryFloat(2), self.getMemoryFloat(3)) if minPos != (0.0, 0.0): self.log("je connais un minerai") if self.distanceTo(minPos) < aiwar.MININGSHIP_DETECTION_RADIUS( ): # on aurait du voir le minerai -> il est vide # reset de la position self.setMemoryFloat(2, 0.0) self.setMemoryFloat(3, 0.0) else: self.log("je vais au minerais connus") self.state(aiwar.DEFAULT) self.rotateTo(minPos) self.move() return # deplacement aleatoire self.log("je cherche du minerais") self.state(aiwar.DEFAULT) random_move(self)