/** * Indicates whether there are any wall collisions. * @param p0 the original location * @param delta the desired change in direction * @param walls possible wall objects * @param vertical true if the wall objects are vertical; false if they are horizontal * @return 0 if there is no collision with a wall, 1 if there is a collision with a solid wall, 2 if there is a potential collision with a semi-wall */ protected int wallCollision(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 1; } else if(wt == 1){ //stochastic wall return 2; } } } return 0; }
/** * 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; }