chesspresso
Class Chess

java.lang.Object
  |
  +--chesspresso.Chess

public abstract class Chess
extends java.lang.Object

General chess-specific definition.

The following methods are used often throughout the higher-level classes and are therefore implemented as simple as possible. Sometimes, checking for illegal arguments is left to the caller for optimized performance.

To del with squares, the concepts of square, column, and row index are introduced. A square index is a number our of [0..63], a column (file) and row (rank) are out of [0..7].

A piece is an uncolored type of chessman, a stone is a piece plus a colored. For instance, possible pieces would be: a knight, a pawn, a king. Possible stones are: a white queen, a black pawn. Possible colors (or players) are: white, black and nobody.

Version:
$Revision: 1.2 $
Author:
Bernhard Seybold

Field Summary
static int A1
           
static int A2
           
static int A3
           
static int A4
           
static int A5
           
static int A6
           
static int A7
           
static int A8
           
static int B1
           
static int B2
           
static int B3
           
static int B4
           
static int B5
           
static int B6
           
static int B7
           
static int B8
           
static short BISHOP
           
static int BLACK
           
static short BLACK_BISHOP
           
static short BLACK_KING
           
static short BLACK_KNIGHT
           
static short BLACK_PAWN
           
static short BLACK_QUEEN
           
static short BLACK_ROOK
           
static int C1
           
static int C2
           
static int C3
           
static int C4
           
static int C5
           
static int C6
           
static int C7
           
static int C8
           
static int D1
           
static int D2
           
static int D3
           
static int D4
           
static int D5
           
static int D6
           
static int D7
           
static int D8
           
static int E1
           
static int E2
           
static int E3
           
static int E4
           
static int E5
           
static int E6
           
static int E7
           
static int E8
           
static int F1
           
static int F2
           
static int F3
           
static int F4
           
static int F5
           
static int F6
           
static int F7
           
static int F8
           
static int G1
           
static int G2
           
static int G3
           
static int G4
           
static int G5
           
static int G6
           
static int G7
           
static int G8
           
static int H1
           
static int H2
           
static int H3
           
static int H4
           
static int H5
           
static int H6
           
static int H7
           
static int H8
           
static short KING
           
static short KNIGHT
           
static short MAX_PIECE
           
static short MAX_STONE
           
static short MIN_PIECE
           
static short MIN_STONE
           
static int NO_COL
           
static short NO_PIECE
           
static int NO_RES
           
static int NO_ROW
           
static int NO_SQUARE
           
static short NO_STONE
           
static int NOBODY
           
static int NUM_OF_COLS
           
static int NUM_OF_ROWS
           
static int NUM_OF_SQUARES
           
static short PAWN
           
static char[] pieceChars
           
static short QUEEN
           
static int RES_BLACK_WINS
           
static int RES_DRAW
           
static int RES_NOT_FINISHED
           
static int RES_WHITE_WINS
           
static short ROOK
           
static int WHITE
           
static short WHITE_BISHOP
           
static short WHITE_KING
           
static short WHITE_KNIGHT
           
static short WHITE_PAWN
           
static short WHITE_QUEEN
           
static short WHITE_ROOK
           
 
Constructor Summary
Chess()
           
 
Method Summary
static int charToCol(char ch)
          Returns the column represented by the character.
static int charToPiece(char ch)
          Converts a character to a piece.
static int charToRow(char ch)
          Returns the row represented by the character.
static char colToChar(int col)
          Returns the character of a column (file): 'a'..'
static int coorToSqi(int col, int row)
          Converts coordinates to square index.
static int deltaCol(int sqi1, int sqi2)
          Returns the column difference from one square index to the other.
static int deltaRow(int sqi1, int sqi2)
          Returns the row difference from one square index to the other.
static int getOpponentStone(int stone)
          Change the color of the stone.
static boolean isWhitePly(int plyNumber)
          Returns whether it is white move at the given ply.
static boolean isWhiteSquare(int sqi)
          Returns whether the square is white.
static int otherPlayer(int player)
          Returns the opposite player.
static char pieceToChar(int piece)
          Returns a character representing the piece.
