net.sourceforge.cilib.games.game.tetris
Class Tetris

java.lang.Object
  extended by net.sourceforge.cilib.games.game.Game<TetrisGameState>
      extended by net.sourceforge.cilib.games.game.tetris.Tetris
All Implemented Interfaces:
Serializable, RealTimeGame, StateGame, UpdateGame, Cloneable

public class Tetris
extends Game<TetrisGameState>
implements UpdateGame, StateGame, RealTimeGame

This is an implimentation of the game of Tetris.

Author:
leo
See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.cilib.games.game.Game
agentMeasurement, currentPlayer, players
 
Constructor Summary
Tetris()
           
Tetris(Tetris other)
          
Tetris(Tetris other, TetrisGameState newState)
          
 
Method Summary
 void display()
          Print the game to the console, is useful during testing.
 boolean gameOver()
          check if the game should terminate
 List<GameState> generateStates(int currentPlater)
          This method generates every possible from the current state for a specific player
 Tetris getClone()
          Create a cloned copy of the current object and return it.
 Tetris getClone(TetrisGameState newState)
          Get a clone with the given GameState This method should typically be used by the StateTraversalStrategy and Agent with regards to decision making when playing the game.
 AbstractGameResult getGameResult()
          Get the result of the game (Win/Lose/Draw)
 int getHeight()
           
 int getMaxLines()
           
 int getWidth()
           
 void initializeGame()
          perform any game specific initialization
 void recordRoundStartState()
          Record the state of the game at the start of the round
 void setAgent(Agent player)
          Add a new agent
 void setAgent(Agent player, int playerID)
          Add an agent with a specified playerID, if it already exists, replace it
 void setHeight(int height)
           
 void setMaxLines(int maxLines)
           
 void setWidth(int width)
           
 void Update()
          This method should update any game elements outside the control of the players
 
Methods inherited from class net.sourceforge.cilib.games.game.Game
addMeasurement, assignPlayerScore, clearMeasurementData, clearMeasurements, getAgentMeasurements, getCurrentIteration, getCurrentPlayer, getCurrentState, getDecisionState, getDomainForPlayer, getNextPlayerID, getPlayer, getPlayerCount, getPlayerIDList, getPlayerScore, getScoringStrategy, initializeAgent, playGame, playGame, setCurrentGameState, setCurrentPlayer, setEntityScore, setScoringStrategy, setSeedingStrategy, setStartPlayer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tetris

public Tetris()

Tetris

public Tetris(Tetris other)


Tetris

public Tetris(Tetris other,
              TetrisGameState newState)

Method Detail

setAgent

public void setAgent(Agent player)
Add a new agent

Overrides:
setAgent in class Game<TetrisGameState>
Parameters:
player - the Agent to add

setAgent

public void setAgent(Agent player,
                     int playerID)
Add an agent with a specified playerID, if it already exists, replace it

Overrides:
setAgent in class Game<TetrisGameState>
Parameters:
player - the new Agent
playerID - the playerID for the agent

display

public void display()
Print the game to the console, is useful during testing.

Specified by:
display in class Game<TetrisGameState>

gameOver

public boolean gameOver()
check if the game should terminate

Specified by:
gameOver in class Game<TetrisGameState>
Returns:
the endgame flag

getClone

public Tetris 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 Game<TetrisGameState>
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

getClone

public Tetris getClone(TetrisGameState newState)
Get a clone with the given GameState This method should typically be used by the StateTraversalStrategy and Agent with regards to decision making when playing the game. Since this process includes making alot of copies of the game a seperate, faster, method is neccesary that does not waste time by making unneccesary copies of the game state and player logic.

Specified by:
getClone in class Game<TetrisGameState>
Parameters:
newState - the new sate to use
Returns:
the copy

getGameResult

public AbstractGameResult getGameResult()
Get the result of the game (Win/Lose/Draw)

Specified by:
getGameResult in class Game<TetrisGameState>
Returns:
the relevant AbstractGameResult object

initializeGame

public void initializeGame()
perform any game specific initialization

Specified by:
initializeGame in class Game<TetrisGameState>

Update

public void Update()
This method should update any game elements outside the control of the players

Specified by:
Update in interface UpdateGame

generateStates

public List<GameState> generateStates(int currentPlater)
This method generates every possible from the current state for a specific player

Specified by:
generateStates in interface StateGame
Parameters:
currentPlater - the player whos turn it is
Returns:
a list of possible game states

getWidth

public int getWidth()

getHeight

public int getHeight()

setWidth

public void setWidth(int width)

setHeight

public void setHeight(int height)

recordRoundStartState

public void recordRoundStartState()
Description copied from interface: RealTimeGame
Record the state of the game at the start of the round

Specified by:
recordRoundStartState in interface RealTimeGame

setMaxLines

public void setMaxLines(int maxLines)

getMaxLines

public int getMaxLines()


Copyright © 2009 CIRG. All Rights Reserved.