def receive_info(self): info = clientpy3.run(id, passwd, "STATUS") #print(info) self.parse_info(info) #test = STATUS() #test.receive_info()
def receive_info(self): info = clientpy3.run(id, passwd, "STATUS").split() #print(info) self.mines = [] self.players = [] self.bombs = [] self.wormholes = [] self.parse_info(info)
def receive_scan(self, x, y): info = clientpy3.run(id, passwd, "SCAN {} {}".format(x, y)).split() if (info[0] == "ERROR"): return False info = [info[0]] + [x, y, 0, 0] + info[1:] #print(info) self.mines = [] self.players = [] self.bombs = [] self.wormholes = [] self.parse_info(info) return True
def moveDiag(curInfo,VISIONRADIUS,MAPWIDTH): chk = checkMine(curInfo) if chk > -1: minex = curInfo['mines'][chk][1] miney = curInfo['mines'][chk][2] foundMine = True else: foundMine = False x = curInfo['x'] y = curInfo['y'] angle = np.random.uniform(0,2*np.pi) run('ElectricBoogalo', 'kirtyhurty', 'ACCELERATE ' + str(angle) + ' 1') # run('ElectricBoogalo', 'kirtyhurty', 'ACCELERATE ' + str(np.arctan(2*float(VISIONRADIUS)/float(MAPWIDTH))) + ' 1') while foundMine == False: curInfo = parseStatus() search_chk = searchAndFind(curInfo, VISIONRADIUS) chk = checkMine(curInfo) if chk > -1: print ('mine found by vision!') run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') minex = curInfo['mines'][chk][1] miney = curInfo['mines'][chk][2] break elif search_chk > -1: print ('mine found by scanning!') minex = globals.KNOWN_MINE_LOC[search_chk][1] miney = globals.KNOWN_MINE_LOC[search_chk][2] break else: foundMine = False print ('moving to: ' + str(minex) +" "+ str(miney)) curInfo = parseStatus() x = curInfo['x'] y = curInfo['y'] moveToPoint(x, y, minex, miney, mineTaking=True)
def __init__(self): to_parse = clientpy3.run(id, passwd, "CONFIGURATIONS") parsed = to_parse.split(" ") #print(parsed) self.width = float(parsed[2]) self.height = float(parsed[4]) self.capture_radius = float(parsed[6]) self.vision_radius = float(parsed[8]) self.friction = float(parsed[10]) self.brake_friction = float(parsed[12]) self.bomb_placer_radius = float(parsed[14]) self.bomb_effect_radius = float(parsed[16]) self.bomb_delay = float(parsed[18]) self.bomb_power = float(parsed[20]) self.scan_radius = float(parsed[22]) self.scan_delay = float(parsed[24].replace('\n', ''))
def avoidWormHole(check, angleChange, angle, xDest, yDest): run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') time.sleep(1) while (check > -1): run('ElectricBoogalo', 'kirtyhurty', 'ACCELERATE ' + str(angle + angleChange) + ' 1') stats = parseStatus() check, differentAngle = checkWormHoleCollision(float(stats['x']), float(stats['y']), xDest, yDest) run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') time.sleep(.2) return 0
def moveToPoint(xCur, yCur, xDest, yDest, mineFinding=False, mineTaking=False, foundFromScanning=False): speed = 1 #STOP SHIP FIRST Moving = True run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') while (Moving): stats = parseStatus() if (float(stats['dx']) < 2 and float(stats['dy']) < 2): Moving = False #SET FIRST MOVE ANGLE angle = np.arctan( (yDest - float(stats['y'])) / (xDest - float(stats['x']))) if (xDest < float(stats['x'])): angle += np.pi print(angle) #CHECK FOR POSSIBLE WORMHOLES IN PATH # check, angleChange = checkWormHoleCollision(xCur,yCur,xDest,yDest) # if(check > -1): # avoidWormHole(check, angleChange, angle, xDest,yDest) #TIME TO ACCELERATE Moving = True stats = parseStatus() oldX = float(stats['x']) oldY = float(stats['y']) while (Moving): stats = parseStatus() bombsAway(stats) if (checkGotWormholed(oldX, oldY, stats['x'], stats['y']) == 1): return -1 if (mineFinding): if len(stats['mines']) > 0: chk = checkMine(stats) if (chk > -1): print('MINE FOUND') run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') time.sleep(5) mineFinding = False xDest = stats['mines'][chk][1] yDest = stats['mines'][chk][2] # while(Moving): # stats = parseStatus() # if(float(stats['dx']) < 0.5 and float(stats['dy']) <0.5): # Moving = False # return 1 if (mineTaking): # run('ElectricBoogalo','kirtyhurty','BRAKE') # time.sleep(.0001) if (np.sqrt((float(stats['x']) - xDest)**2 + (float(stats['y']) - yDest)**2) < float( globals.VISIONRADIUS)): chk = checkMine(stats) print(chk) run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') time.sleep(.004) speed = 0.5 if (chk == -2): return 3 xDest, yDest = decideDirection(stats, xDest, yDest) angle = np.arctan( (yDest - float(stats['y'])) / (xDest - float(stats['x']))) if (xDest < float(stats['x'])): angle += np.pi print(angle) oldX = stats['x'] oldY = stats['y'] #CHECK FOR UNKNOWN WORMHOLES. IF DETECTED, BRAKE IMMEDIATELY. # if(len(stats['wormholes']) > 0): # # run('ElectricBoogalo','kirtyhurty','ACCELERATE ' + str(angle+np.pi) + ' 1') # # time.sleep(2) # # run('ElectricBoogalo','kirtyhurty','BRAKE') # KNOWN_WORMHOLE_LOC.append(stats['wormholes'][0]) # print(KNOWN_WORMHOLE_LOC) # #We know there's a wormhole in the way, probably, let's just do our best to avoid it # check, angleChange = checkWormHoleCollision(float(stats['x']),float(stats['y']),xDest,yDest) # avoidWormHole(check, angleChange, angle, xDest,yDest) run('ElectricBoogalo', 'kirtyhurty', 'ACCELERATE ' + str(angle) + ' ' + str(speed)) if (not mineTaking): if (np.sqrt((float(stats['x']) - xDest)**2 + (float(stats['y']) - yDest)**2) < float(globals.VISIONRADIUS) * 2): # run('ElectricBoogalo','kirtyhurty','BRAKE') # while(Moving): # stats = parseStatus() # if(float(stats['dx']) < 0.5 and float(stats['dy']) <0.5): # Moving = False Moving = False # else: # if(np.sqrt((float(stats['x'])-xDest)**2 + (float(stats['y'])-yDest)**2) < float(CAPTURERADIUS) * 2) # a = 0 if (mineFinding): 2 else: return 1
def bombsAway(curInfo): x = curInfo['x'] y = curInfo['y'] run('ElectricBoogalo', 'kirtyhurty', 'BOMB ' + str(x) + ' ' + str(y))
import clientpy3 import time import subprocess import platform #From http://stackoverflow.com/questions/2084508/clear-terminal-in-python def clear(): subprocess.Popen( "cls" if platform.system() == "Windows" else "clear", shell=True) while(True): print("Cash is : " + str(clientpy3.run("___","____","MY_CASH"))) print("Securities are : " + str(clientpy3.run("___","____","MY_SECURITIES"))) print("My orders are are : " + str(clientpy3.run("___","____","MY_ORDERS"))) clientpy3.run("___","____","CLOSE_CONNECTION"); time.sleep(1) clear()
globals.SCANDELAY = config_rets[config_rets.index('SCANDELAY') + 1] circles = findCircles('canvas.png') print(circles.T) curInfo = parseStatus() path = bestPathAlg(circles.T, [curInfo['x'], curInfo['y']]) print(path) while (True): for i in range(np.shape(path)[0]): print(path[i][0]) print(path[i][1]) curInfo = parseStatus() xTrue, yTrue = scanAhead(path[i][0], path[i][1]) if (xTrue == -1 and yTrue == -1): continue moveToPoint(curInfo['x'], curInfo['y'], xTrue, yTrue, mineFinding=False, mineTaking=True) run('ElectricBoogalo', 'kirtyhurty', 'BRAKE') time.sleep(6) # print(circles) # while(True): # curInfo = parseStatus() # moveDiag(curInfo,globals.VISIONRADIUS,globals.MAPWIDTH) # print (globals.KNOWN_MINE_LOC) # print (globals.KNOWN_MINE_LOC_UNLAB)
def current_xy(): s = run(user, pw, 'STATUS').split() return (float(s[1]), float(s[2]))
def brake(): return run(user, pw, 'BRAKE')
def acc(rad, v): return run(user, pw, 'ACCELERATE ' + str(rad) + ' ' + str(v))
def BOMB(x, y, t): clientpy3.run(id, passwd, "BOMB {} {} {}".format(x, y, t))
def BRAKE(): clientpy3.run(id, passwd, "BRAKE")
def ACCELERATE(radians, accel): clientpy3.run(id, passwd, "ACCELERATE {} {}".format(radians, accel))
def scanAhead(x, y): print('proof dude') status = runRet('ElectricBoogalo', 'kirtyhurty', 'SCAN ' + str(x) + ' ' + str(y)) status_rets = status.split(" ") status_rets = list(filter(None, status_rets)) while (status_rets[0] == 'ERROR'): status = runRet('ElectricBoogalo', 'kirtyhurty', 'SCAN ' + str(x) + ' ' + str(y)) stats = parseStatus() xDest, yDest = x, y xDest, yDest = decideDirection(stats, xDest, yDest) angle = np.arctan( (yDest - float(stats['y'])) / (xDest - float(stats['x']))) if (xDest < float(stats['x'])): angle += np.pi run('ElectricBoogalo', 'kirtyhurty', 'ACCELERATE ' + str(angle) + ' 1') status_rets = status.split(" ") status_rets = list(filter(None, status_rets)) time.sleep(0.1) numMines = status_rets[status_rets.index('MINES') + 1] mineList = [] if numMines != 0: for ii in range(int(numMines)): mine = [ status_rets[status_rets.index('MINES') + ((ii * 3) + 2)], float(status_rets[status_rets.index('MINES') + ((ii * 3) + 3)]), float(status_rets[status_rets.index('MINES') + ((ii * 3) + 4)]) ] mineList.append(mine) numWormholes = status_rets[status_rets.index('WORMHOLES') + 1] wormholeList = [] if numWormholes != 0: for ii in range(int(numWormholes)): wormhole = [ float(status_rets[status_rets.index('WORMHOLES') + ((ii * 5) + 2)]), float(status_rets[status_rets.index('WORMHOLES') + ((ii * 5) + 3)]), float(status_rets[status_rets.index('WORMHOLES') + ((ii * 5) + 4)]), float(status_rets[status_rets.index('WORMHOLES') + ((ii * 5) + 5)]), float(status_rets[status_rets.index('WORMHOLES') + ((ii * 5) + 6)]) ] wormholeList.append(wormhole) distList = [] for ii in range(len(mineList)): dist = math.hypot(x - mineList[ii][1], y - mineList[ii][2]) distList.append(dist) if (len(distList) > 0): correct = mineList[distList.index(min(distList))] if (correct[0] == 'ElectricBoogalo'): print('skip b/c we own it') return -1, -1 if numWormholes != '0': dist = math.hypot(correct[1] - wormholeList[0][0], correct[2] - wormholeList[0][1]) if (dist < wormholeList[0][2]): print('skipped b/c wormhole') return -1, -1 else: print('skipped b/c no mine found') return -1, -1 return correct[1], correct[2]
def get_coords(): s = run(user, pw, 'STATUS').split() n = int(s[6]) if n > 0: return (float(s[8]), float(s[9]), s[7])