static int pieceToStone(int piece, int color)
          Converts a piece, color pair to a stone.
static int plyToMoveNumber(int plyNumber)
          Converts a ply to a move number
static char rowToChar(int row)
          Returns the character of a row (rank): '1'..'8'.
static int sqiToCol(int sqi)
          Extract the column of a square index.
static int sqiToRow(int sqi)
          Extract the row of a square index.
static java.lang.String sqiToStr(int sqi)
          Returns the algebraic representation of a square "a1".."
static boolean stoneHasColor(int stone, int color)
          Check whether the stone is of a certain color.
static char stoneToChar(int stone)
          Returns a character representing the stone.
static int stoneToColor(int stone)
          Extracts the color of a stone.
static int stoneToPiece(int stone)
          Converts a stone to a piece (remove color info).
static int strToSqi(char colCh, char rowCh)
          Converts a col and row character pair to a square index.
static int strToSqi(java.lang.String s)
          Converts a square representation to a square index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_OF_COLS

public static final int NUM_OF_COLS
See Also:
Constant Field Values

NUM_OF_ROWS

public static final int NUM_OF_ROWS
See Also:
Constant Field Values

NUM_OF_SQUARES

public static final int NUM_OF_SQUARES
See Also:
Constant Field Values

RES_WHITE_WINS

public static final int RES_WHITE_WINS
See Also:
Constant Field Values

RES_DRAW

public static final int RES_DRAW
See Also:
Constant Field Values

RES_BLACK_WINS

public static final int RES_BLACK_WINS
See Also:
Constant Field Values

RES_NOT_FINISHED

public static final int RES_NOT_FINISHED
See Also:
Constant Field Values

NO_RES

public static final int NO_RES
See Also:
Constant Field Values

A8

public static final int A8
See Also:
Constant Field Values

B8

public static final int B8
See Also:
Constant Field Values

C8

public static final int C8
See Also:
Constant Field Values

D8

public static final int D8
See Also:
Constant Field Values

E8

public static final int E8
See Also:
Constant Field Values

F8

public static final int F8
See Also:
Constant Field Values

G8

public static final int G8
See Also:
Constant Field Values

H8

public static final int H8
See Also:
Constant Field Values

A7

public static final int A7
See Also:
Constant Field Values

B7

public static final int B7
See Also:
Constant Field Values

C7

public static final int C7
See Also:
Constant Field Values

D7

public static final int D7
See Also:
Constant Field Values

E7

public static final int E7
See Also:
Constant Field Values

F7

public static final int F7
See Also:
Constant Field Values

G7

public static final int G7
See Also:
Constant Field Values

H7

public static final int H7
See Also:
Constant Field Values

A6

public static final int A6
See Also:
Constant Field Values

B6

public static final int B6
See Also:
Constant Field Values

C6

public static final int C6
See Also:
Constant Field Values

D6

public static final int D6
See Also:
Constant Field Values

E6

public static final int E6
See Also:
Constant Field Values

F6

public static final int F6
See Also:
Constant Field Values

G6

public static final int G6
See Also:
Constant Field Values

H6

public static final int H6
See Also:
Constant Field Values

A5

public static final int A5
See Also:
Constant Field Values

B5

public static final int B5
See Also:
Constant Field Values

C5

public static final int C5
See Also:
Constant Field Values

D5

public static final int D5
See Also:
Constant Field Values

E5

public static final int E5
See Also:
Constant Field Values

F5

public static final int F5
See Also:
Constant Field Values

G5

public static final int G5
See Also:
Constant Field Values

H5

public static final int H5
See Also:
Constant Field Values

A4

public static final int A4
See Also:
Constant Field Values

B4

public static final int B4
See Also:
Constant Field Values

C4

public static final int C4
See Also:
Constant Field Values

D4

public static final int D4
See Also:
Constant Field Values

E4

public static final int E4
See Also:
Constant Field Values

F4

public static final int F4
See Also:
Constant Field Values

G4

public static final int G4
See Also:
Constant Field Values

H4

public static final int H4
See Also:
Constant Field Values

A3

public static final int A3
See Also:
Constant Field Values

B3

public static final int B3
See Also:
Constant Field Values

