Java Code Examples for burlap.mdp.core.oo.state.ObjectInstance#get()
The following examples show how to use
burlap.mdp.core.oo.state.ObjectInstance#get() .
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: GridWorldVisualizer.java From burlap with Apache License 2.0 | 6 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { //set the color of the object g2.setColor(this.col); float domainXScale = this.dwidth; float domainYScale = this.dheight; //determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; float rx = (Integer)ob.get(VAR_X)*width; float ry = cHeight - height - (Integer)ob.get(VAR_Y)*height; if(this.shape == 0){ g2.fill(new Rectangle2D.Float(rx, ry, width, height)); } else{ g2.fill(new Ellipse2D.Float(rx, ry, width, height)); } }
Example 2
Source File: GridGameStandardMechanics.java From burlap with Apache License 2.0 | 6 votes |
/** * Returns true if the agent objects between these two states are equal * @param s1 the first state * @param s2 the second state * @return true if the agent objects between these two states are equal */ protected boolean agentsEqual(OOState s1, OOState s2){ List<ObjectInstance> agents1 = s1.objectsOfClass(GridGame.CLASS_AGENT); for(ObjectInstance a1 : agents1){ ObjectInstance a2 = s2.object(a1.name()); int x1 = (Integer)a1.get(GridGame.VAR_X); int x2 = (Integer)a2.get(GridGame.VAR_X); int y1 = (Integer)a1.get(GridGame.VAR_Y); int y2 = (Integer)a2.get(GridGame.VAR_Y); if(x1 != x2 || y1 != y2){ return false; } } return true; }
Example 3
Source File: GridWorldDomain.java From burlap with Apache License 2.0 | 6 votes |
@Override public boolean isTrue(OOState st, String... params) { ObjectInstance agent = st.object(params[0]); ObjectInstance location = st.object(params[1]); int ax = (Integer)agent.get("x"); int ay = (Integer)agent.get("y"); int lx = (Integer)location.get("x"); int ly = (Integer)location.get("y"); if(ax == lx && ay == ly){ return true; } return false; }
Example 4
Source File: FrostbiteVisualizer.java From burlap with Apache License 2.0 | 6 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { int x = (Integer)ob.get(FrostbiteDomain.VAR_X); int y = (Integer)ob.get(FrostbiteDomain.VAR_Y); int size = (Integer)ob.get(FrostbiteDomain.VAR_SIZE); boolean activated = (Boolean)ob.get(FrostbiteDomain.VAR_ACTIVATED); if (activated) g2.setColor(activatedPlatformColor); else g2.setColor(Color.white); g2.fill(new Rectangle2D.Double(x, y, size, size)); if (x + size > gameWidth) g2.fill(new Rectangle2D.Double(x - gameWidth, y, size, size)); else if (x < 0) g2.fill(new Rectangle2D.Double(x + gameWidth, y, size, size)); }
Example 5
Source File: GridGameStandardMechanics.java From burlap with Apache License 2.0 | 6 votes |
/** * Return true if the agent is able to move in the desired location; false if the agent moves into a solid wall * or if the agent randomly fails to move through a semi-wall that is in the way. * @param p0 the initial location of the agent * @param delta the desired change in direction of the agent * @param walls the list of walls in the world * @param vertical whether the list of provided walls are vertical or horizontal walls * @return true if the agent is able to move in the desired location; false otherwise */ protected boolean sampleWallCollision(Location2 p0, Location2 delta, List <ObjectInstance> walls, boolean vertical){ for(int i = 0; i < walls.size(); i++){ ObjectInstance w = walls.get(i); if(this.crossesWall(p0, delta, w, vertical)){ int wt = (Integer)w.get(GridGame.VAR_WT); if(wt == 0){ //solid wall return true; } else if(wt == 1){ //stochastic wall double roll = rand.nextDouble(); if(roll > pMoveThroughSWall){ return true; } } } } return false; }
Example 6
Source File: GridWorldVisualizer.java From burlap with Apache License 2.0 | 5 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { int type = (Integer)ob.get(VAR_TYPE); int multiplier = type / this.baseColors.size(); int colIndex = type % this.baseColors.size(); Color col = this.baseColors.get(colIndex); for(int i = 0; i < multiplier; i++){ col = col.darker(); } //set the color of the object g2.setColor(col); float domainXScale = this.dwidth; float domainYScale = this.dheight; //determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; float rx = (Integer)ob.get(VAR_X)*width; float ry = cHeight - height - (Integer)ob.get(VAR_Y)*height; g2.fill(new Rectangle2D.Float(rx, ry, width, height)); }
Example 7
Source File: GridWorldDQN.java From burlap_caffe with Apache License 2.0 | 5 votes |
@Override public void vectorizeState(State state, FloatPointer input) { GridWorldState gwState = (GridWorldState) state; int width = gwdg.getWidth(); input.fill(0); ObjectInstance agent = gwState.object(GridWorldDomain.CLASS_AGENT); int x = (Integer)agent.get(GridWorldDomain.VAR_X); int y = (Integer)agent.get(GridWorldDomain.VAR_Y); input.put((long)(y*width + x), 1); }
Example 8
Source File: FrostbiteVisualizer.java From burlap with Apache License 2.0 | 5 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { g2.setColor(iglooColor); int building = (Integer)ob.get(FrostbiteDomain.VAR_BUILDING); int layer = -1; // just because ;) int maxLayer = 16; int brickHeight = gameHeight / (5 * maxLayer); int iglooWidth = gameWidth / 6; int iglooOffsetx = 0; int iglooOffsety = 0; for (; layer < Math.min(maxLayer, building) - 1; layer++) { if (layer == maxLayer / 3) { brickHeight /= 2; iglooOffsety = -(layer - 1) * brickHeight; } if (layer >= maxLayer / 3) { iglooWidth -= gameWidth / (4 * maxLayer); iglooOffsetx += gameWidth / (8 * maxLayer); } g2.fill(new Rectangle2D.Double(iglooOffsetx + 3 * gameWidth / 4, iglooOffsety + gameHeight / 5 - brickHeight * layer, iglooWidth, brickHeight)); } if (building >= maxLayer) { g2.setColor(Color.black); int doorWidth = gameWidth / 28; int doorHeight = gameHeight / 20; g2.fill(new Rectangle2D.Double(3 * gameWidth / 4 + gameWidth / 12 - doorWidth / 2, gameHeight / 5 - doorHeight/2, doorWidth, doorHeight)); } }
Example 9
Source File: GridGameStandardMechanics.java From burlap with Apache License 2.0 | 5 votes |
/** * Returns the x-y position of an agent stored in a Location2 object. * @param s the state in which the agent exists * @param agentName the name of the agent. * @return a {@link GridGameStandardMechanics.Location2} object containing the agents position in the world. */ protected Location2 getLocation(OOState s, String agentName){ ObjectInstance a = s.object(agentName); Location2 loc = new Location2((Integer)a.get(GridGame.VAR_X), (Integer)a.get(GridGame.VAR_Y)); return loc; }
Example 10
Source File: GGVisualizer.java From burlap with Apache License 2.0 | 5 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { int colInd = 0; if(ob.className().equals(GridGame.CLASS_AGENT)){ colInd = (Integer)ob.get(GridGame.VAR_PN); } else if(ob.className().equals(GridGame.CLASS_GOAL)){ colInd = (Integer)ob.get(GridGame.VAR_GT); } g2.setColor(this.cols.get(colInd)); float domainXScale = maxX; float domainYScale = maxY; //determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; float rx = (Integer)ob.get(GridGame.VAR_X)*width; float ry = cHeight - height - (Integer)ob.get(GridGame.VAR_Y)*height; if(shape == 0){ g2.fill(new Rectangle2D.Float(rx, ry, width, height)); } else if(shape == 1){ g2.fill(new Ellipse2D.Float(rx, ry, width, height)); } }
Example 11
Source File: ExampleOOGridWorld.java From burlap_examples with MIT License | 5 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { //agent will be filled in blue g2.setColor(Color.BLUE); //set up floats for the width and height of our domain float fWidth = ExampleOOGridWorld.this.map.length; float fHeight = ExampleOOGridWorld.this.map[0].length; //determine the width of a single cell on our canvas //such that the whole map can be painted float width = cWidth / fWidth; float height = cHeight / fHeight; int ax = (Integer)ob.get(VAR_X); int ay = (Integer)ob.get(VAR_Y); //left coordinate of cell on our canvas float rx = ax*width; //top coordinate of cell on our canvas //coordinate system adjustment because the java canvas //origin is in the top left instead of the bottom right float ry = cHeight - height - ay*height; //paint the rectangle g2.fill(new Rectangle2D.Float(rx, ry, width, height)); }
Example 12
Source File: ExampleOOGridWorld.java From burlap_examples with MIT License | 5 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { //agent will be filled in gray g2.setColor(Color.GRAY); //set up floats for the width and height of our domain float fWidth = ExampleOOGridWorld.this.map.length; float fHeight = ExampleOOGridWorld.this.map[0].length; //determine the width of a single cell on our canvas //such that the whole map can be painted float width = cWidth / fWidth; float height = cHeight / fHeight; int ax = (Integer)ob.get(VAR_X); int ay = (Integer)ob.get(VAR_Y); //left coordinate of cell on our canvas float rx = ax*width; //top coordinate of cell on our canvas //coordinate system adjustment because the java canvas //origin is in the top left instead of the bottom right float ry = cHeight - height - ay*height; //paint the rectangle g2.fill(new Ellipse2D.Float(rx, ry, width, height)); }
Example 13
Source File: ExampleOOGridWorld.java From burlap_examples with MIT License | 5 votes |
@Override public boolean isTrue(OOState s, String... params) { ObjectInstance agent = s.object(params[0]); ObjectInstance location = s.object(params[1]); int ax = (Integer)agent.get(VAR_X); int ay = (Integer)agent.get(VAR_Y); int lx = (Integer)location.get(VAR_X); int ly = (Integer)location.get(VAR_Y); return ax == lx && ay == ly; }
Example 14
Source File: GGVisualizer.java From burlap with Apache License 2.0 | 4 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { int p0x, p0y, p1x, p1y; int wp = (Integer)ob.get(GridGame.VAR_POS); int e1 = (Integer)ob.get(GridGame.VAR_E1); int e2 = (Integer)ob.get(GridGame.VAR_E2); if(vertical){ p0x = p1x = wp; p0y = e1; p1y = e2+1; } else{ p0y = p1y = wp; p0x = e1; p1x = e2+1; } float nx0 = (float)p0x / (float)maxX; float ny0 = 1.f - ((float)p0y / (float)maxY); float nx1 = (float)p1x / (float)maxX; float ny1 = 1.f - ((float)p1y / (float)maxY); g2.setColor(Color.black); int wt = (Integer)ob.get(GridGame.VAR_WT); if(wt == 0){ g2.setStroke(new BasicStroke(10)); } else if(wt == 1){ g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {(cWidth/maxX)/5.f}, 0)); } g2.drawLine((int)(nx0*cWidth), (int)(ny0*cHeight), (int)(nx1*cWidth), (int)(ny1*cHeight)); }
Example 15
Source File: BlockDudeVisualizer.java From burlap with Apache License 2.0 | 4 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { g2.setColor(Color.gray); float domainXScale = (maxx) - minx; float domainYScale = (maxy) - miny; //determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; float rx = (Integer)ob.get(BlockDude.VAR_X)*width; float ry = cHeight - height - (Integer)ob.get(BlockDude.VAR_Y)*height; g2.fill(new Rectangle2D.Float(rx, ry, width, height)); }
Example 16
Source File: BlockDudeVisualizer.java From burlap with Apache License 2.0 | 4 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { g2.setColor(Color.black); float domainXScale = (maxx) - minx; float domainYScale = (maxy) - miny; //determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; float rx = (Integer)ob.get(BlockDude.VAR_X)*width; float ry = cHeight - height - (Integer)ob.get(BlockDude.VAR_Y)*height; g2.fill(new Rectangle2D.Float(rx, ry, width, height)); }
Example 17
Source File: LLVisualizer.java From burlap with Apache License 2.0 | 3 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { g2.setColor(Color.blue); double ol = (Double)ob.get(LunarLanderDomain.VAR_LEFT); double or = (Double)ob.get(LunarLanderDomain.VAR_RIGHT); double obb = (Double)ob.get(LunarLanderDomain.VAR_BOTTOM); double ot = (Double)ob.get(LunarLanderDomain.VAR_TOP); double ow = or - ol; double oh = ot - obb; double xr = lld.getXmax() - lld.getXmin(); double yr = lld.getYmax() - lld.getYmin(); double nl = (ol - lld.getXmin()) / xr; double nt = (ot - lld.getYmin()) / yr; double nw = ow/xr; double nh = oh/yr; double sx = nl*cWidth; double sy = cHeight - (nt*cHeight); double sw = nw*cWidth; double sh = nh*cHeight; g2.fill(new Rectangle2D.Double(sx, sy, sw, sh)); }
Example 18
Source File: GridGame.java From burlap with Apache License 2.0 | 3 votes |
@Override public boolean isTrue(OOState s, String... params) { ObjectInstance agent = s.object(params[0]); int ax = (Integer)agent.get(VAR_X); int ay = (Integer)agent.get(VAR_Y); //find all universal goals List <ObjectInstance> goals = s.objectsOfClass(CLASS_GOAL); for(ObjectInstance goal : goals){ int gt = (Integer)goal.get(VAR_GT); if(gt == 0){ int gx = (Integer)goal.get(VAR_X); int gy = (Integer)goal.get(VAR_Y); if(gx == ax && gy == ay){ return true; } } } return false; }
Example 19
Source File: LLVisualizer.java From burlap with Apache License 2.0 | 3 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { g2.setColor(Color.black); double ol = (Double)ob.get(LunarLanderDomain.VAR_LEFT); double or = (Double)ob.get(LunarLanderDomain.VAR_RIGHT); double obb = (Double)ob.get(LunarLanderDomain.VAR_BOTTOM); double ot = (Double)ob.get(LunarLanderDomain.VAR_TOP); double ow = or - ol; double oh = ot - obb; double xr = lld.getXmax() - lld.getXmin(); double yr = lld.getYmax() - lld.getYmin(); double nl = (ol - lld.getXmin()) / xr; double nt = (ot - lld.getYmin()) / yr; double nw = ow/xr; double nh = oh/yr; double sx = nl*cWidth; double sy = cHeight - (nt*cHeight); double sw = nw*cWidth; double sh = nh*cHeight; g2.fill(new Rectangle2D.Double(sx, sy, sw, sh)); }
Example 20
Source File: BlockDudeVisualizer.java From burlap with Apache License 2.0 | 3 votes |
@Override public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) { g2.setColor(Color.blue); float domainXScale = (maxx) - minx; float domainYScale = (maxy) - miny; //determine then normalized width float width = (1.0f / domainXScale) * cWidth; float height = (1.0f / domainYScale) * cHeight; float rx = (Integer)ob.get(BlockDude.VAR_X)*width; float ry = cHeight - height - (Integer)ob.get(BlockDude.VAR_Y)*height; g2.fill(new Rectangle2D.Float(rx, ry, width, height)); //draw eye for showing the direction of the agent g2.setColor(Color.orange); float eyeWidth = width*0.25f; float eyeHeight = height*0.25f; float ex = rx; if((Integer)ob.get(BlockDude.VAR_DIR) == 1){ ex = (rx+width) - eyeWidth; } float ey = ry + 0.2f*height; g2.fill(new Rectangle2D.Float(ex, ey, eyeWidth, eyeHeight)); }