def frame(self): if (game.getFrameCount() % curTask.frameSkip != 2): for i in game.getAllUnits(): if (i.getLastCommand().getType().getName() == 'Move'): game.drawLineMap(i.getPosition(), i.getLastCommand().getTargetPosition(), pybrood.Colors.Red) return for i in game.getAllUnits(): if (curTask.can_control(i, self.playerMe)): if (i.getID() in Socks): continue Socks[i.getID()] = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Socks[i.getID()].connect((address, 12346)) kys = list(Socks.keys()) for i in kys: if (curTask.is_terminal(game.getUnit(i))): unitThreads[i] = threading.Thread(target=dead_unit, args=[i]) unitThreads[i].start() else: unitThreads[i] = threading.Thread(target=unit_thread, args=[i]) unitThreads[i].start() for i in unitThreads.keys(): unitThreads[i].join() for i in kys: if (curTask.is_terminal(game.getUnit(i))): Socks[i].close() Socks.pop(i, None) unitThreads.pop(i, None) if (game.getFrameCount() >= curTask.maxFrame or len(Socks) == 0): ans = curTask.finalValueFunc(self.playerMe) print('final Value', ans) game.leaveGame()
def findEnemyBaseFinalValue(player): for u in game.getAllUnits(): if (u.getType().getName() in ['Protoss_Nexus']): return 0 loc = game.getStartLocations() myLoc = player.getStartLocation() ans = numpy.inf for i in loc: for u in game.getAllUnits(): if (u.getType().getName() == 'Zerg_Drone'): if (i != myLoc and numpy.linalg.norm(numpy.array(u.getPosition()) - i) < ans): ans = numpy.linalg.norm(numpy.array(myLoc) - i) return -ans
def frame(self): if (game.isReplay() == True): for i in game.getAllUnits(): if (i.getType().getName() == 'Zerg_Drone'): #if(random.randint(1,5)!=1): # continue if (newOrder(i)): mz = util32.ord2cmd(i.getOrder().getID()) ''' if(mz==0): if(random.randint(1,200)<=199): continue elif(mz==1 or mz==3 or mz==5): if(random.randint(1,10)<=9): continue ''' #x=util32.game2stateDrone(i) x = util32.game2msgDrone(i) y = [ i.getOrderTargetPosition()[0] + 180 - i.getPosition()[0], i.getOrderTargetPosition()[1] + 180 - i.getPosition()[1], mz ] pickle.dump(x, self.fout) pickle.dump(y, self.fout)
def findGasValue(unit): #gasPos=[11111,11111] ans = numpy.inf for u in game.getAllUnits(): if (u.getType() == pybrood.UnitTypes.Resource_Vespene_Geyser): if (dist(u.getPosition(), unit.getPosition()) < ans): ans = dist(u.getPosition(), unit.getPosition()) return -ans / (pybrood.UnitTypes.Zerg_Drone.topSpeed() * 10)
def prepare(self): self.playerMe=game.self() global minerals units=game.getAllUnits() minerals=[] for u in units: if(u.getType().getName()=='Resource_Mineral_Field'): minerals.append(u)
def findEnemyBaseValue(unit): for u in game.getAllUnits(): if (u.getType().getName() in ['Protoss_Nexus']): if (u.getPlayer() != unit.getPlayer()): return 0 loc = game.getStartLocations() myLoc = unit.getPlayer().getStartLocation() ans = numpy.inf for i in loc: if (i != myLoc and numpy.linalg.norm(numpy.array(myLoc) - i) < ans): ans = numpy.linalg.norm(numpy.array(myLoc) - i) return -ans
def prepare(self): force = game.getForce(0) print(force) print(force.getID()) print(force.getName()) units = game.getAllUnits() for u in units: print('Unit', u.getID(), u.getType().getName(), u.getPosition(), u.getTilePosition()) game.print('Hello world!') print(Color(255, 0, 0).getName())
def command(unit, order): showCommands = 0 # order=[random.randint(-239,239),random.randint(-239,239),random.randint(0,5)] coord = unit.getPosition() coord[0] += order[0] - WINDOW_SIZE // 2 coord[1] += order[1] - WINDOW_SIZE // 2 game.drawLineMap(unit.getPosition(), coord, pybrood.Colors.Red) #game.drawLineMouse(unit.getPosition(), coord, pybrood.Colors.Red) #game.drawLineScreen(unit.getPosition(), coord, pybrood.Colors.Red) lcmd = unit.getLastCommand() if (showCommands): for uu in game.getAllUnits(): if (order[2] == 1 and uu.getID() != unit.getID() and collide(order, unit)): print('conflict') # print('cmd',lcmd.getType().getName(),lcmd.getTargetPosition()) if (lcmd.getTargetPosition() == coord and type2cmd(lcmd.getType()) == order[2]): return if (order[2] == 0): if (showCommands): print('holding') unit.holdPosition() elif (order[2] == 1): if (showCommands): print('moving to', coord) unit.move(coord) elif (order[2] == 4): if (showCommands): print('building') unit.build(pybrood.UnitTypes.Zerg_Spawning_Pool, coord) elif (order[2] == 3): if (showCommands): print('gathering ', coord, get_all_mineral()) unit.gather(game.getClosestUnit(coord)) elif (order[2] == 2): if (showCommands): print('attacking ', coord) unit.attack(game.getClosestUnit(coord, radius=1)) elif (order[2] == 5): unit.returnCargo()
def frame(self): #return curFrame=game.getFrameCount() units=game.getAllUnits() regions=game.getAllRegions() if(curFrame>=3600): trace.append(self.playerMe.gatheredMinerals()-50) print(trace) game.restartGame() if(curFrame%move_every!=0): return for u in units: if(u.getType().getName()=='Terran_SCV' and u.getPlayer().getID()==self.playerMe.getID()): k=wrapup(units,regions,u,curFrame//move_every,self.playerMe.gatheredMinerals()-50,u.getOrder().getName()) soc.send(k) k=b'' k=soc.recv(10240) k=unravel(k) move(u,k) elif(u.getType().getName()=='Terran_Command_Center'): #print('minerals:%d'%self.playerMe.minerals(),typeSCV) if(self.playerMe.minerals()>=50 and u.canTrain(typeSCV)): u.train(typeSCV)
def dragoonDefusalValue(unit): ans = 0 for u in game.getAllUnits(): if (u.getType() == pybrood.UnitTypes.Terran_Vulture_Spider_Mine): ans += 1 return unit.getKillCount() - ans * 0.2
def get_all_drones(): ans = [] for i in game.getAllUnits(): if (i.getType().getName() == 'Zerg_Drone'): ans.append(i.getPosition()) return ans
def get_all_mineral(): ans = [] for i in game.getAllUnits(): if (i.getType().getName() == 'Resource_Mineral_Field'): ans.append(i.getPosition()) return ans