C3

public static final int C3
See Also:
Constant Field Values

D3

public static final int D3
See Also:
Constant Field Values

E3

public static final int E3
See Also:
Constant Field Values

F3

public static final int F3
See Also:
Constant Field Values

G3

public static final int G3
See Also:
Constant Field Values

H3

public static final int H3
See Also:
Constant Field Values

A2

public static final int A2
See Also:
Constant Field Values

B2

public static final int B2
See Also:
Constant Field Values

C2

public static final int C2
See Also:
Constant Field Values

D2

public static final int D2
See Also:
Constant Field Values

E2

public static final int E2
See Also:
Constant Field Values

F2

public static final int F2
See Also:
Constant Field Values

G2

public static final int G2
See Also:
Constant Field Values

H2

public static final int H2
See Also:
Constant Field Values

A1

public static final int A1
See Also:
Constant Field Values

B1

public static final int B1
See Also:
Constant Field Values

C1

public static final int C1
See Also:
Constant Field Values

D1

public static final int D1
See Also:
Constant Field Values

E1

public static final int E1
See Also:
Constant Field Values

F1

public static final int F1
See Also:
Constant Field Values

G1

public static final int G1
See Also:
Constant Field Values

H1

public static final int H1
See Also:
Constant Field Values

NO_COL

public static final int NO_COL
See Also:
Constant Field Values

NO_ROW

public static final int NO_ROW
See Also:
Constant Field Values

NO_SQUARE

public static final int NO_SQUARE
See Also:
Constant Field Values

MIN_PIECE

public static final short MIN_PIECE
See Also:
Constant Field Values

MAX_PIECE

public static final short MAX_PIECE
See Also:
Constant Field Values

KING

public static final short KING
See Also:
Constant Field Values

PAWN

public static final short PAWN
See Also:
Constant Field Values

QUEEN

public static final short QUEEN
See Also:
Constant Field Values

ROOK

public static final short ROOK
See Also:
Constant Field Values

BISHOP

public static final short BISHOP
See Also:
Constant Field Values

KNIGHT

public static final short KNIGHT
See Also:
Constant Field Values

NO_PIECE

public static final short NO_PIECE
See Also:
Constant Field Values

MIN_STONE

public static final short MIN_STONE
See Also:
Constant Field Values

MAX_STONE

public static final short MAX_STONE
See Also:
Constant Field Values

WHITE_KING

public static final short WHITE_KING
See Also:
Constant Field Values

WHITE_PAWN

public static final short WHITE_PAWN
See Also:
Constant Field Values

WHITE_QUEEN

public static final short WHITE_QUEEN
See Also:
Constant Field Values

WHITE_ROOK

public static final short WHITE_ROOK
See Also:
Constant Field Values

WHITE_BISHOP

public static final short WHITE_BISHOP
See Also:
Constant Field Values

WHITE_KNIGHT

public static final short WHITE_KNIGHT
See Also:
Constant Field Values

BLACK_KING

public static final short BLACK_KING
See Also:
Constant Field Values

BLACK_PAWN

public static final short BLACK_PAWN
See Also:
Constant Field Values

BLACK_QUEEN

public static final short BLACK_QUEEN
See Also:
Constant Field Values

BLACK_ROOK

public static final short BLACK_ROOK
See Also:
Constant Field Values

BLACK_BISHOP

public static final short BLACK_BISHOP
See Also:
Constant Field Values

BLACK_KNIGHT

public static final short BLACK_KNIGHT
See Also:
Constant Field Values

NO_STONE

public static final short NO_STONE
See Also:
Constant Field Values

pieceChars

public static final char[] pieceChars

WHITE

public static final int WHITE
See Also:
Constant Field Values

BLACK

public static final int BLACK
See Also:
Constant Field Values

NOBODY

public static final int NOBODY
See Also:
Constant Field Values
Constructor Detail

Chess

public Chess()
Method Detail

coorToSqi

public static final int coorToSqi(int col,
                                  int row)
Converts coordinates to square index.

Parameters:
col - the column (file)
row - the row (rank)
Returns:
the square index

sqiToRow

public static final int sqiToRow(int sqi)
Extract the row of a square index.

