def midfielder(self, robot_id): goal_dist = helper.distance(self.cur_my_posture[robot_id][X], self.field[X] / 2, self.cur_my_posture[robot_id][Y], 0) shoot_mul = 1 dribble_dist = 0.426 v = 5 goal_to_ball_unit = helper.unit( [self.field[X] / 2 - self.cur_ball[X], -self.cur_ball[Y]]) delta = [ self.cur_ball[X] - self.cur_my_posture[robot_id][X], self.cur_ball[Y] - self.cur_my_posture[robot_id][Y] ] # if (self.distances[MY_TEAM][robot_id] < 0.5) and (delta[X] > 0): if self.distances[MY_TEAM][robot_id] < 0.5: # near self.wheels[2 * robot_id:2 * robot_id + 2] = self.agent.get_action( np.reshape(self.histories[robot_id], -1)) # ddpg action self.printConsole("robot id " + str(robot_id) + " distance: " + str(self.distances[MY_TEAM][robot_id])) self.printConsole("robot id " + str(robot_id) + "ddpg action") else: # far self.position( robot_id, self.cur_ball[X] - dribble_dist * goal_to_ball_unit[X], self.cur_ball[Y] - dribble_dist * goal_to_ball_unit[Y])
def midfielder(self, robot_id): goal_dist = helper.distance(self.cur_my[robot_id][X], self.field[X]/2, self.cur_my[robot_id][Y], 0) shoot_mul = 1 dribble_dist = 0.426 v = 5 goal_to_ball_unit = helper.unit([self.field[X]/2 - self.cur_ball[X], - self.cur_ball[Y]]) delta = [self.cur_ball[X] - self.cur_my[robot_id][X], self.cur_ball[Y] - self.cur_my[robot_id][Y]] if (self.dist_ball[MY_TEAM][robot_id] < 0.5) and (delta[X] > 0): self.position(robot_id, self.cur_ball[X] + v*delta[X], self.cur_ball[Y] + v*delta[Y]) else: self.position(robot_id, self.cur_ball[X] - dribble_dist*goal_to_ball_unit[X], self.cur_ball[Y] - dribble_dist*goal_to_ball_unit[Y])