We do that math a lot, so make helpers & trust the compiler to optimize.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@981 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -130,7 +130,7 @@ public class DropBoard extends Board
|
|||||||
public int getPiece (int col, int row)
|
public int getPiece (int col, int row)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return _board[(row*_bwid) + col];
|
return _board[coordsToIndex(col, row)];
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warning("Failed getting piece", "col", col, "row", row, e);
|
log.warning("Failed getting piece", "col", col, "row", row, e);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -413,7 +413,7 @@ public class DropBoard extends Board
|
|||||||
public boolean setPiece (int col, int row, int piece)
|
public boolean setPiece (int col, int row, int piece)
|
||||||
{
|
{
|
||||||
if (col >= 0 && row >= 0 && col < _bwid && row < _bhei) {
|
if (col >= 0 && row >= 0 && col < _bwid && row < _bhei) {
|
||||||
_board[(row*_bwid) + col] = piece;
|
_board[coordsToIndex(col, row)] = piece;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -676,7 +676,7 @@ public class DropBoard extends Board
|
|||||||
*/
|
*/
|
||||||
public void setBoard (int[] board)
|
public void setBoard (int[] board)
|
||||||
{
|
{
|
||||||
int size = (_bwid*_bhei);
|
int size = size();
|
||||||
if (board.length < size) {
|
if (board.length < size) {
|
||||||
log.warning("Attempt to set board with invalid data size",
|
log.warning("Attempt to set board with invalid data size",
|
||||||
"len", board.length, "expected", size);
|
"len", board.length, "expected", size);
|
||||||
@@ -694,6 +694,30 @@ public class DropBoard extends Board
|
|||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from column & row to an index into our board array.
|
||||||
|
*/
|
||||||
|
protected int coordsToIndex (int col, int row)
|
||||||
|
{
|
||||||
|
return (row * _bwid) + col;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an index into our board array to a column.
|
||||||
|
*/
|
||||||
|
protected int indexToCol (int idx)
|
||||||
|
{
|
||||||
|
return idx % _bwid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an index into our board array to a row.
|
||||||
|
*/
|
||||||
|
protected int indexToRow (int idx)
|
||||||
|
{
|
||||||
|
return idx / _bwid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of characters to which a single piece should be padded when dumping the
|
* Returns the number of characters to which a single piece should be padded when dumping the
|
||||||
* board for debugging purposes.
|
* board for debugging purposes.
|
||||||
|
|||||||
Reference in New Issue
Block a user