def strategy(self, data): global trajectory print "TEAM", data.teams team = data.teams[self.team] ball = data.ball if my_side == 0: goal = Position(-80,0) else: goal = Position(80,0) Abg = ball.angle_to(goal) # angulo ball to goal obj = RobotPosition(ball.x, ball.y, Abg) current = team[1] if current.distance_to(ball) <= 8: new_obj = move_by_radius(ball.tonp(), 10, Abg) obj = RobotPosition(new_obj[0], new_obj[1], Abg) move = self.controller.go_with_trajectory(obj, current) trajectory = self.traj.get_trajectory(obj, current, 10) out_data = VsssOutData(moves=[ Move(0,0), move, Move(0,0), ]) return out_data
def strategy(self, data): if time.time() - self.start_time < self.all_forwards_time: return self.all_forwards() for i in xrange(self.team_size - 1): if time.time() - self.last_changes[i] > self.durations[i]: if not self.is_lineal[i]: self.durations[i] = uniform(0.5, 1.5) ang = uniform(0, 0.1) if uniform() > 0.5: ang = -ang # lineal if uniform() > 0.5: #forwards self.the_moves[i] = Move(1, ang) else: #backwards self.the_moves[i] = Move(-1, ang) else: self.durations[i] = uniform(0.1, 0.2) # angular if uniform() > 0.5: # left self.the_moves[i] = Move(0, 1) else: # right self.the_moves[i] = Move(0, -1) self.last_changes[i] = time.time() self.is_lineal[i] = not self.is_lineal[i] return VsssOutData(self.change_order(self.the_moves))
def strategy(self, data): team = data.teams[self.team] ball = data.ball goal = Position(50, 50) move = self.controller.go_to_from(goal, team[0]) print move out_data = VsssOutData(moves=[move, Move(0, 0), Move(0, 0)]) return out_data
def set_up(self): super(VisionTestStrategy, self).set_up() self.last_changes = [time.time()] * 3 self.durations = [0] * 3 self.portero_move = Move(0, 1) self.the_moves = [Move(0, 0), Move(0, 0), self.portero_move] self.is_lineal = [0] * 3 self.start_time = time.time() self.all_forwards_time = 2
def strategy(self, data): send_now = False for e in pygame.event.get(): if e.type == pygame.QUIT: self.done = True elif e.type == pygame.KEYDOWN or e.type == pygame.KEYUP: send_now = True if e.key == pygame.K_ESCAPE: self.done = True elif e.key >= pygame.K_0 and e.key <= pygame.K_9: self.power = (e.key - pygame.K_0)/10.0 if self.power == 0: self.power = 1.0 elif e.key == pygame.K_PLUS or e.key == pygame.K_KP_PLUS: self.power += 0.01 elif e.key == pygame.K_MINUS or e.key == pygame.K_KP_MINUS: self.power -= 0.01 if time.time() - self.prev_send > self.own_latency/1000.0: send_now = True if not send_now: return VsssOutData(moves=[Move()]*self.team_size) controls = [ [K_UP, K_DOWN, K_RIGHT, K_LEFT], [K_w, K_s, K_d, K_a], [K_i, K_k, K_l, K_j] ] moves = [] for i in range(self.team_size): move = Move(0, 0) if pygame.key.get_pressed()[controls[i][0]]: move.linvel = self.power if pygame.key.get_pressed()[controls[i][1]]: move.linvel = -self.power if pygame.key.get_pressed()[controls[i][2]]: move.angvel = self.power if pygame.key.get_pressed()[controls[i][3]]: move.angvel = -self.power moves.append(move) print move, print '' self.prev_send = time.time() return VsssOutData(moves=moves)
def strategy(self, data): # global vitoko_gay # vitoko_gay = not vitoko_gay # if vitoko_gay: # return VsssOutData(moves=[Move()]*3) # print data.teams, data.ball team = data.teams[self.team] ball = data.ball goal = RobotPosition(ball.x, ball.y, ball.angle_to(Position(75, 0))) out_data = VsssOutData(moves=[ self.controller.go_to_from(goal, team[0]), Move(0, 0), Move(0, 0), # self.controller.go_to_from(goal, team[1]), # self.controller.go_to_from(goal, team[2]), ]) print out_data.moves return out_data
def strategy(self, data): screen.fill(WHITE) ball = data.ball #ball.x += 75 #ball.y = -ball.y #ball.y += 65 self.pred.update(ball, time.time()) pygame.draw.circle(screen, RED, [ int((ball.x + 75) * enlargement), int((-ball.y + 65) * enlargement) ], int(2.2 * enlargement)) events = pygame.event.get() for event in events: if event.type == pygame.KEYUP: self.do_predict = True if event.type == pygame.KEYDOWN: self.do_predict = False if self.do_predict: self.predPos = self.pred.predict(ball, 2) self.pred_time = time.time() if self.pred_time is None: pass elif time.time() - self.pred_time > 2: self.pred_time = None else: for i, bPosition in enumerate(listPredPositions): col = BLACK if i == 0: col = GREEN pygame.draw.circle(screen, col, [ int((bPosition.x + 75) * enlargement), int((-bPosition.y + 65) * enlargement) ], 3) if len(self.predPos) != 0: for pre in self.predPos: pygame.draw.circle(screen, BLACK, [ int((pre.x + 75) * enlargement), int((-pre.y + 65) * enlargement) ], 3) pygame.display.flip() return VsssOutData(moves=[Move(10, 10)])
def strategy(self, data): global temp_goal global prev_time cur_time = time.time() print "TIME ELAPSED:", time.time() - prev_time prev_time = cur_time goal = RobotPosition(data.ball.x, data.ball.y, data.ball.angle_to(Position(75, 0))) obstacles = data.teams[0] obstacles.extend(data.teams[1]) obstacles.remove(data.teams[self.team][1]) temp_goal = self.controller.get_reference_position( goal, data.teams[self.team][1], obstacles=obstacles) my_move = self.controller.go_to_from_with_angle( goal, data.teams[self.team][1], vel=1, obstacles=obstacles) self.file.write(str(data.teams[self.team][1]) + "\n") if data.teams[self.team][1].distance_to(goal) <= 9: my_move = Move(0, 0) # if data.teams[self.team][1].has_in_front(goal): # my_move = self.controller.go_to_from(Position(75, 0), data.teams[self.team][1], vel=0.5) # my_move = self.controller.go_to_from(goal, data.teams[self.team][1], vel=0.5) return VsssOutData(moves=[Move(0, 0), my_move, Move(0, 0)])
def strategy(self, data): send_now = False for e in pygame.event.get(): if e.type == pygame.QUIT: self.done = True elif e.type == pygame.KEYDOWN or e.type == pygame.KEYUP: send_now = True if e.key == pygame.K_ESCAPE: self.done = True elif e.key >= pygame.K_0 and e.key <= pygame.K_9: self.power = (e.key - pygame.K_0) / 10.0 if self.power == 0: self.power = 1.0 elif e.key == pygame.K_PLUS or e.key == pygame.K_KP_PLUS: self.power += 0.01 elif e.key == pygame.K_MINUS or e.key == pygame.K_KP_MINUS: self.power -= 0.01 if time.time() - self.prev_send > self.own_latency / 1000.0: send_now = True if not send_now: return VsssOutData(moves=[Move()] * self.team_size) controls = [[K_UP, K_DOWN, K_RIGHT, K_LEFT], [K_w, K_s, K_d, K_a], [K_i, K_k, K_l, K_j]] moves = [] for i in range(self.team_size): move = Move(0, 0) if pygame.key.get_pressed()[controls[i][0]]: move.linvel = self.power if pygame.key.get_pressed()[controls[i][1]]: move.linvel = -self.power if pygame.key.get_pressed()[controls[i][2]]: move.angvel = self.power if pygame.key.get_pressed()[controls[i][3]]: move.angvel = -self.power moves.append(move) print move, print '' self.prev_send = time.time() return VsssOutData(moves=moves)
def all_forwards(self): moves = [Move(1.0, 0)] * 2 + [self.portero_move] return VsssOutData(moves=self.change_order(moves))