All Packages Class Hierarchy This Package Previous Next Index
Class kpalin.alabra.ChessPlay
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----kpalin.alabra.ChessPlay
- public class ChessPlay
- extends Panel
- implements MouseListener, ChessCtrlCallback
This is the key class of the whole program. This is attached on
application window or an applet panel and the whole chess stuff is
under this class.
- Author:
- Kimmo Palin
-
canFortify
- Possibility of fortification.
-
checkBlockers
- This is the data about tiles that can be moved to block a check.
-
ctrl
- The panel that holds all control etc.
-
grid
- The panel that holds the chess board.
-
initSet
- Initial settings got with an implementation specific way.
-
pPromotion
- This is an instance of pawn promotion dialog.
-
prevTarget
- The previous move.
-
processClicks
- Process click-events.
-
startTile
- The tile where is the piece to be moved.
-
whosTurn
- Whos turn is it?.
-
ChessPlay(ChessSettings)
- Creates new chess play object.
-
actionPerformed(ActionEvent)
- Listens for the reset button on ctrlPanel.
-
blocksThreatAt(int, BoardTile)
- An assistant method to validate moves.
-
blocksThreatAt(int, int, BoardTile)
- An assistant method to validate moves.
-
canBishopMove(BoardTile)
- Checks if bishop on the tile can move.
-
canKingMove(BoardTile)
- Checks if king on the tile can move.
-
canKnightMove(BoardTile)
- Checks if knight on the tile can move.
-
canMove(BoardTile)
- Checks if a piece in specific tile can move.
-
canPawnMove(BoardTile)
- Checks if pawn on the tile can move.
-
canQueenMove(BoardTile)
- Checks if queen on the tile can move.
-
canRookMove(BoardTile)
- Checks if rook on the tile can move.
-
canSideMove(int)
- Checks if specified player can move any pieces.
-
canSimpleMove(BoardTile, int, int[][])
- This checks if bishop,knight,rook or queen can move.
-
changeTurn()
- Takes care of the boring routines when we change turn.
-
checkForMate(int)
- Checks if side is on mate.
-
finishPromotion(PromotionListen)
- Finalizes the pawn promotion.
-
gameOver(int)
- Sets the game to game over-state.
-
getNChecks(int, int, BoardTile)
- Finds all checks.
-
isCheckPos(int, BoardTile)
- Checks for checks.
-
killAll()
- Tries to clean up after stoping applet.
-
knightThreat(Vector, int, int, BoardTile)
- Checks for threatening knights.
-
makeMove(BoardTile, BoardTile)
- Validate and make the move.
-
mouseClicked(MouseEvent)
- This is the callback method for the BoardTiles.
-
mouseEntered(MouseEvent)
-
-
mouseExited(MouseEvent)
-
-
mousePressed(MouseEvent)
-
-
mouseReleased(MouseEvent)
-
-
movePiece(BoardTile, BoardTile)
- Moves the piece to target without any
checking of validity of the move.
-
movePiece(BoardTile, BoardTile, Piece)
- Moves the piece to target without any
checking of validity of the move.
-
otherThreat(Vector, int, int, BoardTile)
- Checks for threatening rooks, bishops, and queen.
-
pause()
- Pause the timers.
-
pawnThreat(Vector, int, int, BoardTile)
- Checks for threatening pawns.
-
promotePawn(int, BoardTile, BoardTile)
- Starts pawnPromotion procedure.
-
recordGameOver(int)
- Adds result of the game to movelist, if game is over.
-
resetGame()
- Reset the game
-
unpause()
- Unpause the timers.
-
update(Observable, Object)
- Listener for pawn promotion.
-
validBishopMove(BoardTile, BoardTile)
- Checks the validity of a move for a Bishop.
-
validEnPassant(BoardTile, BoardTile)
- Checks validity of en'passant-move
-
validFort(BoardTile, BoardTile)
- Checks the validity of a fortification.
-
validKingMove(BoardTile, BoardTile)
- Checks the validity of a move for a King.
-
validKnightMove(BoardTile, BoardTile)
- Checks the validity of a move for a Knight.
-
validPawnMove(BoardTile, BoardTile)
- Checks the validity of a move for a Pawn.
-
validQueenMove(BoardTile, BoardTile)
- Checks the validity of a move for a Queen.
-
validRookMove(BoardTile, BoardTile)
- Checks the validity of a move for a Rook.
-
validStraightMove(BoardTile, int, int, int)
- This is a helpper method for pieces that move straight lines and
diagonals.
-
whoCanBlock(BoardTile, BoardTile, int)
- Finds out the pieces that can come to block a check.
grid
private BoardGrid grid
- The panel that holds the chess board.
initSet
private final ChessSettings initSet
- Initial settings got with an implementation specific way.
ctrl
private CtrlPanel ctrl
- The panel that holds all control etc. stuff on the screen.
processClicks
private boolean processClicks
- Process click-events.
whosTurn
private int whosTurn
- Whos turn is it?.
- See Also:
- WHITE, BLACK, GAMEOVER
pPromotion
private PawnPromote pPromotion
- This is an instance of pawn promotion dialog. Set in pawnPromote
and null:ed in update or resetGame.
startTile
private BoardTile startTile
- The tile where is the piece to be moved. Not really good place
for this stuff but can't help it. Only mouseClicked can use this!
- See Also:
- mouseClicked
prevTarget
private BoardTile prevTarget
- The previous move. This is needed for the en'passant.
canFortify
private boolean canFortify[][]
- Possibility of fortification. Left dimension is Piece.WHITE or
Piece.Black, right Piece.LONGFORT or Piece.SHORTFORT
checkBlockers
private Vector checkBlockers
- This is the data about tiles that can be moved to block a check.
If there is no current threat, this will be null.
ChessPlay
ChessPlay(ChessSettings set)
- Creates new chess play object.
resetGame
public void resetGame()
- Reset the game
promotePawn
void promotePawn(int side,
BoardTile from,
BoardTile to)
- Starts pawnPromotion procedure. This is a bit dirty because
we have to artificially block input to ChessPlay as long
as this goes on. The control is returned to ChessPlay
after update.
- See Also:
- update
update
public void update(Observable o,
Object arg)
- Listener for pawn promotion.
- Parameters:
- o - the observable object
- arg - an argument (not used)
finishPromotion
private void finishPromotion(PromotionListen plisten)
- Finalizes the pawn promotion.
- Parameters:
- plisten - The communication object towards PawnPromotion.
actionPerformed
public void actionPerformed(ActionEvent e)
- Listens for the reset button on ctrlPanel.
mouseEntered
public void mouseEntered(MouseEvent e)
mouseExited
public void mouseExited(MouseEvent e)
mousePressed
public void mousePressed(MouseEvent e)
mouseReleased
public void mouseReleased(MouseEvent e)
mouseClicked
public void mouseClicked(MouseEvent e)
- This is the callback method for the BoardTiles. This is the best
place for this because it needs connections to ctrl (change turn)
and grid (information about the board status)
checkForMate
private boolean checkForMate(int side)
- Checks if side is on mate.
- Parameters:
- side - Side which can be on mate.
- Returns:
- true if side is on mate, false if not.
whoCanBlock
private Vector whoCanBlock(BoardTile kingTile,
BoardTile threat,
int limit)
- Finds out the pieces that can come to block a check.
- Parameters:
- kingTile - The tile where's the threatend king
- threat - The tile where is the agressor. (Piece must be there)
- limit - if >0 return max limit threats <=0 return all threats.
- Returns:
- Vector of the tiles from where pieces can come blocking. (not null)
changeTurn
private void changeTurn()
- Takes care of the boring routines when we change turn.
makeMove
private void makeMove(BoardTile from,
BoardTile target)
- Validate and make the move.
- Parameters:
- from - The tile where the move starts.
- target - The target tile where to move the piece.
killAll
public void killAll()
- Tries to clean up after stoping applet.
blocksThreatAt
private BoardTile blocksThreatAt(int side,
BoardTile tile)
- An assistant method to validate moves. Analyses how a piece in a
specific tile blocks threats to king. The return tile is always
in (1,1)-(-1,-1) box near the given tile.
- Parameters:
- side - The moving side.
- tile - The tile whose blocking we're analyzing.
No need to have piece in here.
- Returns:
- null if piece in tile doesn't block any threats, otherwise
the tile in the direction of the threat.
blocksThreatAt
private BoardTile blocksThreatAt(int side,
int jumpcount,
BoardTile tile)
- An assistant method to validate moves. Analyses how a piece in a
specific tile is possibly blocking threats to king. The return tile
is always in (1,1)-(-1,-1) box near the given tile.
- Parameters:
- side - The moving side.
- jumpcount - Number of pieces +1 that can be between king and threat.
- tile - The tile whose blocking we're analyzing.
No need to have piece in here.
- Returns:
- null if piece in tile doesn't block any threats, otherwise
the tile in the direction of the threat.
validEnPassant
private boolean validEnPassant(BoardTile from,
BoardTile target)
- Checks validity of en'passant-move
- Parameters:
- from - Tile where the move starts. Here must be a piece.
- target - Tile where player is moving a piece.
validPawnMove
private boolean validPawnMove(BoardTile from,
BoardTile target)
- Checks the validity of a move for a Pawn.
- Parameters:
- target - The target tile.
validBishopMove
private boolean validBishopMove(BoardTile from,
BoardTile target)
- Checks the validity of a move for a Bishop.
- Parameters:
- from - Starting tile of the move.
- target - The target tile.
knightThreat
private void knightThreat(Vector baddies,
int side,
int count,
BoardTile kingPos)
- Checks for threatening knights.
- Parameters:
- baddies - A vector where to add the threats.
- side - The kings side. (Piece.WHITE or Piece.BLACK)
- kingPos - The tile whose threat to analyse. (note: no need for a
King to be in this tile.)
- count - Maximum number of threat-tiles to return
pawnThreat
private void pawnThreat(Vector baddies,
int side,
int count,
BoardTile kingPos)
- Checks for threatening pawns.
- Parameters:
- baddies - A vector where to add the threats.
- side - The kings side. (Piece.WHITE or Piece.BLACK)
- kingPos - The tile whose threat to analyse. (note: no need for a
King to be in this tile.)
- count - Maximum number of threat-tiles to return
otherThreat
private void otherThreat(Vector baddies,
int side,
int count,
BoardTile kingPos)
- Checks for threatening rooks, bishops, and queen.
- Parameters:
- baddies - A vector where to add the threats.
- side - The kings side. (Piece.WHITE or Piece.BLACK)
- kingPos - The tile whose threat to analyse. (note: no need for a
King to be in this tile.)
- count - Maximum number of threat-tiles to baddies.
getNChecks
private Vector getNChecks(int side,
int count,
BoardTile kingPos)
- Finds all checks.
- Parameters:
- side - The kings side. (Piece.WHITE or Piece.BLACK)
- kingPos - The tile whose threat to analyse. (note: no need for a
King to be in this tile.)
- count - How many threats to return.
- Returns:
- A Vector of threatening BoardTiles. Maximum size count.
isCheckPos
private BoardTile isCheckPos(int side,
BoardTile kingPos)
- Checks for checks.
- Parameters:
- side - The kings side. (Piece.WHITE or Piece.BLACK)
- kingPos - The tile whose threat to analyse. (note: no need for a
King to be in this tile.)
- Returns:
- The tile of the threat or null.
validFort
private boolean validFort(BoardTile from,
BoardTile target)
- Checks the validity of a fortification.
- Parameters:
- from - Starting position of the king.
- target - The target tile.
- Returns:
- true if can move, false if not
validKingMove
private boolean validKingMove(BoardTile from,
BoardTile target)
- Checks the validity of a move for a King.
- Parameters:
- from - Starting position.
- target - The target tile.
- Returns:
- true if can move, false if not
validKnightMove
private boolean validKnightMove(BoardTile from,
BoardTile target)
- Checks the validity of a move for a Knight.
- Parameters:
- target - The target tile.
validQueenMove
private boolean validQueenMove(BoardTile from,
BoardTile target)
- Checks the validity of a move for a Queen.
- Parameters:
- from - Start tile of the move.
- target - The target tile.
validRookMove
private boolean validRookMove(BoardTile from,
BoardTile target)
- Checks the validity of a move for a Rook.
- Parameters:
- target - The target tile.
validStraightMove
private boolean validStraightMove(BoardTile from,
int signx,
int signy,
int delta)
- This is a helpper method for pieces that move straight lines and
diagonals.
- Parameters:
- signx - Direction to move on x acsis.
- singy - Direction to move on y acsis.
- delta - Length of the move. (Measured in (signx,signy))
- Returns:
- true if there's no pieces on the way.
movePiece
private void movePiece(BoardTile from,
BoardTile target)
- Moves the piece to target without any
checking of validity of the move. This also removes eaten piece
in en passant move. The move record is updated here because
this is the only place we have enough information at hand.
- Parameters:
- from - Starting tile of the move.
- target - The target tile where the piece is to be moved.
movePiece
private void movePiece(BoardTile from,
BoardTile target,
Piece promoteTo)
- Moves the piece to target without any
checking of validity of the move. This also removes eaten piece
in en passant move. The move record is updated here because
this is the only place we have enough information at hand.
- Parameters:
- from - Starting tile of the move.
- target - The target tile where the piece is to be moved.
- promoteTo - A piece, to which the moving piece is to be promoted.
null if no promotion.
recordGameOver
private void recordGameOver(int winner)
- Adds result of the game to movelist, if game is over.
- Parameters:
- winner - Side of the winner.
canSideMove
boolean canSideMove(int who)
- Checks if specified player can move any pieces.
- Parameters:
- who - Id of the side who we are looking for.
- Returns:
- true if who can move.
pause
void pause()
- Pause the timers.
unpause
void unpause()
- Unpause the timers. This will start the white's timer if the window
is iconified and deiconified before first move. (good or bad??)
gameOver
private void gameOver(int winner)
- Sets the game to game over-state.
- Parameters:
- winner - Winner of the game or Piece.DRAW
canMove
private boolean canMove(BoardTile tile)
- Checks if a piece in specific tile can move. Note: tile must
contain a piece.
- Parameters:
- tile - Tile on the board, containing a piece.
canSimpleMove
private boolean canSimpleMove(BoardTile tile,
int side,
int cords[][])
- This checks if bishop,knight,rook or queen can move.
- Parameters:
- tile - Tile where the piece is.
- side - Side of the moving piece.
- cords - The coordinates relative to tile, to where the piece can move.
- See Also:
- bishopMoves, knightMoves, rookMoves
canKingMove
private boolean canKingMove(BoardTile tile)
- Checks if king on the tile can move.
- Parameters:
- tile - The tile where the knight is.
- Returns:
- true if can move, false if not.
canKnightMove
boolean canKnightMove(BoardTile tile)
- Checks if knight on the tile can move.
- Parameters:
- tile - The tile where the knight is.
- Returns:
- true if can move, false if not.
canRookMove
boolean canRookMove(BoardTile tile)
- Checks if rook on the tile can move.
- Parameters:
- tile - The tile where the rook is.
- Returns:
- true if can move, false if not.
canQueenMove
boolean canQueenMove(BoardTile tile)
- Checks if queen on the tile can move.
- Parameters:
- tile - The tile where the queen is.
- Returns:
- true if can move, false if not.
canPawnMove
boolean canPawnMove(BoardTile tile)
- Checks if pawn on the tile can move.
- Parameters:
- tile - The tile where the pawn is.
- Returns:
- true if can move, false if not.
canBishopMove
boolean canBishopMove(BoardTile tile)
- Checks if bishop on the tile can move.
- Parameters:
- tile - The tile where the bishop is.
- Returns:
- true if can move, false if not.
All Packages Class Hierarchy This Package Previous Next Index