Java Code Examples for burlap.mdp.core.oo.state.generic.GenericOOState#touch()
The following examples show how to use
burlap.mdp.core.oo.state.generic.GenericOOState#touch() .
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: MinecraftModel.java From burlapcraft with GNU Lesser General Public License v3.0 | 6 votes |
protected void simMove(GenericOOState gs){ //get agent and current position BCAgent agent = (BCAgent)gs.touch(CLASS_AGENT); //get objects and their positions List<ObjectInstance> blocks = gs.objectsOfClass(HelperNameSpace.CLASS_BLOCK); List<HelperPos> coords = new ArrayList<HelperPos>(); for (ObjectInstance block : blocks) { int blockX = ((BCBlock)block).x; int blockY = ((BCBlock)block).y; int blockZ = ((BCBlock)block).z; coords.add(new HelperPos(blockX, blockY, blockZ)); } //get resulting position int [][][] map = ((BCMap)gs.object(CLASS_MAP)).map; HelperPos newPos = this.moveResult(agent.x, agent.y, agent.z, agent.rdir, coords, map); //set the new position agent.x = newPos.x; agent.y = newPos.y; agent.z = newPos.z; }
Example 2
Source File: ExampleOOGridWorld.java From burlap_examples with MIT License | 5 votes |
public State sample(State s, Action a) { s = s.copy(); GenericOOState gs = (GenericOOState)s; ExGridAgent agent = (ExGridAgent)gs.touch(CLASS_AGENT); int curX = agent.x; int curY = agent.y; int adir = actionDir(a); //sample direction with random roll double r = Math.random(); double sumProb = 0.; int dir = 0; for(int i = 0; i < 4; i++){ sumProb += this.transitionProbs[adir][i]; if(r < sumProb){ dir = i; break; //found direction } } //get resulting position int [] newPos = this.moveResult(curX, curY, dir); //set the new position agent.x = newPos[0]; agent.y = newPos[1]; //return the state we just modified return gs; }
Example 3
Source File: MinecraftModel.java From burlapcraft with GNU Lesser General Public License v3.0 | 5 votes |
protected void simRotate(GenericOOState gs, int direction){ //get agent and current position BCAgent agent = (BCAgent)gs.touch(CLASS_AGENT); int rotDir = (direction + agent.rdir) % 4; //set the new rotation direction agent.rdir = rotDir; }
Example 4
Source File: MinecraftModel.java From burlapcraft with GNU Lesser General Public License v3.0 | 5 votes |
protected void simChangeItem(GenericOOState gs){ //get agent BCAgent agent = (BCAgent)gs.touch(CLASS_AGENT); int curItem = agent.selected; int nextItem = curItem >= 0 && curItem < 9 ? (curItem+1) % 9 : 0; agent.selected = nextItem; }
Example 5
Source File: MinecraftModel.java From burlapcraft with GNU Lesser General Public License v3.0 | 5 votes |
protected State destroyResult(int curX, int curY, int curZ, int rotDir, List<BCBlock> blocks, GenericOOState s) { //System.out.println("Destroying at: " + curX + "," + curY + "," + curZ); // go through blocks and see if any of them can be mined for (BCBlock block : blocks) { if (((block.x == curX) && (block.z == curZ + 1) && (block.y == curY) && (rotDir == 0)) || ((block.x == curX) && (block.z == curZ - 1) && (block.y == curY) && (rotDir == 2)) || ((block.x == curX + 1) && (block.z == curZ) && (block.y == curY) && (rotDir == 3)) || ((block.x == curX - 1) && (block.z == curZ) && (block.y == curY) && (rotDir == 1))) { // get id of the block int blockID = block.type; boolean present = false; BCInventory inv = (BCInventory)s.touch(CLASS_INVENTORY); int invInd = inv.indexOfType(blockID); if(invInd == -1){ invInd = inv.firstFree(); } if(invInd == -1){ return s; //no free slots! } BCInventory.BCIStack [] stack = inv.touch(); stack[invInd].type = blockID; stack[invInd].inc(); s.removeObject(block.name()); break; } } return s; }
Example 6
Source File: MinecraftModel.java From burlapcraft with GNU Lesser General Public License v3.0 | 3 votes |
protected void simPitch(GenericOOState gs, int vertDirection){ //get agent and current position BCAgent agent = (BCAgent)gs.touch(CLASS_AGENT); //set agent's vert dir agent.vdir = vertDirection; }