Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'continuous' action space env.reset() does not reset player position #20

Open
m0re4u opened this issue Dec 20, 2021 · 1 comment
Open
Assignees

Comments

@m0re4u
Copy link
Contributor

m0re4u commented Dec 20, 2021

Hi @artemZholus,

Resetting the player position does not seem to work when starting the environment with the action space set to continuous.

Here's a MWE:

import gym
import iglu
from PIL import Image
from collections import OrderedDict
import numpy as np
import time


env = gym.make("IGLUSilentBuilder-v0", action_space='continuous')
env.observation_space
obs = env.reset()

noop_action = OrderedDict([('move_x', np.array(0)), ('move_y', np.array(0)), ('move_z', np.array(0)), ('camera', np.array([0, 0], dtype=np.float32)), ('hotbar', np.array(1)), ('attack', np.array(0)), ('use', np.array(0))])
start_fly = OrderedDict([('move_x', np.array(0)), ('move_y', np.array(1)), ('move_z', np.array(0)), ('camera', np.array([0, 0], dtype=np.float32)), ('hotbar', np.array(1)), ('attack', np.array(0)), ('use', np.array(0))])
look_down = OrderedDict([('move_x', np.array(0)), ('move_y', np.array(0)), ('move_z', np.array(0)), ('camera', np.array([90, 0], dtype=np.float32)), ('hotbar', np.array(1)), ('attack', np.array(0)), ('use', np.array(0))])
look_up = OrderedDict([('move_x', np.array(0)), ('move_y', np.array(0)), ('move_z', np.array(0)), ('camera', np.array([0, 0], dtype=np.float32)), ('hotbar', np.array(1)), ('attack', np.array(0)), ('use', np.array(0))])
place_block_1 = OrderedDict([('move_x', np.array(0)), ('move_y', np.array(0)), ('move_z', np.array(0)), ('camera', np.array([0, 0], dtype=np.float32)), ('hotbar', np.array(1)), ('attack', np.array(0)), ('use', np.array(1))])

def make_action(action, wait=False):
    obs, _, _, _ = env.step(action)
    im = Image.fromarray(
            obs["pov"],
        ).resize((256, 256))
    im.save(f"output_{time.time():10.8f}.png")

    if wait:
        for _ in range(4):
            make_action(noop_action, wait=False)

make_action(noop_action, wait=True)
make_action(look_down)
make_action(start_fly, wait=True)
make_action(start_fly, wait=True)
make_action(place_block_1)
make_action(start_fly, wait=True)
make_action(start_fly, wait=True)


env.reset()
make_action(noop_action, wait=True)
make_action(look_down, wait=True)  # we're still flying

output_1640023971 97719121
output_1640023972 14017224
output_1640023972 55107307
output_1640023972 84333348
output_1640023973 22247696
output_1640023973 40249443

If you look at the final output image, you can see the agent is still floating in mid-air, but the block is gone. Also when the environment is reset, the camera is reset to (0,0). It seems to be a problem in the movement command?

I checked the communication with Malmo, it also seems to generate the fake reset command for FakeResetCommandImplementation properly, perhaps the x,y,z in player.setPositionAndRotation(x, y, z, yaw, pitch); are not set correctly (see CODE) ?

This is where I lost track..

@artemZholus artemZholus self-assigned this Dec 27, 2021
@artemZholus
Copy link
Collaborator

Sorry for the long reply. The problem is known and the solution is simple. In Minecraft, there are two instances of the player, on the client side and on the server side. The problem is that we do not update the server side when we should. I'll fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants