org.vizzini.game.boardgame
Class GridBoardSupport

java.lang.Object
  extended by org.vizzini.game.boardgame.GridBoardSupport

public class GridBoardSupport
extends Object

Provides support for grid boards in the game framework. Provides methods for converting between grid coordinates and indexes.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson

Constructor Summary
GridBoardSupport(int fileCount, int rankCount, int levelCount)
          Construct this object with the given parameters.
 
Method Summary
 boolean contains(int index)
          Return true if the given position is within the limits of this board.
 boolean contains(int file, int rank, int level)
          Return true if the given position is within the limits of this board.
 int coordsToIndex(int file, int rank, int level)
          Return the index computed from the given parameters.
 int getCellCount()
          Return the cell count.
 int[] getDimensions()
          Return the dimensions.
 int getFileCount()
          Return the file count.
 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[] indexToCoords(int bitIndex)
          Return the coordinates computed from the given index.
 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.
 int positionToIndex(IntegerPosition position)
          Return the index computed from the given position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridBoardSupport

public GridBoardSupport(int fileCount,
                        int rankCount,
                        int levelCount)
Construct this object with the given parameters.

Parameters:
fileCount - File count.
rankCount - Rank count.
levelCount - Level count.
Since:
v0.1
Method Detail

contains

public boolean contains(int index)
Return true if the given position is within the limits of this board.

Parameters:
index - Index.
Since:
v0.1

contains

public boolean contains(int file,
                        int rank,
                        int level)
Return true if the given position is within the limits of this board.

Parameters:
file - File.
rank - Rank.
level - Level.
Since:
v0.1

coordsToIndex

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

Parameters:
file - File.
rank - Rank.
level - Level.
Returns:
The index, or -1 if the coordinates are out of range.

getCellCount

public int getCellCount()
Return the cell count.

Since:
v0.1

getDimensions

public int[] getDimensions()
Return the dimensions. Don't use this method in performance critical code; creating the int array is time consuming.

Since:
v0.1

getFileCount

public int getFileCount()
Return the file count.

Since:
v0.1

getLevelCount

public int getLevelCount()
Return the level count.

Since:
v0.1

getMaxDimension

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

Since:
v0.1

getRankCount

public int getRankCount()
Return the rank count.

Since:
v0.1

indexToCoords

public int[] indexToCoords(int bitIndex)
Return the coordinates computed from the given index. Don't use this method in performance critical code; creating the int array is time consuming. Use the methods indexToFile(), indexToRank(), and indexToLevel() instead. (Yes, three method calls are faster than creating an int array.)

Since:
v0.1

indexToFile

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

Parameters:
index - Index.
Since:
v0.1

indexToLevel

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

Parameters:
index - Index.
Since:
v0.1

indexToPosition

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

Parameters:
index - Index.
Since:
v0.1

indexToRank

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

Parameters:
index - Index.
Since:
v0.1

positionToIndex

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

Parameters:
position - Position.
Since:
v0.1


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02