rules
Class Piece

java.lang.Object
  extended by rules.Piece

public final class Piece
extends java.lang.Object

This is the piece object, this object contains a hexadecimal location, piece type and colour. Once you instantiate a piece object, it is considered immutable, that means, the contents cannot be changed. You must reassign your variables to achieve the desired effect, like with a string.

Author:
Spork Innovation Technologies

Field Summary
static byte BISHOP
          The identifier for bishops.
static byte BLACK
          The colour/side identifier for black pieces.
static byte KING
          The identifier for the king.
static byte KNIGHT
          The identifier for knights.
static byte NULL
          The identifier for the null piece.
static byte NULL_COL
          The colour/side identifier for null pieces.
static int NUM_SIDES
          The number of players in the game.
static byte PAWN
          The identifier for pawns.
static byte QUEEN
          The identifier for the queen.
static byte ROOK
          The identifier for rooks.
static byte WHITE
          The colour/side identifier for white pieces.
 
Constructor Summary
Piece(byte x88loc, byte ptype, byte colour)
          Makes a piece with the given position 0x88 coordinate and type (and state = true).
 
Method Summary
 Piece destroy()
          Returns the "null piece", or a piece that has no defined colour or piece type.
 boolean exists()
          Returns whether or not the piece is on the board.
 byte getColour()
          Returns the colour of the piece.
static Piece getNullPiece()
          Returns the null piece.
 byte getPosition()
          Returns the position of the piece.
 byte getType()
          Returns the type of the piece as defined by the piece constants above.
 boolean isEqual(Piece other)
          Compares this piece to another piece for equality.
 Piece move(byte difference)
          Moves a piece a 0x88 difference in decimal, that is, the difference between 0x58 and 0x70 is actually not 12.
 Piece move(Move m)
          Applies a Move m to this object.
 java.lang.String toString()
          Returns a string representation of this Piece object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NUM_SIDES

public static final int NUM_SIDES
The number of players in the game.

See Also:
Constant Field Values

WHITE

public static final byte WHITE
The colour/side identifier for white pieces.

See Also:
Constant Field Values

BLACK

public static final byte BLACK
The colour/side identifier for black pieces.

See Also:
Constant Field Values

NULL_COL

public static final byte NULL_COL
The colour/side identifier for null pieces.

See Also:
Constant Field Values

PAWN

public static final byte PAWN
The identifier for pawns.

See Also:
Constant Field Values

ROOK

public static final byte ROOK
The identifier for rooks.

See Also:
Constant Field Values

KNIGHT

public static final byte KNIGHT
The identifier for knights.

See Also:
Constant Field Values

BISHOP

public static final byte BISHOP
The identifier for bishops.

See Also:
Constant Field Values

QUEEN

public static final byte QUEEN
The identifier for the queen.

See Also:
Constant Field Values

KING

public static final byte KING
The identifier for the king.

See Also:
Constant Field Values

NULL

public static final byte NULL
The identifier for the null piece.

See Also:
Constant Field Values
Constructor Detail

Piece

public Piece(byte x88loc,
             byte ptype,
             byte colour)
Makes a piece with the given position 0x88 coordinate and type (and state = true).

Parameters:
x88loc - the 0x88 location of the piece.
ptype - the type of the piece (pawn, knight, etc..) according to the constants.
colour - the colour of the piece.
Method Detail

exists

public boolean exists()
Returns whether or not the piece is on the board.

Returns:
Whether or not the piece is on the board.

getColour

public byte getColour()
Returns the colour of the piece.

Returns:
the colour of the piece.

getPosition

public byte getPosition()
Returns the position of the piece.

Returns:
the position of the piece.

getType

public byte getType()
Returns the type of the piece as defined by the piece constants above.

Returns:
the type of the piece.

move

public Piece move(byte difference)
Moves a piece a 0x88 difference in decimal, that is, the difference between 0x58 and 0x70 is actually not 12. It's 18. You need to put 18 for this method to work properly. Also, like Strings, you MUST reassign your variable, ex. Piece p = new Piece (32, 4, 3); p = p.move (15) Note: You can actually move your piece out of the board. Just use the exists() method to test whether or not it is out of the board.

Parameters:
difference - between the squares in decimal.
Returns:
A new Piece of the same type and colour, but a different location.

move

public Piece move(Move m)
Applies a Move m to this object. This returns a new object with the move applied to it. This means you must reassign your variable.


destroy

public Piece destroy()
Returns the "null piece", or a piece that has no defined colour or piece type. You must reassign to get this effect. ex. Piece p = new Piece (32, 4, 3); p = p.destroy();

Returns:
The null piece.

getNullPiece

public static Piece getNullPiece()
Returns the null piece. A piece that has no valid colour or type and at a non-existent location.

Returns:
The null piece.

isEqual

public boolean isEqual(Piece other)
Compares this piece to another piece for equality.

Parameters:
otherPiece - The piece to be compared to.
Returns:
True if every aspect is the same, false otherwise.

toString

public java.lang.String toString()
Returns a string representation of this Piece object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this Piece object.