def test_pickup_mechanics_swap(): grid = Grid(height=3, width=4) agent = Agent(position=(1, 2), orientation=Orientation.S) item_pos = (2, 2) agent.obj = Key(Color.BLUE) grid[item_pos] = Key(Color.GREEN) state = State(grid, agent) next_state = step_with_copy(state, Action.PICK_N_DROP) assert state.grid[item_pos] == next_state.agent.obj assert state.agent.obj == next_state.grid[item_pos]
def test_pickup_mechanics_drop(): grid = Grid(height=3, width=4) agent = Agent(position=(1, 2), orientation=Orientation.S) item_pos = (2, 2) agent.obj = Key(Color.BLUE) state = State(grid, agent) # Can drop: next_state = step_with_copy(state, Action.PICK_N_DROP) assert isinstance(next_state.agent.obj, NoneGridObject) assert agent.obj == next_state.grid[item_pos] # Cannot drop: state.grid[item_pos] = Wall() next_state = step_with_copy(state, Action.PICK_N_DROP) assert isinstance(next_state.grid[item_pos], Wall) assert agent.obj == next_state.agent.obj