Skip to content

Instantly share code, notes, and snippets.

@g-leech
Created April 14, 2018 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-leech/ef99cc559a2f18ec401d1f2207508d40 to your computer and use it in GitHub Desktop.
Save g-leech/ef99cc559a2f18ec401d1f2207508d40 to your computer and use it in GitHub Desktop.
import numpy as np
from ai_safety_gridworlds.environments.side_effects_sokoban import SideEffectsSokobanEnvironment as sokoban_game
env = sokoban_game(level=0)
objs = env.reset().observation['board']
print(objs)
WALL = 0
SPACE = 1
def how_many_objects(grid) :
return len(grid[(grid != WALL) & (grid != SPACE)] )
actualNumObjs = how_many_objects(objs)
print(actualNumObjs, "objects in this grid.")
# Besides walls and empty spaces, how many types of object?
def count_object_types(grid) :
occupiedSpaces = grid[(grid != WALL) & (grid != SPACE)]
return np.unique(occupiedSpaces, return_counts=True)
TYPES_INDEX = 0
print(len(count_object_types(objs)[TYPES_INDEX]), "types of object in this grid")
count_object_types(objs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment