/** * 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; }
/** * Takes a list of possible location outcomes for each agent and generates all joint location outcomes * @param locOutcomes a list of possible location outcomes * @return all joint location outcomes */ protected List<LocationSetProb> getAllLocationSets(List<List<Location2Prob>> locOutcomes){ List <LocationSetProb> sets = new ArrayList<GridGameStandardMechanics.LocationSetProb>(); Location2 [] locArray = new Location2[locOutcomes.size()]; generateAllLocationSetsHelper(locOutcomes, 0, locArray, 1., sets); return sets; }
protected void generateAllPossibleCollisionWinnerAssignments(List <List<Integer>> collisionLists, int i, int [] assignment, List <List<Integer>> discovered){ if(i == collisionLists.size()){ //package it up List <Integer> assignmentList = new ArrayList<Integer>(assignment.length); for(int a : assignment){ assignmentList.add(a); } discovered.add(assignmentList); return ; } //otherwise we're in recursive step List<Integer> possibleWinners = collisionLists.get(i); for(int w : possibleWinners){ assignment[i] = w; this.generateAllPossibleCollisionWinnerAssignments(collisionLists, i+1, assignment, discovered); } }
Location2 loc = this.getLocation((OOState)s, this.agentName(pn, (OOState)s)); previousLocations.add(loc); if(gsa.actionName().equals(GridGame.ACTION_NOOP)){ Location2 loc = previousLocations.get(i); Action gsa = ja.action(i); possibleOutcomes.add(this.getPossibleLocationsFromWallCollisions((OOState)s, loc, this.attemptedDelta(gsa.actionName()), noopLocations)); List <LocationSetProb> outcomeSets = this.getAllLocationSets(possibleOutcomes); List <Location2> basicMoveResults = this.resolvePositionSwaps(previousLocations, sp.locs); List <LocationSetProb> cOutcomeSets = this.getPossibleCollisionOutcomes(previousLocations, basicMoveResults); Action gsa = ja.action(i); Location2 loc = csp.locs.get(i); String agentName = this.agentName(i, (OOState)s); ObjectInstance agent = ns.touch(agentName); ((MutableState)agent).set(GridGame.VAR_X, loc.x); return this.combineDuplicateTransitionProbabilities(tps);
Location2 loc = this.getLocation((OOState)s, this.agentName(pn, (OOState)s)); previousLocations.add(loc); if(gsa.actionName().equals(GridGame.ACTION_NOOP)){ Location2 loc = previousLocations.get(i); Action gsa = ja.action(i); basicMoveResults.add(this.sampleBasicMovement((OOState)s, loc, this.attemptedDelta(gsa.actionName()), noopLocations)); basicMoveResults = this.resolvePositionSwaps(previousLocations, basicMoveResults); List <Location2> finalPositions = this.resolveCollisions(previousLocations, basicMoveResults); for(int i = 0; i < finalPositions.size(); i++){ Action gsa = ja.action(i); Location2 loc = finalPositions.get(i); String agentName = this.agentName(i, (OOState)s);
if(this.agentsEqual((OOState)tp.s, (OOState)cmpTP.s)){ sumP += cmpTP.p; marked.add(j);
return this.backupNoOps(originalPositions, resolvedPositions, newNoopPositions);
@Override public OOSGDomain generateDomain() { OOSGDomain domain = new OOSGDomain(); domain.addStateClass(CLASS_AGENT, GGAgent.class) .addStateClass(CLASS_GOAL, GGGoal.class) .addStateClass(CLASS_DIM_H_WALL, GGWall.GGHorizontalWall.class) .addStateClass(CLASS_DIM_V_WALL, GGWall.GGVerticalWall.class); domain.addActionType(new UniversalActionType(ACTION_NORTH)) .addActionType(new UniversalActionType(ACTION_SOUTH)) .addActionType(new UniversalActionType(ACTION_EAST)) .addActionType(new UniversalActionType(ACTION_WEST)) .addActionType(new UniversalActionType(ACTION_NOOP)); OODomain.Helper.addPfsToDomain(domain, this.generatePFs()); domain.setJointActionModel(new GridGameStandardMechanics(domain, this.semiWallProb)); return domain; }
/** * This method will recursively generate all possible joint location outcomes for a list of possible outcomes for each agent * @param locOutcomes the list of possible location outcomes for each agent * @param i the index from which to generate possible outcomes in a depth-first manner * @param locArray an array holding the current assignments for a given depth * @param stackedProb the probability of this location set occurring * @param discovered the discovered combinations thus far */ protected void generateAllLocationSetsHelper(List<List<Location2Prob>> locOutcomes, int i, Location2 [] locArray, double stackedProb, List<LocationSetProb> discovered){ if(i == locOutcomes.size()){ //bundle them up List <Location2> locs = new ArrayList<GridGameStandardMechanics.Location2>(locArray.length); Collections.addAll(locs, locArray); LocationSetProb lsp = new LocationSetProb(locs, stackedProb); discovered.add(lsp); return ; } //otherwise we're in recursive step List<Location2Prob> individualOutcomes = locOutcomes.get(i); for(Location2Prob lp : individualOutcomes){ locArray[i] = lp.l; this.generateAllLocationSetsHelper(locOutcomes, i+1, locArray, stackedProb*lp.p, discovered); } }
this.generateAllPossibleCollisionWinnerAssignments(collisionLists, 0, assignment, winnerAssignments);
/** * 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; }