Example #1
0
    def init(self, info):
        self.field = info['field']
        self.max_linear_velocity = info['max_linear_velocity']
        self.goal = info['goal']
        self.number_of_robots = info['number_of_robots']
        self.end_of_frame = False
        self._frame = 0 
        self.wheels = [0 for _ in range(25)]
        self.cur_posture = []
        self.prev_posture = []
        self.cur_posture_opp = []
        self.cur_ball = []
        self.prev_ball = []
        self.set_default_formation()

        self.previous_frame = Frame()
        self.frame_skip = 2 # number of frames to skip
        self.obs_size = 3 # state size
        self.act_size = 7 # number of discrete actions

        # for RL
        self.action = 0
        self.previous_action = 0

        self.num_inputs = self.obs_size
        # RL algorithm class
        self.load = True
        self.play = True
        self.trainer = DQN(self.number_of_robots, self.obs_size, self.act_size, self.load, self.play)

        helper.printConsole("Initializing variables...")
    def init(self, info):
        self.field = info['field']
        self.max_linear_velocity = info['max_linear_velocity']
        self.robot_size = info['robot_size'][0]
        self.goal = info['goal']
        self.penalty_area = info['penalty_area']
        self.goal_area = info['goal_area']
        self.number_of_robots = info['number_of_robots']
        self.end_of_frame = False
        self._frame = 0
        self.speeds = [0 for _ in range(20)]
        self.cur_posture = []
        self.cur_posture_opp = []
        self.cur_ball = []
        self.previous_ball = []
        self.predicted_ball = []
        self.previous_frame = Frame()
        self.gk_index = 0
        self.d1_index = 1
        self.d2_index = 2
        self.f1_index = 3
        self.f2_index = 4
        self.GK = Goalkeeper(self.field, self.goal, self.penalty_area,
                             self.goal_area, self.robot_size,
                             self.max_linear_velocity[self.gk_index])
        self.D1 = Defender_1(self.field, self.goal, self.penalty_area,
                             self.goal_area, self.robot_size,
                             self.max_linear_velocity[self.d1_index])
        self.D2 = Defender_2(self.field, self.goal, self.penalty_area,
                             self.goal_area, self.robot_size,
                             self.max_linear_velocity[self.d2_index])
        self.F1 = Forward_1(self.field, self.goal, self.penalty_area,
                            self.goal_area, self.robot_size,
                            self.max_linear_velocity[self.f1_index])
        self.F2 = Forward_2(self.field, self.goal, self.penalty_area,
                            self.goal_area, self.robot_size,
                            self.max_linear_velocity[self.f2_index])

        self.game_state = 0

        #   X ,    Y ,    TH
        self.default_formation = [
            -3.80,
            0.00,
            1.57,  # GK
            -2.25,
            1.00,
            0.00,  # D1
            -2.25,
            -1.00,
            0.00,  # D2
            -0.65,
            0.30,
            0.00,  # F1
            -0.65,
            -0.30,
            0.00
        ]  # F2

        self.set_default_formation(self.default_formation)
Example #3
0
 def init(self, info):
     self.field = info['field']
     self.max_linear_velocity = info['max_linear_velocity']
     self.robot_size = info['robot_size'][0]
     self.goal = info['goal']
     self.penalty_area = info['penalty_area']
     self.goal_area = info['goal_area']
     self.number_of_robots = info['number_of_robots']
     self.end_of_frame = False
     self._frame = 0
     self.speeds = [0 for _ in range(30)]
     self.cur_posture = []
     self.cur_posture_opp = []
     self.cur_ball = []
     self.previous_ball = []
     self.previous_posture = []
     self.previous_posture_opp = []
     self.predicted_ball = []
     self.idx = 0
     self.idx_opp = 0
     self.previous_frame = Frame()
     self.defense_angle = 0
     self.attack_angle = 0
     self.team = TeamK(self.field, self.goal, self.penalty_area,
                       self.goal_area, self.robot_size,
                       self.max_linear_velocity)
     helper.printConsole("Initializing variables...")
Example #4
0
    def init(self, info): 
        self.field = info['field']
        self.max_linear_velocity = info['max_linear_velocity']
        self.robot_size = info['robot_size'][0]
        self.goal = info['goal']
        self.penalty_area = info['penalty_area']
        self.goal_area = info['goal_area']
        self.number_of_robots = info['number_of_robots']
        self.end_of_frame = False
        self._frame = 0 
        self.speeds = [0 for _ in range(30)]
        self.cur_posture = []
        self.cur_posture_opp = []
        self.cur_ball = []
        self.previous_ball = []
        self.predicted_ball = []
        self.idx = 0
        self.idx_opp = 0
        self.previous_frame = Frame()
        self.defense_angle = 0
        self.attack_angle = 0
        self.gk_index = 0
        self.d1_index = 1
        self.d2_index = 2
        self.f1_index = 3
        self.f2_index = 4
        
        self.GK = Goalkeeper(self.field, self.goal, self.penalty_area, 
                                self.goal_area, self.robot_size,
                                self.max_linear_velocity)
        self.D1 = Defender_1(self.field, self.goal, self.penalty_area, 
                                self.goal_area, self.robot_size,
                                self.max_linear_velocity)
        self.D2 = Defender_2(self.field, self.goal, self.penalty_area, 
                                self.goal_area, self.robot_size,
                                self.max_linear_velocity)
        self.F1 = Forward_1(self.field, self.goal, self.penalty_area, 
                                self.goal_area, self.robot_size,
                                self.max_linear_velocity)
        self.F2 = Forward_2(self.field, self.goal, self.penalty_area,
                                self.goal_area, self.robot_size,
                                self.max_linear_velocity)
        

        
        helper.printConsole("Initializing variables...")
Example #5
0
    def init(self, info):
        self.field = info['field']
        self.max_linear_velocity = info['max_linear_velocity']
        self.goal = info['goal']
        self.number_of_robots = info['number_of_robots']
        self.end_of_frame = False
        self._frame = 0
        self.speeds = [0 for _ in range(20)]
        self.cur_posture = []
        self.prev_posture = []
        self.cur_posture_opp = []
        self.cur_ball = []
        self.prev_ball = []
        self.set_default_formation()

        self.previous_frame = Frame()
        self.frame_skip = 2  # number of frames to skip
        self.obs_size = 3  # state size
        self.act_size = 7  # number of discrete actions

        # for RL
        self.number_of_agents = 1  # in this example, just F2 is trained
        self.action = 0
        self.previous_action = 0
        self.state = []
        self.previous_state = []
        self.reward = 0
        self.previous_reward = 0

        # RL algorithm class
        self.trainer = DQN(self.number_of_agents, self.obs_size, self.act_size)

        # log rewards
        self.total_reward = 0
        self.rew = np.zeros(4)
        # for logging rewards
        self.t = 0
        self.episode = 1
        self.plot_reward = Logger()
        self.save_png_interval = 10
        helper.printConsole("Initializing variables...")