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

aima.core.learning.reinforcement.example.CellWorldEnvironmentState Maven / Gradle / Ivy

Go to download

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

The newest version!
package aima.core.learning.reinforcement.example;

import java.util.HashMap;
import java.util.Map;

import aima.core.agent.Agent;
import aima.core.agent.EnvironmentState;
import aima.core.environment.cellworld.Cell;

/**
 * An implementation of the EnvironmentState interface for a Cell World.
 * 
 * @author Ciaran O'Reilly
 * 
 */
public class CellWorldEnvironmentState implements EnvironmentState {
	private Map agentLocations = new HashMap();

	/**
	 * Default Constructor.
	 */
	public CellWorldEnvironmentState() {
	}

	/**
	 * Reset the environment state to its default state.
	 */
	public void reset() {
		agentLocations.clear();
	}

	/**
	 * Set an agent's location within the cell world environment.
	 * 
	 * @param anAgent
	 *            the agents whose location is to be tracked.
	 * @param location
	 *            the location for the agent in the cell world environment.
	 */
	public void setAgentLocation(Agent anAgent, Cell location) {
		CellWorldPercept percept = agentLocations.get(anAgent);
		if (null == percept) {
			percept = new CellWorldPercept(location);
			agentLocations.put(anAgent, percept);
		} else {
			percept.setCell(location);
		}
	}

	/**
	 * Get the location of an agent within the cell world environment.
	 * 
	 * @param anAgent
	 *            the agent whose location is being queried.
	 * @return the location of the agent within the cell world environment.
	 */
	public Cell getAgentLocation(Agent anAgent) {
		return agentLocations.get(anAgent).getCell();
	}

	/**
	 * Get a percept for an agent, representing what it senses within the cell
	 * world environment.
	 * 
	 * @param anAgent
	 *            the agent a percept is being queried for.
	 * @return a percept for the agent, representing what it senses within the
	 *         cell world environment.
	 */
	public CellWorldPercept getPerceptFor(Agent anAgent) {
		return agentLocations.get(anAgent);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy