net.sourceforge.cilib.games.states
Class GridGameState

java.lang.Object
  extended by net.sourceforge.cilib.games.states.GameState
      extended by net.sourceforge.cilib.games.states.GridGameState
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
TetrisGameState

public class GridGameState
extends GameState

This is a GameState where all the GameItem's are stored in a matrix. For games like TickTackToe or Tetris storing all the gameItems in a list would not be desireable since accessing an item in a specific location in the grid would be much more complex.

Author:
leo
See Also:
Serialized Form

Field Summary
protected  GameItem[][] state
           
 
Fields inherited from class net.sourceforge.cilib.games.states.GameState
currentIteration, randomizer
 
Constructor Summary
GridGameState()
           
GridGameState(GridGameState other)
          Copy constructor
GridGameState(int gridWidth, int gridHeight)
           
 
Method Summary
 void clearState()
          Clear the state and reset it to a start state.
 GridGameState getClone()
          Create a cloned copy of the current object and return it.
 int getGridHeight()
           
 int getGridWidth()
           
 GameItem getItem(int i, int j)
          Get an Item at a specific index in the matrix.
 void setGridHeight(int gridHeight)
           
 void setGridWidth(int gridWidth)
           
 void setItem(int i, int j, GameItem item)
          Set an item at a specific index in the matrix
 
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

state

protected GameItem[][] state
Constructor Detail

GridGameState

public GridGameState()

GridGameState

public GridGameState(int gridWidth,
                     int gridHeight)

GridGameState

public GridGameState(GridGameState other)
Copy constructor

Parameters:
other -
Method Detail

getGridHeight

public int getGridHeight()

setGridHeight

public void setGridHeight(int gridHeight)

getGridWidth

public int getGridWidth()

setGridWidth

public void setGridWidth(int gridWidth)

getItem

public GameItem getItem(int i,
                        int j)
Get an Item at a specific index in the matrix.

Parameters:
i - the specified Column
j - the specified Row
Returns:
the Game Item. If this position is empty, null will be returned.

setItem

public void setItem(int i,
                    int j,
                    GameItem item)
Set an item at a specific index in the matrix

Parameters:
i - the specified Column
j - the specified Row
item - the item to set. This method does not check if an item already exists, and will simply override what is in that position.

clearState

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

Specified by:
clearState in class GameState

getClone

public GridGameState 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.