org.vizzini.game.boardgame
Class AbstractGridBoard

java.lang.Object
  extended by org.vizzini.game.AbstractEnvironment
      extended by org.vizzini.game.boardgame.AbstractGridBoard
All Implemented Interfaces:
Serializable, Cloneable, IGridBoard, IEnvironment
Direct Known Subclasses:
AbstractChessEnvironment, DefaultGridBoard

public abstract class AbstractGridBoard
extends AbstractEnvironment
implements IGridBoard

Provides functionality for 2D and 3D grid board environments in the game framework.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson
See Also:
Serialized Form

Field Summary
protected static UndoAction UNDO_ACTION
          Undo action.
 
Constructor Summary
AbstractGridBoard()
           
 
Method Summary
 int agentTokenCount(IAgent agent, int startF, int startR, int startL, int df, int dr, int dl)
          Return the number of token's the given agent has in the line specified by the other arguments.
 void configure(Properties properties)
          Configure this environment.
 int coordsToIndex(int file, int rank, int level)
          Return the index computed from the given parameters.
 void copy(IEnvironment environment)
          Copy data from the given instance into this.
 IToken get(int file, int rank, int level)
          Return the token at the given position.
 int getCellCount()
          Return the cell count.
 IAgent getCurrentAgent()
          Return the current agent.
 int getFileCount()
          Return the file count.
 IAgent getLastAgent()
          Return the last agent who performed an action.
 int getLevelCount()
          Return the level count.
 int getMaxDimension()
          Return the maximum of the file, rank, and level counts.
 int getRankCount()
          Return the rank count.
 int indexToFile(int index)
          Return the file coordinates computed from the given index.
 int indexToLevel(int index)
          Return the level coordinates computed from the given index.
 IntegerPosition indexToPosition(int index)
          Return the position computed from the given index.
 int indexToRank(int index)
          Return the rank coordinates computed from the given index.
 boolean is3D()
          Return true if this is using 3D coordinates.
 boolean isActionHistoryUsed()
           
 boolean isPositionUsable(IntegerPosition position)
          Return true if the given position is usable.
 boolean isPositionUsable(int file, int rank, int level)
          Return true if the given position is usable.
 boolean isRedoAllowed()
          Return true if a redo action is allowed.
 boolean isUndoAllowed()
          Return true if an undo action is allowed.
 void performAction(IAction action)
          Perform the given action.
 int positionToIndex(IntegerPosition position)
          Return the index computed from the given position.
 void setActionHistoryUsed(boolean isActionHistoryUsed)
           
protected  void setLastAgent(IAgent agent)
          Set the last agent who performed an action.
 void setToken(IntegerPosition position, IToken token)
          Set the token at the given position.
 void setToken(int file, int rank, int level, IToken token)
          Set the token at the given position.
 void undoAction(IAction action)
          Undo the given action.
 
Methods inherited from class org.vizzini.game.AbstractEnvironment
addStateListener, clone, createInitialTokens, equals, get, getAdjudicator, getAgentCollection, getStateManager, getTeamCollection, getTokenCollection, getTokenCollectionClass, getTurnNumber, hashCode, incrementTurnNumber, isFiringStateChanges, open, performActions, removeStateListener, reset, setAdjudicator, setAgentCollection, setFiringStateChanges, setTokenCollectionClass, setTurnNumber, update
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.vizzini.game.IEnvironment
addStateListener, clone, get, getAdjudicator, getAgentCollection, getTeamCollection, getTokenCollection, getTurnNumber, incrementTurnNumber, isFiringStateChanges, open, performActions, removeStateListener, reset, setAdjudicator, setAgentCollection, setFiringStateChanges, setTurnNumber, update
 

Field Detail

UNDO_ACTION

protected static final UndoAction UNDO_ACTION
Undo action.

Constructor Detail

AbstractGridBoard

public AbstractGridBoard()
Method Detail

agentTokenCount

public int agentTokenCount(IAgent agent,
                           int startF,
                           int startR,
                           int startL,
                           int df,
                           int dr,
                           int dl)
Return the number of token's the given agent has in the line specified by the other arguments.

There are many possible lines:
files: rl
ranks: fl
levels: fr
file diagonals: 2f
rank diagonals: 2r
level diagonals: 2l
triagonals: 4
total: rl + rl + fr + 2f + 2r + 2l + 4
Example: f = r = l = 4
16 + 16 + 16 + 8 + 8 + 8 + 4 = 48 + 24 + 4 = 76

Specified by:
agentTokenCount in interface IGridBoard
Parameters:
agent - Agent of interest.
startF - Starting file.
startR - Starting rank.
startL - Starting level.
df - Delta in the file direction.
dr - Delta in the rank direction.
dl - Delta in the level direction.
Since:
v0.2

configure

public void configure(Properties properties)
               throws InstantiationException,
                      IllegalAccessException
Configure this environment.

Specified by:
configure in interface IEnvironment
Overrides:
configure in class AbstractEnvironment
Parameters:
properties - Source of configuration information.
Throws:
InstantiationException
IllegalAccessException
Since:
v0.1

coordsToIndex

public int coordsToIndex(int file,
                         int rank,
                         int level)
