Java Code Examples for burlap.domain.singleagent.gridworld.state.GridWorldState#touchAgent()
The following examples show how to use
burlap.domain.singleagent.gridworld.state.GridWorldState#touchAgent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridWorldDomain.java From burlap with Apache License 2.0 | 6 votes |
/** * Attempts to move the agent into the given position, taking into account walls and blocks * @param s the current state * @param xd the attempted new X position of the agent * @param yd the attempted new Y position of the agent * @return input state s, after modification */ protected State move(State s, int xd, int yd){ GridWorldState gws = (GridWorldState)s; int ax = gws.agent.x; int ay = gws.agent.y; int nx = ax+xd; int ny = ay+yd; //hit wall, so do not change position if(nx < 0 || nx >= map.length || ny < 0 || ny >= map[0].length || map[nx][ny] == 1 || (xd > 0 && (map[ax][ay] == 3 || map[ax][ay] == 4)) || (xd < 0 && (map[nx][ny] == 3 || map[nx][ny] == 4)) || (yd > 0 && (map[ax][ay] == 2 || map[ax][ay] == 4)) || (yd < 0 && (map[nx][ny] == 2 || map[nx][ny] == 4)) ){ nx = ax; ny = ay; } GridAgent nagent = gws.touchAgent(); nagent.x = nx; nagent.y = ny; return s; }
Example 2
Source File: TestHashing.java From burlap with Apache License 2.0 | 5 votes |
public Set<HashableState> generateStates(SADomain domain, State state, HashableStateFactory factory, int width) { Set<HashableState> hashedStates = new HashSet<HashableState>(); for (int i = 0; i < width; ++i) { for (int j =0 ; j < width; ++j) { GridWorldState copy = (GridWorldState)state.copy(); copy.touchAgent().x = i; copy.agent.y = j; hashedStates.add(factory.hashState(copy)); } } return hashedStates; }
Example 3
Source File: TestHashing.java From burlap with Apache License 2.0 | 5 votes |
public Set<HashableState> generateRandomStates(SADomain domain, State state, HashableStateFactory factory, int width, int numStates, boolean moveLocations) { Set<HashableState> hashedStates = new HashSet<HashableState>(); Random random = new Random(); int misses = 0; int prevSize = 0; while (hashedStates.size() < numStates) { if (hashedStates.size() == prevSize) { misses++; } if (misses > 100) { break; } prevSize = hashedStates.size(); if (prevSize > 0 && prevSize % 10000 == 0) { System.out.println("\t" + prevSize); } GridWorldState copy = (GridWorldState)state.copy(); copy.touchAgent().x = random.nextInt(width); copy.agent.y = random.nextInt(width); if (moveLocations) { List<GridLocation> locations = copy.deepTouchLocations(); for(GridLocation loc : locations){ loc.x = random.nextInt(width); loc.y = random.nextInt(width); } } hashedStates.add(factory.hashState(copy)); } return hashedStates; }
Example 4
Source File: IRLExample.java From burlap_examples with MIT License | 3 votes |
public State generateState() { GridWorldState s = (GridWorldState)this.sourceState.copy(); int h = RandomFactory.getDefault().nextInt(this.height); s.touchAgent().y = h; return s; }