def main(): #connect to print sys.argv[1] #via this port print sys.argv[2] #wait before moveing around print sys.argv[3] playerList = [] n = NC.client_thread(sys.argv[1],int(sys.argv[2])) n.connect() time.sleep(int(sys.argv[3])) cashRate = 50 cashTicks = 0 cash = 100 DONE = False while not DONE: n.send() #Bot Logic Goes Here n.minput(25, random.randint(0,1000), random.randint(0,1000)) #/Bot Logic #Game Engine Logic Is Here n.recv() while not n.recv_queue.empty(): tempData = n.recv_queue.get()
def connectGame(screen, settingData): print "Starting New Game" print settingData[1] n = NC.client_thread(settingData[0],int(settingData[1])) n.connect() pygame.display.set_caption('New Game') print "Done" return n;
def main(): #connect to print sys.argv[1] #via this port print sys.argv[2] #wait before moveing around print sys.argv[3] playerList = [] n = NC.client_thread(sys.argv[1],int(sys.argv[2])) n.connect() time.sleep(int(sys.argv[3])) cashRate = 50 cashTicks = 0 cash = 100 DONE = False while not DONE: n.send() cashTicks += 1 if cashTicks == cashRate: cash += 1 cashTicks = 0 #Bot Logic Goes Here push = random.randint(0,200) if (push < 50): n.minput(1, random.randint(0,1000), random.randint(0,1000)) elif (push > 70): n.minput(3, random.randint(0,1000), random.randint(0,1000)) elif (push == 53): n.minput(24, random.randint(0,1000), random.randint(0,1000)) cash -= 8 elif (push == 54): n.minput(25, random.randint(0,1000), random.randint(0,1000)) cash -= 10 #/Bot Logic #Game Engine Logic Is Here n.recv() while not n.recv_queue.empty(): tempData = n.recv_queue.get()
def client(): # Initialize components n = NC.client_thread(sys.argv[2],8888) n.connect() c = C.console(n) c.setDaemon(True) c.start() # Dummy main event loop for client while n.connected: if n.match: # This loop will run at a pre determined rate (eg. 10 Hz) # Pack/queue all player commands (NET:Provide methods to pack and queue) n.send() # Send player commands (NET:Provide method to send all packets) # Process all commands (NET:Provide access to all the commands) # Process metrics (NET:Provide access to simplified metrics) # Progess turn number (NET:Handle internally I think) time.sleep(1) # Dummy frame render time n.recv() # Recv oponent commands (NET:Provide method to recv all packets) else: pass
def main(): #connect to print sys.argv[1] #via this port print sys.argv[2] #wait before moveing around print sys.argv[3] playerList = [] pygame.init() windowSize = 640,480 screen = pygame.display.set_mode(windowSize,0,8) n = NC.client_thread(sys.argv[1],int(sys.argv[2])) n.connect() for peer in n.peer_list: playerList.append(player.Player(peer[0], peer[1])) time.sleep(int(sys.argv[3])) sel = False DONE = False mySelf = None n.minput(1,52,52) aDelta = time.time() elapsedTime = 0 while not DONE: n.send() #Bot Logic Goes Here push = random.randint(0,4) # time deltas to keep track of when to click on the screen bDelta = time.time() elapsedTime += (bDelta - aDelta) aDelta = bDelta #Game Engine Logic Is Here n.recv() while not n.recv_queue.empty(): tempData = n.recv_queue.get() if tempData[2] == 7: playerList.append(player.Player(tempData[3], tempData[4])) for person in playerList: if n.info.cid == person.playerID: mySelf = person for person in playerList: if tempData[0] == person.playerID: if tempData[2] == 2: if tempData[3][0] == 1: # selecting for tro in person.troops: tro.setSelectVal(False) for tro in person.troops: dist = vec.subtract(tempData[3][1], tempData[3][2], tro.getLocationX(), tro.getLocationY()) if fabs(dist[0])< tro.size and fabs(dist[1]) < tro.size: tro.setSelectVal(True) break else: tro.setSelectVal(False) elif tempData[3][0] == 3: # orders for tro in person.troops: if tro.isSelected(): tro.moveToTargetX = tempData[3][1] tro.moveToTargetY = tempData[3][2] for person in playerList: for tro in person.troops: unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed()) tro.setRotation(unitDirect) tro.locationX = tro.locationX + (tro.speed * unitDirect[0]) tro.locationY = tro.locationY + (tro.speed * unitDirect[1]) # Follow player 1's speedster troop if mySelf != None and elapsedTime > 0.5: elapsedTime = 0 for person in playerList: if person.playerID == 1: unitDirect = vec.unitdir(person.troops[0].moveToTargetX, person.troops[0].moveToTargetY, person.troops[0].locationX, person.troops[0].locationY, person.troops[0].getSpeed()) if unitDirect[0] != 0 and unitDirect[1] != 0: print "moving, must gettem" n.minput(3, person.troops[0].getLocationX(), person.troops[0].getLocationY())
def main(): #connect to print sys.argv[1] #via this port print sys.argv[2] #wait before moveing around print sys.argv[3] playerList = [] pygame.init() windowSize = 640,480 screen = pygame.display.set_mode(windowSize,0,8) n = NC.client_thread(sys.argv[1],int(sys.argv[2])) n.connect() for peer in n.peer_list: playerList.append(player.Player(peer[0], peer[1])) time.sleep(int(sys.argv[3])) DONE = False while not DONE: n.send() #Game Engine Logic Is Here n.recv() while not n.recv_queue.empty(): tempData = n.recv_queue.get() if tempData[2] == 7: playerList.append(player.Player(tempData[3], tempData[4])) for person in playerList: if n.info.cid == person.playerID: mySelf = person for person in playerList: if tempData[0] == person.playerID: if tempData[2] == 2: if tempData[3][0] == 1: for tro in person.troops: tro.setSelectVal(False) for tro in person.troops: dist = vec.subtract(tempData[3][1], tempData[3][2], tro.getLocationX(), tro.getLocationY()) if fabs(dist[0])< tro.size and fabs(dist[1]) < tro.size: tro.setSelectVal(True) break else: tro.setSelectVal(False) elif tempData[3][0] == 3: for tro in person.troops: if tro.isSelected(): tro.moveToTargetX = tempData[3][1] tro.moveToTargetY = tempData[3][2] for person in playerList: for tro in person.troops: unitDirect = vec.unitdir(tro.getMoveToTargetX(), tro.getMoveToTargetY(), tro.getLocationX(), tro.getLocationY(), tro.getSpeed()) tro.setRotation(unitDirect) tro.locationX = tro.locationX + (tro.speed * unitDirect[0]) tro.locationY = tro.locationY + (tro.speed * unitDirect[1]) #Bot Logic Goes Here #for each unit for play in playerList: if play.playerID == n.info.cid: for tro in play.troops: num = random.randint(0,5) if num == 1: n.minput(1,tro.locationX+1, tro.locationY+1) n.minput(3, random.randint(0,1000), random.randint(0,1000)) if (num == 2): n.minput(1, random.randint(0,1000), random.randint(0,1000)) elif (num == 3): n.minput(3, random.randint(0,1000), random.randint(0,1000))