public class GameEpisode
extends java.lang.Object
This class should be used either by constructing with an initial state (GameEpisode(State)
) or by constructing with the default constructor and then
using the initializeInState(State)
method before recording any further transitions. Transitions should then be recorded with the
transition(JointAction, State, double[])
method which takes as input the next state to which the agent transitions, the joint action taken
in the previously recorded state that causes the transition, and the joint reward received for the transition.
When querying about the state, joint action, or joint rewards, use the methods state(int)
, jointAction(int)
, and jointReward(int)
respectively.
These methods take as input the time step of the element you want. Note that t = 0 refers to the initial state step so calling getState(0) and getJointAction(0)
will return the initial state and the joint action taken in the initial state, respectively. However, joint rewards are always received in the next time step
from the state and action that produced them. Therefore, getJointReward(0) is undefined. Instead, the first reward received will be at time step 1: getReward(1).
Additionally, the action and reward for a specific agent in a specific time step can be queried with agentAction(int, int)
and
agentReward(int, int)
, respectively.
Modifier and Type | Field and Description |
---|---|
java.util.List<JointAction> |
jointActions
The sequence of joint actions
|
java.util.List<double[]> |
jointRewards
The sequence of joint rewards
|
java.util.List<State> |
states
The sequence of states
|
Constructor and Description |
---|
GameEpisode()
Initialzes the datastructures.
|
GameEpisode(State initialState)
Initializes with an initial state of the game.
|
Modifier and Type | Method and Description |
---|---|
Action |
agentAction(int t,
int agentNum)
Returns the action taken for the given agent at the given time step where t=0 refers to the joint action taken in the initial state.
|
double |
agentReward(int t,
int agentNum)
Returns the reward received for the agent with the given name at the given step.
|
java.util.List<JointAction> |
getJointActions()
Returns the joint action sequence list object
|
java.util.List<double[]> |
getJointRewards()
Returns the joint reward sequence list object
|
java.util.List<State> |
getStates()
Returns the state sequence list object
|
void |
initializeInState(State initialState)
Clears out any already recorded states, joint actions, and rewards, and sets the initial state of the game.
|
JointAction |
jointAction(int t)
Returns the joint action taken in time step t where t=0 refers to the joint action taken in the initial state.
|
double[] |
jointReward(int t)
Returns the joint reward received in time step t.
|
static void |
main(java.lang.String[] args) |
int |
maxTimeStep()
Returns the max time step index in this game which equals
numTimeSteps() -1. |
int |
numTimeSteps()
Returns the number of time steps recorded which is equal to the number of states observed.
|
static GameEpisode |
parse(java.lang.String episodeString) |
static GameEpisode |
read(java.lang.String path)
Reads a game that was written to a file and turns into a
GameEpisode object. |
java.lang.String |
serialize() |
State |
state(int t)
Returns the state stored at time step t where t=0 refers to the initial state
|
void |
transition(JointAction jointAction,
State nextState,
double[] jointReward)
Records a transition from the last recorded state in this object using the specififed joint action to the specified next state and with the specified joint reward
being received as a result.
|
void |
write(java.lang.String path)
Writes this game to a file.
|
public java.util.List<State> states
public java.util.List<JointAction> jointActions
public java.util.List<double[]> jointRewards
public GameEpisode()
initializeInState(State)
should be called
to set the initial state of the game before any transitions are recorded.public GameEpisode(State initialState)
initialState
- the initial state of the game.public void initializeInState(State initialState)
initialState
- the initial state of the game.public State state(int t)
t
- the time steppublic JointAction jointAction(int t)
t
- the time steppublic double[] jointReward(int t)
t
- the time steppublic Action agentAction(int t, int agentNum)
t
- the time stepagentNum
- the agent number for the action to be returnedpublic double agentReward(int t, int agentNum)
t
- the time stepagentNum
- the agent for whom the reward should be returnedpublic int numTimeSteps()
public int maxTimeStep()
numTimeSteps()
-1.public void transition(JointAction jointAction, State nextState, double[] jointReward)
jointAction
- the joint action taken in the last recorded state in this objectnextState
- the next state to which the agents transitionjointReward
- the joint reward received for the transitonpublic java.util.List<State> getStates()
public java.util.List<JointAction> getJointActions()
public java.util.List<double[]> getJointRewards()
public java.lang.String serialize()
public static GameEpisode parse(java.lang.String episodeString)
public void write(java.lang.String path)
path
- the path to the file in which to write this game.public static GameEpisode read(java.lang.String path)
GameEpisode
object.path
- the path to the game file.GameEpisode
object.public static void main(java.lang.String[] args)