def getEnemyPosition(self, enemies): enemyPos = Position(0,0) if len(enemies) > 0: for e in enemies: enemyPos += e.getPosition() enemyPos /= len(enemies) return enemyPos else: return self.center
def __init__(self,squad_num): self.units = [] self.center = Position(0,0) self.Max_units=4 self.current_units=0 self.old_current_units=0 self.squad_leader=None self.squad_number=squad_num self.reward=0.01 self.killCounts=[] self.last_squad_leader=True self.enemies=[] self.enemies_old_health=[] self.old_health=0 self.BASE_REWARD=0.01 self.POSITIVE_REWARD=100 self.NEGATIVE_REWARD=-50
def getPosition(self): return Position(self.x, self.y)
def updateCenter(self): self.center = Position(0,0) for unit in self.units: self.center += unit.getPosition() if len(self.units)>0: self.center /= len(self.units)
def explore(self): amt = 1000 shift = Position(randint(-amt, amt), randint(-amt, amt)) pos = self.center + shift self.move(pos)
def attackShift(self, shift): for unit in self.units: unit.attack(Position(shift[0] + unit.getPosition().getX(), shift[1] + unit.getPosition().getY()))
#image1.show() #sleep(5) image = numpy.array(image1) image = skimage1.transform.resize(image, (80, 80)) image = skimage1.color.rgb2gray(image) image = skimage1.exposure.rescale_intensity(image, out_range=(0, 255)) Combatmodel.trainNetwork(squad.reward, image) #use Combatmodel.a_t and Combatmodel.place to get action and do it if Combatmodel.place < 6400: #chose to move x = Combatmodel.place % 80 y = Combatmodel.place / 80 squad.move(Position(ratioW * x, ratioH * y)) elif Combatmodel.place >= 6400 and Combatmodel.place < 12800: #chose to attackmove x = (Combatmodel.place - 6400) % 80 y = (Combatmodel.place - 6400) / 80 squad.attackMove(Position(ratioW * x, ratioH * y)) else: print("do nothing") else: print("Inproper DQNVER input") """ if ctr > 5: ctr = 0 squad.retreat(squad.getNearbyEnemies()) else: ctr += 1