Return the index computed from the given parameters.

Specified by:
coordsToIndex in interface IGridBoard
Parameters:
file - File.
rank - Rank.
level - Level.
Returns:
The index, or -1 if the coordinates are out of range.

copy

public void copy(IEnvironment environment)
Copy data from the given instance into this.

Specified by:
copy in interface IEnvironment
Overrides:
copy in class AbstractEnvironment
Parameters:
environment - Environment from which to copy data.
Since:
v0.1

get

public IToken get(int file,
                  int rank,
                  int level)
Return the token at the given position.

Specified by:
get in interface IGridBoard
Parameters:
file - File.
rank - Rank.
level - Level.
Since:
v0.1

getCellCount

public int getCellCount()
Return the cell count.

Specified by:
getCellCount in interface IGridBoard
Since:
v0.1

getCurrentAgent

public IAgent getCurrentAgent()
Return the current agent. FIXME: this assumes only two agents.

Since:
v0.1

getFileCount

public int getFileCount()
Return the file count.

Specified by:
getFileCount in interface IGridBoard
Since:
v0.1

getLastAgent

public IAgent getLastAgent()
Return the last agent who performed an action.

Specified by:
getLastAgent in interface IGridBoard
Since:
v0.1

getLevelCount

public int getLevelCount()
Return the level count.

Specified by:
getLevelCount in interface IGridBoard
Since:
v0.1

getMaxDimension

public int getMaxDimension()
Return the maximum of the file, rank, and level counts.

Specified by:
getMaxDimension in interface IGridBoard
Since:
v0.2

getRankCount

public int getRankCount()
Return the rank count.

Specified by:
getRankCount in interface IGridBoard
Since:
v0.1

indexToFile

public int indexToFile(int index)
Return the file coordinates computed from the given index.

Specified by:
indexToFile in interface IGridBoard
Parameters:
index - Index.
Since:
v0.2

indexToLevel

public int indexToLevel(int index)
Return the level coordinates computed from the given index.

Specified by:
indexToLevel in interface IGridBoard
Parameters:
index - Index.
Since:
v0.2

indexToPosition

public IntegerPosition indexToPosition(int index)
Return the position computed from the given index.

Specified by:
indexToPosition in interface IGridBoard
Parameters:
index - Index.
Since:
v0.2

indexToRank

public int indexToRank(int index)
Return the rank coordinates computed from the given index.

Specified by:
indexToRank in interface IGridBoard
Parameters:
index - Index.
Since:
v0.2

is3D

public boolean is3D()
Return true if this is using 3D coordinates.

Specified by:
is3D in interface IGridBoard
Since:
v0.1

isActionHistoryUsed

public boolean isActionHistoryUsed()
Specified by:
isActionHistoryUsed in interface IGridBoard
Returns:
Return isActionHistoryUsed.
Since:
v0.3

isPositionUsable

public boolean isPositionUsable(IntegerPosition position)
Return true if the given position is usable.

Specified by:
isPositionUsable in interface IGridBoard
Parameters:
position - Position.
Since:
v0.1

isPositionUsable

public boolean isPositionUsable(int file,
                                int rank,
                                int level)
Return true if the given position is usable.

Specified by:
isPositionUsable in interface IGridBoard
Since:
v0.1

isRedoAllowed

public boolean isRedoAllowed()
Return true if a redo action is allowed.

Specified by:
isRedoAllowed in interface IGridBoard
Since:
v0.2

isUndoAllowed

public boolean isUndoAllowed()
Return true if an undo action is allowed.

Specified by:
isUndoAllowed in interface IGridBoard
Since:
v0.2

performAction

public void performAction(IAction action)
Perform the given action.

Specified by:
performAction in interface IEnvironment
Parameters:
action - Action.
Throws:
ClassCastException - if action0 is not a PlacementAction.
Since:
v0.2

positionToIndex

public int positionToIndex(IntegerPosition position)
Return the index computed from the given position.

Specified by:
positionToIndex in interface IGridBoard
Parameters:
position - Position.
Since:
v0.2

setActionHistoryUsed

public void setActionHistoryUsed(boolean isActionHistoryUsed)
Specified by:
setActionHistoryUsed in interface IGridBoard
Parameters:
isActionHistoryUsed - The isActionHistoryUsed to set.
Since:
v0.3

setToken

public void setToken(IntegerPosition position,
                     IToken token)
Set the token at the given position.

Specified by:
setToken in interface IGridBoard
Parameters:
position - Position.
token - Token.
Since:
v0.1

setToken

public void setToken(int file,
                     int rank,
                     int level,
                     IToken token)
Set the token at the given position.

Specified by:
setToken in interface IGridBoard
Parameters:
file - File.
rank - Rank.
level - Level.
token - Token.
Since:
v0.1

undoAction

public void undoAction(IAction action)
Undo the given action.

Specified by:
undoAction in interface IEnvironment
Parameters:
action - Action.
Throws:
ClassCastException - if action0 is not a PlacementAction.
Since:
v0.2

setLastAgent

protected void setLastAgent(IAgent agent)
Set the last agent who performed an action.

Parameters:
agent - Agent.
Since:
v0.1


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02