All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.environment.vacuum.VacuumWorldGoalTest Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

There is a newer version: 3.0.0
Show newest version
package aima.core.environment.vacuum;

import aima.core.agent.Agent;
import aima.core.search.framework.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;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy