Beispiel #1
0
def agent():
    env = RemoteEnv(IN_PORT=8080, OUT_PORT=7070)
    env.open(0)
    for i in range(10000000):
        sum_energy = 0
        state = env.step("restart")
        prev_energy = state['energy']
        print(prev_energy)
        done = state['done']
        while not done:
            frame = image_decode(state['frame'], 20, 20)
            print(frame)
            action = int(input('action'))
            for i in range(8):
                state = env.step("act", action)
            state = env.step('get_status')
            done = state["done"]
            energy = state['energy']
            frame = state['frame']
            touched = state['touched']
            ID = state['id']
            delta = (energy - prev_energy)
            print(delta)
            sum_energy += delta
            prev_energy = energy
        print(sum_energy)
    env.close()
Beispiel #2
0
    def step(self, action, value=None):
        state = None
        for i in range(8):
            state = super().step(action, value)
            if state['done']:
                break

        imgdata = image_decode(state['frame'], 20, 20)

        self.buf.append(imgdata)
        state['frame'] = np.array(self.buf, dtype=np.float32)
        state['frame'] = np.moveaxis(state['frame'], 0, -1)
        state['frame'] = state['frame'].reshape(1, 20, 20, 4)
        self.proprioceptions[0] = state['touched']
        self.proprioceptions[1] = state['energy']
        state['proprioception'] = np.array(self.proprioceptions,
                                           np.float32).reshape(
                                               1, len(self.proprioceptions))
        return state
Beispiel #3
0
def agent():
    env = RemoteEnv(IN_PORT=8085, OUT_PORT=7075)
    env.open(0)
    for i in range(10000000):
        state = env.step("restart")
        prev_energy = state['energy']
        done = state['done']
        while not done:
            action = int(input('action'))
            #action = np.random.choice([0, 1])
            reward_sum = 0
            touched = -1
            for i in range(8):
                state = env.step("act", action)
                state = env.step('get_status')
                energy = state['energy']
                if touched == -1:
                    touched = state['touched']
                elif not state['touched'] in [0, 1]:
                    touched = state['touched']
                if state['done']:
                    break
            done = state['done']
            reward_sum += (energy - prev_energy)
            prev_energy = energy
            frame = state['frame']
            ID = state['id']
            frame = image_decode(state['frame'], 20, 20)
            print(frame)
            print(reward_sum)
            print(touched)
            print(state['signal'])
            print(state['done'])
            prev_energy = energy
        if i >= 2:
            break
    env.close()
Beispiel #4
0
def get_frame_from_fields(fields):
    imgdata = image_decode(fields['frame'], 20, 20)
    return imgdata
Beispiel #5
0
 def step(self, action):
     obs, reward, done, info = self.env.step(action)
     return image_decode(obs), reward, done, info
Beispiel #6
0
 def reset(self):
     state = self.env.reset()
     self.state = image_decode(state)