Parameters:
sqi - the square index
Returns:
the row

sqiToCol

public static final int sqiToCol(int sqi)
Extract the column of a square index.

Parameters:
sqi - the square index
Returns:
the column

deltaRow

public static final int deltaRow(int sqi1,
                                 int sqi2)
Returns the row difference from one square index to the other.

Parameters:
sqi1 - the one square index
sqi2 - the other square index
Returns:
the row difference from sqi1 to sqi2

deltaCol

public static final int deltaCol(int sqi1,
                                 int sqi2)
Returns the column difference from one square index to the other.

Parameters:
sqi1 - the one square index
sqi2 - the other square index
Returns:
the column difference from sqi1 to sqi2

colToChar

public static final char colToChar(int col)
Returns the character of a column (file): 'a'..'h'.

Parameters:
col - the column
Returns:
the character representing the column

rowToChar

public static final char rowToChar(int row)
Returns the character of a row (rank): '1'..'8'.

Returns:
the character representing the column

sqiToStr

public static final java.lang.String sqiToStr(int sqi)
Returns the algebraic representation of a square "a1".."h8".

Parameters:
sqi - the square
Returns:
the algebraic representation

isWhiteSquare

public static final boolean isWhiteSquare(int sqi)
Returns whether the square is white.

Parameters:
sqi - the square
Returns:
whether sqi is a white square

charToCol

public static final int charToCol(char ch)
Returns the column represented by the character.

Parameters:
ch - the column character ('a'..'h')
Returns:
the column, or NO_COL if an illegal character is passed

charToRow

public static final int charToRow(char ch)
Returns the row represented by the character.

Parameters:
ch - the row character ('1'..'8')
Returns:
the column, or NO_ROW if an illegal character is passed

strToSqi

public static final int strToSqi(java.lang.String s)
Converts a square representation to a square index.

Parameters:
s - the algebraic square representation
Returns:
the square index, or NO_SQUARE if an illegal string is passed

strToSqi

public static final int strToSqi(char colCh,
                                 char rowCh)
Converts a col and row character pair to a square index.

Returns:
the square index, or NO_SQUARE if an illegal character is passed

stoneToColor

public static final int stoneToColor(int stone)
Extracts the color of a stone.

Parameters:
stone - the colored piece
Returns:
the color of the stone

stoneHasColor

public static final boolean stoneHasColor(int stone,
                                          int color)
Check whether the stone is of a certain color.

Parameters:
stone - the colored piece
color - the color to test for
Returns:
the true iff the stone is of the given color

stoneToPiece

public static final int stoneToPiece(int stone)
Converts a stone to a piece (remove color info).

Parameters:
stone - the colored piece
Returns:
the piece

getOpponentStone

public static final int getOpponentStone(int stone)
Change the color of the stone.

Parameters:
stone - the colored piece
Returns:
the stone with inverse color

charToPiece

public static final int charToPiece(char ch)
Converts a character to a piece.

Parameters:
ch - a piece character
Returns:
the piece represented by the character, or NO_PIECE if illegal

pieceToChar

public static final char pieceToChar(int piece)
Returns a character representing the piece.

Parameters:
piece - the piece
Returns:
the character representing the piece, or '?' if an illegal piece is passed

stoneToChar

public static final char stoneToChar(int stone)
Returns a character representing the stone.

Parameters:
stone - the stone
Returns:
the character representing the stone, or '?' if an illegal piece is passed

pieceToStone

public static final int pieceToStone(int piece,
                                     int color)
Converts a piece, color pair to a stone.

Parameters:
piece - the piece
color - the color
Returns:
the stone, or NO_PIECE if illegal

otherPlayer

public static final int otherPlayer(int player)
Returns the opposite player.

Parameters:
player - the player (or color)
Returns:
the opposite player (color respectively)

isWhitePly

public static boolean isWhitePly(int plyNumber)
Returns whether it is white move at the given ply.

Parameters:
plyNumber - the ply number, starting at 0

plyToMoveNumber

public static int plyToMoveNumber(int plyNumber)
Converts a ply to a move number

Parameters:
plyNumber - the ply number, starting at 0