aima.core.environment.vacuum.VacuumWorldGoalTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
The newest version!
package aima.core.environment.vacuum;
import aima.core.agent.Agent;
import aima.core.search.framework.problem.GoalTest;
/**
* Tests for goals states
*
* @author Andrew Brown
*/
public class VacuumWorldGoalTest implements GoalTest {
private Agent agent;
/**
* Constructor
*
* @param agent
*/
public VacuumWorldGoalTest(Agent agent) {
this.agent = agent;
}
/**
* Tests whether the search has identified a goal state
*
* @param state
* @return true if the state is a goal state, false otherwise.
*/
@Override
public boolean isGoalState(Object state) {
// setup
VacuumEnvironmentState vacEnvState = (VacuumEnvironmentState) state;
String currentLocation = vacEnvState.getAgentLocation(this.agent);
String adjacentLocation = (currentLocation
.equals(VacuumEnvironment.LOCATION_A)) ? VacuumEnvironment.LOCATION_B
: VacuumEnvironment.LOCATION_A;
// test goal state
if (VacuumEnvironment.LocationState.Clean != vacEnvState
.getLocationState(currentLocation)) {
return false;
} else if (VacuumEnvironment.LocationState.Clean != vacEnvState
.getLocationState(adjacentLocation)) {
return false;
} else {
return true;
}
}
}