net.sourceforge.cilib.games.states
Class ListGameState

java.lang.Object
  extended by net.sourceforge.cilib.games.states.GameState
      extended by net.sourceforge.cilib.games.states.ListGameState
All Implemented Interfaces:
Serializable, Cloneable

public class ListGameState
extends GameState

This is a GameState where GameItem's are stored in a list of items. This implies that any items position in the list has not correlation to the items location in the game. This is usefull when you have items in large 2 or 3 dimensional spaces and you would more likely look for an item by searching through a list than quering a location in a known structure.

Author:
leo
See Also:
Serialized Form

Field Summary
protected  List<GameItem> currentState
           
 
Fields inherited from class net.sourceforge.cilib.games.states.GameState
currentIteration, randomizer
 
Constructor Summary
ListGameState()
           
ListGameState(ListGameState other)
          Copy constructor
 
Method Summary
 void addGameItem(GameItem item)
          Add an item to the game state at the end of the list.
 void clearState()
          Clear the state and reset it to a start state.
 ListGameState getClone()
          Create a cloned copy of the current object and return it.
 GameItem getItem(Enum itemToken)
          Returns first item that contains specified token
 GameItem getItem(int index)
          Get an item with the specified index in the list.
 GameItem getItem(ItemLocation location)
          Get an item that matches a given ItemLocation
 int getSize()
           
 
Methods inherited from class net.sourceforge.cilib.games.states.GameState
getCurrentIteration, getRandomizer, increaseIteration, resetIterationCount, setRandomizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentState

protected List<GameItem> currentState
Constructor Detail

ListGameState

public ListGameState()

ListGameState

public ListGameState(ListGameState other)
Copy constructor

Parameters:
other -
Method Detail

getSize

public int getSize()

addGameItem

public void addGameItem(GameItem item)
Add an item to the game state at the end of the list.

Parameters:
item - the item to add

clearState

public void clearState()
Clear the state and reset it to a start state.

Specified by:
clearState in class GameState

getItem

public GameItem getItem(int index)
Get an item with the specified index in the list.

Parameters:
index - the index in the list of items
Returns:
the item to retrieve

getItem

public GameItem getItem(ItemLocation location)
Get an item that matches a given ItemLocation

Parameters:
location - the location
Returns:
the requested item, if the item is not found null is returned

getItem

public GameItem getItem(Enum itemToken)
Returns first item that contains specified token

Parameters:
itemToken - the target token
Returns:
the game item

getClone

public ListGameState getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Cloneable
Specified by:
getClone in class GameState
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()


Copyright © 2009 CIRG. All Rights Reserved.