Skip to content

Sample Random Controller (2 Player)

Raluca D. Gaina edited this page Feb 12, 2018 · 1 revision

This is a very simple, completely functional controller for the Two Player Track of GVG-AI. It does not take into account the fact that there is a second player in the game, it just returns a random action to be executed in the next game cycle.

Note that this class extends AbstractMultiPlayer (and not AbstractPlayer, the single player version) and that the player ID is caught in the constructor and used to access the list of actions available for this particular player.

package random; //The package name is the same as the username in the web.

public class Agent extends AbstractMultiPlayer {

	int id; //this player's ID

	/**
	 * initialize all variables for the agent
	 * @param stateObs Observation of the current state.
     * @param elapsedTimer Timer when the action returned is due.
	 * @param playerID ID of this agent.
	 */
	public Agent(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer, int playerID){
		id = playerID;
	}

	/**
	 * return ACTION_NIL on every call to simulate doNothing player
	 * @param stateObs Observation of the current state.
	 * @param elapsedTimer Timer when the action returned is due.
	 * @return 	ACTION_NIL all the time
	 */
	@Override
	public ACTIONS act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer) {
		ArrayList<ACTIONS> a = stateObs.getAvailableActions(id);
		return ACTIONS.values()[new Random().nextInt(a.size())];
	}
}

Table of Contents:

Clone this wiki locally