|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.puzzle.data.Board
com.threerings.puzzle.drop.data.DropBoard
public class DropBoard
A class that provides for various useful logical operations to be enacted on a two-dimensional board and provides an easier mechanism for referencing pieces by position.
| Nested Class Summary | |
|---|---|
static interface |
DropBoard.PieceOperation
An interface to be implemented by classes that would like to apply some operation to each piece in a column or row segment in the board. |
protected static class |
DropBoard.SetPieceOperation
An operation that sets all pieces to a specified piece. |
protected static class |
DropBoard.SetSegmentOperation
An operation that sets the pieces in a board segment to a specified array of pieces. |
| Nested classes/interfaces inherited from class com.threerings.puzzle.data.Board |
|---|
Board.BoardRandom |
| Nested classes/interfaces inherited from interface com.threerings.io.Streamable |
|---|
Streamable.Closure |
| Field Summary | |
|---|---|
protected int |
_bhei
The board dimensions in pieces. |
protected int[] |
_board
The board data. |
protected Rectangle |
_bounds
The bounds of this board. |
protected int |
_bwid
The board dimensions in pieces. |
protected static DropBoard.SetPieceOperation |
_setPieceOp
The operation used to set a piece in a board segment. |
protected static DropBoard.SetSegmentOperation |
_setSegmentOp
The operation used to set the pieces in a board segment. |
static DropBoard.PieceOperation |
CLEAR_OP
An operation that does naught but clear pieces, which proves to be generally useful. |
protected static int[] |
COERCE_DX
|
protected static int |
DEFAULT_PAD_WIDTH
The number of characters to which each board piece should be padded when outputting for debug purposes. |
static int |
INPLACE_ROTATION
The rotation constant for rotation wherein the block occupies the same columns when rotating. |
protected static int[] |
ORIENT_HEIGHTS
|
protected static int[] |
ORIENT_ORIGIN_DX
|
protected static int[] |
ORIENT_ORIGIN_DY
|
protected static int[] |
ORIENT_WIDTHS
|
static int |
RADIAL_ROTATION
The rotation constant for rotation around a central piece. |
protected static int[][][] |
ROTATE_DX
|
protected static int[][][] |
ROTATE_DY
|
| Fields inherited from class com.threerings.puzzle.data.Board |
|---|
_rando |
| Fields inherited from interface com.threerings.puzzle.drop.data.DropPieceCodes |
|---|
DROP_BLOCK_PIECE_COUNT, PIECE_NONE |
| Fields inherited from interface com.threerings.util.DirectionCodes |
|---|
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST |
| Constructor Summary | |
|---|---|
DropBoard()
Constructs an empty drop board for use when unserializing. |
|
DropBoard(int[] board,
int bwid,
int bhei)
Constructs a drop board with the given board and dimensions. |
|
DropBoard(int bwid,
int bhei)
Constructs a drop board of the given dimensions with its pieces initialized to PIECE_NONE. |
|
DropBoard(int bwid,
int bhei,
int piece)
Constructs a drop board of the given dimensions with its pieces initialized to the given piece. |
|
| Method Summary | |
|---|---|
void |
applyOp(int col,
int row,
DropBoard.PieceOperation op)
Applies a specified DropBoard.PieceOperation to the specified piece in the board. |
void |
applyOp(int dir,
int col,
int row,
DropBoard.PieceOperation op)
Applies a specified DropBoard.PieceOperation to all pieces in the specified row or column
starting at the specified coordinates and spanning the remainder of the row or column
(depending on the application direction) in the board. |
void |
applyOp(int dir,
int col,
int row,
int len,
DropBoard.PieceOperation op)
Applies a specified DropBoard.PieceOperation to all pieces in a row or column segment
starting at the specified coordinates and of the specified length in the board. |
void |
applyRisingPieces(int[] pieces)
Called by the DropControllerDelegate when it's time to apply a rising row of pieces
to the board. |
DropBoard |
clone()
|
protected int |
coordsToIndex(int col,
int row)
Converts from column & row to an index into our board array. |
void |
copyInto(DropBoard board)
Copies the contents of this board directly into the supplied board, overwriting the destination board in its entirety. |
void |
dump()
Outputs a string representation of the board contents. |
void |
dumpAndCompare(Board other)
Outputs a string representation of the board contents, interlaced with the supplied comparison board. |
boolean |
equals(Board other)
Returns whether this board is equal to the given comparison board. |
void |
fill(int piece)
Fills the board contents with the given piece. |
protected String |
formatPiece(int piece)
Returns a string representation of the given piece for use when dumping the board. |
int[] |
getBoard()
Returns the raw board data associated with this board. |
Rectangle |
getBounds()
Returns the bounds of this board. |
void |
getColumnLevels(byte[] columns)
Populates the given array with the column levels for this board. |
int |
getDropDistance(int col,
int row)
Returns the distance the piece at the given column and row can drop until it hits a non-empty piece (defined as DropPieceCodes.PIECE_NONE). |
Point |
getForgivingMove(int col,
int row,
int wid,
int hei,
int dx,
int dy,
float pctdone)
Returns a Point object containing the coordinates to place the bottom-left of the
given block at after moving it the given distance on the x- and y-axes, or
null if the move is not valid. |
int[] |
getForgivingRotation(int[] rows,
int[] cols,
int orient,
int dir,
int rtype,
float pctdone,
boolean canPopup)
Rotates the given block in the given direction and returns its final state as (orient,
col, row, popped), where orient is the final orientation of the drop
block; col and row are the final column and row coordinates,
respectively, of the central drop block piece. |
int |
getHeight()
Returns the height of the board in rows. |
int |
getNextPiece()
For boards that are always filled, this method is called to obtain pieces to fill the board. |
protected int |
getPadWidth()
Returns the number of characters to which a single piece should be padded when dumping the board for debugging purposes. |
int |
getPiece(int col,
int row)
Returns the piece at the given column and row in the board. |
int |
getWidth()
Returns the width of the board in columns. |
boolean |
inBounds(int col,
int row)
Returns true if the specified coordinate is within the bounds of the board, false if it is not. |
protected int |
indexToCol(int idx)
Converts from an index into our board array to a column. |
protected int |
indexToRow(int idx)
Converts from an index into our board array to a row. |
boolean |
isBlockEmpty(int col,
int row,
int wid,
int hei)
Returns whether the specified block in the board is empty. |
boolean |
isRowEmpty(int row)
Returns whether the given row in the board is empty. |
boolean |
isValidDrop(int[] rows,
int[] cols,
float pctdone)
Returns whether all of the pieces at the given coordinates can be dropped one row. |
boolean |
isValidPosition(int x,
int y)
Returns whether the given coordinates are within the board bounds. |
boolean |
rowContainsPieces(int row,
int blankPiece)
Returns true if the specified row (which count down, with zero at the top of the board) contains any pieces. |
void |
setBoard(int[] board)
Sets the board pieces. |
void |
setBoard(int[] board,
int bwid,
int bhei)
Sets the board data and board dimensions. |
boolean |
setPiece(int col,
int row,
int piece)
Sets the piece at the given coordinates. |
void |
setRect(int x,
int y,
int width,
int height,
int piece)
Sets the pieces within the specified rectangle to the given piece. |
void |
setSegment(int dir,
int col,
int row,
int[] pieces)
Sets the pieces in the given board segment to the specified pieces. |
boolean |
setSegment(int dir,
int col,
int row,
int len,
int piece)
Sets the pieces in the given board segment to the specified piece. |
int |
size()
Returns the size of the board in pieces. |
String |
toString()
|
| Methods inherited from class com.threerings.puzzle.data.Board |
|---|
getRandom, getSeedForEvent, initializeSeed, isSeedingEvent, populate, seedFromEvent |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int RADIAL_ROTATION
public static final int INPLACE_ROTATION
public static final DropBoard.PieceOperation CLEAR_OP
protected int[] _board
protected int _bwid
protected int _bhei
protected transient Rectangle _bounds
protected static final int[][][] ROTATE_DX
protected static final int[][][] ROTATE_DY
protected static final int[] ORIENT_WIDTHS
protected static final int[] ORIENT_HEIGHTS
protected static final int[] ORIENT_ORIGIN_DX
protected static final int[] ORIENT_ORIGIN_DY
protected static final int[] COERCE_DX
protected static final DropBoard.SetSegmentOperation _setSegmentOp
protected static final DropBoard.SetPieceOperation _setPieceOp
protected static final int DEFAULT_PAD_WIDTH
| Constructor Detail |
|---|
public DropBoard()
public DropBoard(int bwid,
int bhei)
public DropBoard(int bwid,
int bhei,
int piece)
public DropBoard(int[] board,
int bwid,
int bhei)
| Method Detail |
|---|
public int getWidth()
public int getHeight()
public int getPiece(int col,
int row)
public int getNextPiece()
public int getDropDistance(int col,
int row)
DropPieceCodes.PIECE_NONE).
public boolean isRowEmpty(int row)
public boolean isValidDrop(int[] rows,
int[] cols,
float pctdone)
public boolean inBounds(int col,
int row)
public boolean isBlockEmpty(int col,
int row,
int wid,
int hei)
col - the left coordinate of the block.row - the bottom coordinate of the block.wid - the width of the block.hei - the height of the block.
public int[] getForgivingRotation(int[] rows,
int[] cols,
int orient,
int dir,
int rtype,
float pctdone,
boolean canPopup)
(orient,
col, row, popped), where orient is the final orientation of the drop
block; col and row are the final column and row coordinates,
respectively, of the central drop block piece. popped will be set to 1 if the
piece was popped up, 0 otherwise.
public Point getForgivingMove(int col,
int row,
int wid,
int hei,
int dx,
int dy,
float pctdone)
Point object containing the coordinates to place the bottom-left of the
given block at after moving it the given distance on the x- and y-axes, or
null if the move is not valid. Note that only the final block position is
checked.
col - the leftmost column of the block.row - the bottommost row of the block.wid - the width of the block.hei - the height of the block.dx - the distance to move the block in columns.dy - the distance to move the block in rows.pctdone - the percentage of the inter-block distance that the piece has fallen thus
far.public void getColumnLevels(byte[] columns)
public void applyRisingPieces(int[] pieces)
DropControllerDelegate when it's time to apply a rising row of pieces
to the board. Shifts all of the pieces in the given board up one row and places the given
row of pieces at the bottom of the board.
public boolean rowContainsPieces(int row,
int blankPiece)
row - the row to check for pieces.blankPiece - the blank piece value, non-instances of which will be sought.public void fill(int piece)
public boolean setPiece(int col,
int row,
int piece)
public void setRect(int x,
int y,
int width,
int height,
int piece)
public boolean setSegment(int dir,
int col,
int row,
int len,
int piece)
dir - the direction of the segment; one of DirectionCodes.HORIZONTAL or DirectionCodes.VERTICAL.col - the starting column of the segment.row - the starting row of the segment.len - the length of the segment in pieces.piece - the piece to set in the segment.
public void setSegment(int dir,
int col,
int row,
int[] pieces)
dir - the direction of the segment; one of DirectionCodes.HORIZONTAL or DirectionCodes.VERTICAL.col - the starting column of the segment.row - the starting row of the segment.pieces - the pieces to set in the segment.
public void applyOp(int dir,
int col,
int row,
DropBoard.PieceOperation op)
DropBoard.PieceOperation to all pieces in the specified row or column
starting at the specified coordinates and spanning the remainder of the row or column
(depending on the application direction) in the board.
dir - the direction to iterate in; one of DirectionCodes.HORIZONTAL or DirectionCodes.VERTICAL.col - the starting column of the segment.row - the starting row of the segment.op - the piece operation to apply to each piece.
public void applyOp(int dir,
int col,
int row,
int len,
DropBoard.PieceOperation op)
DropBoard.PieceOperation to all pieces in a row or column segment
starting at the specified coordinates and of the specified length in the board.
dir - the direction to iterate in; one of DirectionCodes.HORIZONTAL or DirectionCodes.VERTICAL.col - the starting leftmost column of the segment.row - the starting bottommost row of the segment.len - the number of pieces in the segment.op - the piece operation to apply to each piece.
public void applyOp(int col,
int row,
DropBoard.PieceOperation op)
DropBoard.PieceOperation to the specified piece in the board.
col - the column of the piece.row - the row of the piece.op - the piece operation to apply to the piece.public void dump()
Board
dump in class Boardpublic void dumpAndCompare(Board other)
Board
dumpAndCompare in class Boardpublic String toString()
toString in class Objectpublic boolean equals(Board other)
Board
equals in class Board
public boolean isValidPosition(int x,
int y)
public Rectangle getBounds()
public int size()
public void copyInto(DropBoard board)
public int[] getBoard()
public void setBoard(int[] board,
int bwid,
int bhei)
public void setBoard(int[] board)
public DropBoard clone()
clone in class Board
protected int coordsToIndex(int col,
int row)
protected int indexToCol(int idx)
protected int indexToRow(int idx)
protected int getPadWidth()
protected String formatPiece(int piece)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||