public class BlockDude extends java.lang.Object implements DomainGenerator
BlockDudeLevelConstructor
and states can be visualized with the
BlockDudeVisualizer
. You can run this class' main method
to launch an interactive visualizer for the first level with keys: w, a, d, s, x for
the actions up, west, east, pickup, putdown, respectively.
State.semiDeepCopy(java.util.Set)
instead of a
State.copy()
. The semi-deep copy only copies ObjectInstance
in the previous state that will have its values modified by the action execution:
typically, the agent and a moved block are deep copied, with the un moved block objects and brick objects
shallow copied to the new state. This is much more memory efficient, but you should avoid directly modifying
any single state outside of state construction to avoid changes to other states that may be in memory that use the
same shallow copy. Instead, if you wish to directly modify states, always make a
State.copy()
first. Alternatively, you can set Actions to always make deep copies
by setting this class's useSemiDeep
parameter to false with with the setUseSemiDeep(boolean)
method.Modifier and Type | Class and Description |
---|---|
class |
BlockDude.AtExitPF
A
PropositionalFunction that takes as arguments an agent object and an exit object
and evaluates whether the agent is at the exit. |
class |
BlockDude.HoldingBlockPF
A
PropositionalFunction that takes as arguments an agent object and a block objects and evaluates whether
the agent is holding the block. |
class |
BlockDude.MoveAction
A class for performing a horizontal movement either east or west.
|
class |
BlockDude.MoveUpAction
And action class for performing an up movement action.
|
class |
BlockDude.PickupAction
An action class for performing a pickup action.
|
class |
BlockDude.PutdownAction
An action class for performing a put down action.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTIONEAST
Name for the east action
|
static java.lang.String |
ACTIONPICKUP
Name for the pickup action
|
static java.lang.String |
ACTIONPUTDOWN
Name for the put down action
|
static java.lang.String |
ACTIONUP
Name for the up action
|
static java.lang.String |
ACTIONWEST
Name for the west action
|
static java.lang.String |
ATTDIR
Direction attribute name
|
static java.lang.String |
ATTHOLD
Name for the boolean attribute that indicates whether the agent is holding a block
|
static java.lang.String |
ATTMAP
Name for the attribute that holds the brick map
|
static java.lang.String |
ATTX
X position attribute name
|
static java.lang.String |
ATTY
Y position attribute name
|
static java.lang.String |
CLASSAGENT
Name for the agent OO-MDP class
|
static java.lang.String |
CLASSBLOCK
Name for the block OO-MDP class
|
static java.lang.String |
CLASSBRICKS
Name for the bricks OO-MDP class
|
static java.lang.String |
CLASSEXIT
Name for the exit OO-MDP class
|
protected int |
maxx
Domain parameter specifying the maximum x dimension value of the world
|
protected int |
maxy
Domain parameter specifying the maximum y dimension value of the world
|
static java.lang.String |
PFATEXIT
Name for the propositional function that tests whether the agent is at an exit
|
static java.lang.String |
PFHOLDINGBLOCK
Name for the propositional function that tests whether the agent is holding a block.
|
protected boolean |
useSemiDeep
Domain parameter specifying whether actions create semi-deep copies of states or fully deep copies of states.
|
Constructor and Description |
---|
BlockDude()
Initializes a world with a maximum 25x25 dimensionality and actions that use semi-deep state copies.
|
BlockDude(int maxx,
int maxy)
Initializes a world with the maximum space dimensionality provided and actions that use semi-deep state copies.
|
Modifier and Type | Method and Description |
---|---|
Domain |
generateDomain()
Returns a newly instanced Domain object
|
protected static ObjectInstance |
getBlockAt(State s,
int x,
int y)
Finds a block object in the
State located at the provided position and returns its
ObjectInstance . |
int |
getMaxx() |
int |
getMaxy() |
static State |
getUninitializedState(Domain domain,
int nb)
Returns an uninitialized state that contains the specified number of block objects.
|
boolean |
getUseSemiDeep()
Returns whether generated domain's actions use semi-deep state copies or full deep copies..
|
static int |
greatestHeightBelow(State s,
int[] map,
int xWidth,
int x,
int maxY)
Returns the maximum height of the world at the provided x coordinate that is <= the value maxY.
|
static void |
main(java.lang.String[] args)
Runs an interactive visual explorer for level one of Block Dude.
|
protected static void |
moveCarriedBlockToNewAgentPosition(State s,
ObjectInstance agent,
int ax,
int ay,
int nx,
int ny)
Moves a carried block to a new position of the agent
|
static void |
moveHorizontally(State s,
int dx,
int maxx)
Modifies state s to be the result of a horizontal movement.
|
static void |
moveUp(State s,
int maxx)
Modifies state s to be the result of a vertical movement, that will result in the agent onto the platform adjacent
to its current location in the direction the agent is facing, provided that there is room for the agent (and any block
it's holding) to step onto it.
|
static int |
oneDMapIndex(int x,
int y,
int xWidth)
Returns the single dimensional array index for the brick map for 2D coordinates x, y.
|
static void |
pickupBlock(State s,
int maxx)
Modifies state s to be the result of the pick up action.
|
static void |
putdownBlock(State s,
int maxx)
Modifies state s to put down the block the agent is holding.
|
static void |
setAgent(State s,
int x,
int y,
int dir,
boolean holding)
Sets the agent object's x, y, direction, and holding attribute to the specified values.
|
static void |
setBlock(State s,
int i,
int x,
int y)
Sets the ith block's x and y position in a state.
|
static void |
setBrickMap(State s,
int[][] map)
Sets the state to use the provided brick map.
|
static void |
setBrickValue(State s,
int x,
int y,
int v)
Sets the brick value in grid location x, y.
|
static void |
setExit(State s,
int x,
int y)
Sets the x and y position of the first exit object in the state.
|
void |
setMaxx(int maxx) |
void |
setMaxy(int maxy) |
void |
setUseSemiDeep(boolean useSemiDeep)
Sets whether generated domain's actions use semi-deep state copies or full deep copies.
|
public static final java.lang.String ATTX
public static final java.lang.String ATTY
public static final java.lang.String ATTDIR
public static final java.lang.String ATTHOLD
public static final java.lang.String ATTMAP
public static final java.lang.String CLASSAGENT
public static final java.lang.String CLASSBLOCK
public static final java.lang.String CLASSBRICKS
public static final java.lang.String CLASSEXIT
public static final java.lang.String ACTIONUP
public static final java.lang.String ACTIONEAST
public static final java.lang.String ACTIONWEST
public static final java.lang.String ACTIONPICKUP
public static final java.lang.String ACTIONPUTDOWN
public static final java.lang.String PFHOLDINGBLOCK
public static final java.lang.String PFATEXIT
protected int maxx
protected int maxy
protected boolean useSemiDeep
ObjectInstance
between
states that have their values change from the action execution
(typically the agent or a specifically moved block). If false,
then the states are completely deep copied by action execution.public BlockDude()
public BlockDude(int maxx, int maxy)
maxx
- maxy
- public Domain generateDomain()
DomainGenerator
generateDomain
in interface DomainGenerator
public boolean getUseSemiDeep()
public void setUseSemiDeep(boolean useSemiDeep)
useSemiDeep
- if true, then use semi-deep; if false use full deep.public int getMaxx()
public void setMaxx(int maxx)
public int getMaxy()
public void setMaxy(int maxy)
public static State getUninitializedState(Domain domain, int nb)
setAgent(burlap.oomdp.core.State, int, int, int, boolean)
,
setExit(burlap.oomdp.core.State, int, int)
, setBlock(burlap.oomdp.core.State, int, int, int)
,
and setBrickMap(burlap.oomdp.core.State, int[][])
or
setBrickValue(burlap.oomdp.core.State, int, int, int)
. If you want pre-generated states,
see the BlockDudeLevelConstructor
domain
- the generated Block Dude domain to which the state will belongnb
- the number of blocks to include in the stateState
with 1 agent object, 1 exit object, 1 bricks object and nb block objects.public static void setAgent(State s, int x, int y, int dir, boolean holding)
s
- the state whose agent object should be modifiedx
- the x position of the agenty
- the y position of the agentdir
- the direction the agent is facingholding
- whether the agent is holding a block or notpublic static void setExit(State s, int x, int y)
s
- the state to modifyx
- the x position of the exity
- the y position of the exitpublic static void setBlock(State s, int i, int x, int y)
s
- the state to modifyi
- which block ot modifyx
- the x position of the blocky
- the y position of the blockpublic static void setBrickValue(State s, int x, int y, int v)
s
- the state to modifyx
- the x position of the brick value to sety
- the y position of the brick value to setv
- if 1, then a brick will be at position x,y; if false then no brick will be present.public static void setBrickMap(State s, int[][] map)
s
- the state to modifymap
- the brick map to set.public static int oneDMapIndex(int x, int y, int xWidth)
x
- the x coordinatey
- the y coordinatexWidth
- the maximum x dimensionality of the world.public static void moveHorizontally(State s, int dx, int maxx)
s
- the state to modifydx
- the change in x direction; should only be +1 (east) or -1 (west).maxx
- the maximum x dimensionality of the worldpublic static void moveUp(State s, int maxx)
s
- the state to modify.maxx
- the maximum x dimensionality of the worldpublic static void pickupBlock(State s, int maxx)
s
- the state to modify.maxx
- the maximum x dimensionality of the worldpublic static void putdownBlock(State s, int maxx)
s
- the state to modifymaxx
- the maximum x dimensionality of the worldprotected static void moveCarriedBlockToNewAgentPosition(State s, ObjectInstance agent, int ax, int ay, int nx, int ny)
s
- the state to modifyagent
- the agent ObjectInstance
ax
- the previous x position of the agentay
- the previous y position of the agentnx
- the new x position of the *agent*ny
- the new y position of the *agent*protected static ObjectInstance getBlockAt(State s, int x, int y)
State
located at the provided position and returns its
ObjectInstance
. If not block at the location exists, then null is returned.s
- the state to checkx
- the x positiony
- the y positionObjectInstance
for the corresponding block object in the state at the given position or null if one does not exist.public static int greatestHeightBelow(State s, int[] map, int xWidth, int x, int maxY)
s
- the state to searchmap
- the brick mapxWidth
- the maximum x dimensionality of the worldx
- the x position to searchmaxY
- the y position under which the highest point is searchedpublic static void main(java.lang.String[] args)
args
- can be empty.