Location2 p1 = p0.add(delta); for(Location2 anl : agentNoOpLocs){ if(p1.equals(anl)){ p1 = p1.subtract(delta); locs.add(new Location2Prob(p1, 1.)); return locs; p1 = p1.subtract(delta); locs.add(new Location2Prob(p1, 1.)); //agent certainly cannot move locs.add(new Location2Prob(p1.subtract(delta), 1.-this.pMoveThroughSWall)); p1 = p1.subtract(delta); locs.add(new Location2Prob(p1, 1.)); //agent certainly cannot move locs.add(new Location2Prob(p1.subtract(delta), 1.-this.pMoveThroughSWall));
if(candLoc.equals(cLoc)){ collisions.add(j);
/** * Returns the attempted change in position by the agent for the given action. For instance, if the action is north, * it would result in an attempted position change of (0, +1). * @param actionName the action taken. * @return the attempted change in position for the given action. */ protected Location2 attemptedDelta(String actionName){ if(actionName.equals(GridGame.ACTION_NORTH)){ return new Location2(0, 1); } else if(actionName.equals(GridGame.ACTION_SOUTH)){ return new Location2(0, -1); } else if(actionName.equals(GridGame.ACTION_EAST)){ return new Location2(1, 0); } else if(actionName.equals(GridGame.ACTION_WEST)){ return new Location2(-1, 0); } else if(actionName.equals(GridGame.ACTION_NOOP)){ return new Location2(0, 0); } throw new RuntimeException("Error: Unknown action named '" + actionName + "' that GridGameStandardMechanics cannot handle"); }
Location2 dl = resolved.get(i); Location2 ol = originalPositions.get(i); if(!dl.equals(ol) && noops.contains(dl)){ resolved.set(i, ol); noops.add(ol);
/** * Returns a new {@link Location2} object that is the subtraction of a provided object from this object (this - o). This objects values * are not affected by this operation. * @param o the other object whose values should be subtract. * @return a new {@link Location2} object that is the subtraction of a provided object from this object (this - o). */ public Location2 subtract(Location2 o){ return new Location2(x-o.x, y-o.y); }
/** * 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; }
/** * Returns a new {@link Location2} object that is the sum of this object and the provided object. This objects values * are not affected by this operation. * @param o the other object whose values should be added. * @return a new {@link Location2} object that is the sum of this object and the provided object. */ public Location2 add(Location2 o){ return new Location2(x+o.x, y+o.y); }