Commit 9102c50f authored by Bruno Zanuttini's avatar Bruno Zanuttini
Browse files

First version of GridWorld

parent 5b8ae36d
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
package fr.greyc.mad.framework.example.gridworld;

import java.util.Collections;
import java.util.List;

import fr.greyc.mad.framework.model.Action;
import fr.greyc.mad.framework.model.Environment;
import fr.greyc.mad.framework.model.Observation;

public class GridWorld extends Environment{

	@Override
	protected List<Action> getEnvironmentActions() {
		return Collections.emptyList();
	}

	// TODO: check semantics (and document in superclass)
	@Override
	protected List<Observation<?>> getEnvironmentObservations() {
		return Collections.emptyList();
	}

	public void move(GridWorldAgentBody body, int dRow, int dColumn) {
		// TODO Auto-generated method stub
		
	}

}
+27 −0
Original line number Diff line number Diff line
package fr.greyc.mad.framework.example.gridworld;

import fr.greyc.mad.framework.model.Action;

public class GridWorldAction implements Action {

	protected final GridWorld environment;

	protected final GridWorldAgentBody body;

	protected final int dRow;

	protected final int dColumn;

	public GridWorldAction(GridWorld environment, GridWorldAgentBody body, int dRow, int dColumn) {
		this.environment = environment;
		this.body = body;
		this.dRow = dRow;
		this.dColumn = dColumn;
	}

	@Override
	public void execute() {
		this.environment.move(this.body, this.dRow, this.dColumn);
	}

}
+49 −0
Original line number Diff line number Diff line
package fr.greyc.mad.framework.example.gridworld;

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

public class GridWorldActionFactory {

	protected final GridWorld environment;

	private final Map<GridWorldAgentBody, ActionMap> cache;

	public GridWorldActionFactory(GridWorld environment) {
		this.environment = environment;
		this.cache = new HashMap<>();
	}

	public GridWorldAction get(GridWorldAgentBody body, int dRow, int dColumn) {
		return this.cache.get(body).get(dRow, dColumn);
	}

	class ActionMap {

		final Map<Integer, Map<Integer, GridWorldAction>> map;

		final GridWorldAgentBody body;

		ActionMap(GridWorldAgentBody body) {
			this.map = new HashMap<>();
			this.body = body;
		}

		GridWorldAction get(int dRow, int dColumn) {
			Map<Integer, GridWorldAction> forRow = this.map.get(dRow);
			if (forRow == null) {
				forRow = new HashMap<>();
				this.map.put(dRow, forRow);
			}
			if (forRow.containsKey(dColumn)) {
				return forRow.get(dColumn);
			} else {
				GridWorldAction action = new GridWorldAction(GridWorldActionFactory.this.environment, this.body, dRow,
						dColumn);
				forRow.put(dColumn, action);
				return action;
			}
		}
	}

}
+23 −0
Original line number Diff line number Diff line
package fr.greyc.mad.framework.example.gridworld;

import java.util.List;

import fr.greyc.mad.framework.model.Action;
import fr.greyc.mad.framework.model.AgentBody;
import fr.greyc.mad.framework.model.Observation;

public class GridWorldAgentBody implements AgentBody{

	@Override
	public List<Action> getActions() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Observation<?>> getObservations() {
		// TODO Auto-generated method stub
		return null;
	}

}
+6 −0
Original line number Diff line number Diff line
/**
 * A package for a simple grid world environment, with agents able to move from squares to neighboring squares.
 * 
 * @author Bruno Zanuttini
 */
package fr.greyc.mad.framework.example.gridworld;
 No newline at end of file