---------------------------------------------------------------------------
Welcome to the Chessboard component v1.0 for Delphi 2, Delphi 3 and
Borland C++ Builder !

version 1.11 - July 25th 1997
---------------------------------------------------------------------------
Description:

The Chessboard component provides a customizable 2D Chessboard
that can keep track of a game and verify the legality of moves.
It allows the programmer to trap  the following events:

LegalMove, Illegal Move, Capture, En Passant, Castling, Promotion,
Check, Mate, Stale Mate and Only Two Kings Left.

The colors, size, Pieces and Squares can be customized. The component
can be resized at runtime.

The Chessboard component comes with three files:
Chess.cpp (source file), Chess.h (header file) and Chess.txt
(current file).

---------------------------------------------------------------------------
Installation of the component:

Start Delphi2, Delphi3 or Borland C++ Builder.
Select "Component", "Install" ,"Add" and
"Browse" and then browse to the file CHESS.PAS. The component will
appear on a new tab called Chess.
Note: Borland C++ Builder users can also choose for CHESS.CPP
---------------------------------------------------------------------------
Product History:

version 1.11 - July 25th 1997
     * Small bug in PAS file did not allow compiling of the component.
version 1.1 - July 23th 1997
     * Fixed bug: Pieces were not displayed properly when being dragged
       if the Chessboard were not the child of the form
     * Fixed bug: The letters A-H were not displayed in the right position
       if WhiteOnTop were TRUE
     * Removed property Align because it was put there without the
       intention.
     * Added property Enabled, which allows to lock the Chessboard
     * Added member function DrawChessPiece which allows displaying
       of a chess piece outside of the component.
     * Datatype Square is now being used consequently

version 1.0 - June 20th 1997
     * Added PAS file for Delphi2 and Delphi3
version 1.0 - June 11th 1997
     * initial version (C++ Builder only)
----------------------------------------------------------------------------

Property Descriptions:

bool BoardLines
Boardlines: Boolean
    Determines whether lines will be drawn
    around the board and between the squares

TBitmap BorderBitmap
BorderBitmap: TBitmap
    If assigned a value, this bitmap will be used to draw the border around
    the board. BorderColor will then be ignored.

TColor BorderColor
BorderColor: TColor
   Sets the color of the border. Will be visible only if no value has
   been assigned to BorderBitmap.

CastleSet CastlingAllowed
CastlingAllowed: CastleSet
    This set stores whether castling is still allowed for each king in each
    direction. Example: CastleSet<<WhiteKingSide will allow short castling
    for white while CastleSet>>BlackQueenSide will disable long castling
    for Black.

TFont CoordFont
CoordFont: TFont
   Sets the font eventually used to display the coordinates around the board.

int CurrentMove (read-only)
CurrentMove: Integer
    Stores the current move of the game in the list. CurrentMove cannot be
    modified directly. Use:  GotoMove (int move, bool WhiteMoves);
    to change its value.

TBitmap CustomPieceSet
CustomPieceSet: TBitmap
    If assigned a legal value (that is a bitmap with a Width of
    1.5 times its Height) this bitmap will be used as the new piece set
    instead of the default The bitmap should consist of 6 x 4 smaller square
    bitmaps of equal size. The order of the pieces should be: pawn, knight,
    bishop, rook, queen and king. The first row represents the white pieces,
    the third row represents the black pieces. The second and fourth row
    should be monochrome and will be used to determine the mask of the white
    and black pieces respectively. The pieces will not be shown in the place
    where the mask bitmap contains a non-zero value. This allows transparent
    drawing of the pieces on the board.

CoordSet DisplayCoords
DisplayCoords: CoordSet
    Determines whether coordinates are being displayed around the screen.
    Examples: DisplayCoords<<West will display coordinates on the left of
    the board. DisplayCoords>>East will make disappear coordinates at the
    right of the board.


Square EnPassant
EnPassant: Square
    if EnPassant doesn't equal None, it contains the square on which
    an EnPassant capture can take place. If white moves for instance
    E2-E4, EnPassant will be set to the value E3 (on which the pawn
    can be taken).  Legal values are: A3-H3, A6-H6

TPen LineStyle
LineStyle: TPen
    Contains the linestyle eventually used to display lines between
    the squares and around the board.

String Position
Position: String
    The contents of the board are stored in this string which is
    always 64 characters long. The board is stored from square
    A8 through H8 to H1. Each character represents a piece on the
    board. The characters P, N, B, R, Q, K represent the pawn
    knight, bishop, rook, queen and king respectively.
    White pieces are uppercased, black pieces lowercased. Empty
    squares are represented by spaces.
    To quickly initialize a standard setup, fill the string
    with 'init'.

bool Resizable
Resizable: Boolean
    Determines whether the ChessBoard can be resized. If TRUE,
    when the user moves the cursor over the right-down corner,
    the shape of the cursor will change and allow the ChessBoard
    to be resized. The resizing does not yet happen flicker-free.

int ResizeMinSize
ResizeMinSize: Integer
    The minimum allowed size of the ChessBoard (it's Width and Height)
    while it is in the resizing state.

int ResizeMaxSize
ResizeMaxSize: Integer
    The maximum allowed size of the ChessBoard (it's Width and Height)
    while it is in the resizing state.

int SizeOfBorder
SizeOfBorder: Integer
    Determines the width of the border around the board. Changing its
    value may change the size of the chessboard as well. (Width and Height)

int SizeOfSquare
SizeOfSquare: Integer
    Determines the squaresize. Changing its value may change the size of
    the chessboard as well. (Width and Height)

TColor SquareColorDark
SquareColorDark: TColor
   The color of the dark squares. Will be visible only if no value has
   been assigned to SquareDark.

TColor SquareColorLight
SquareColorLight: TColor
   The color of the light squares. Will be visible only if no value has
   been assigned to SquareLight.

TBitmap SquareDark
SquareDark: TBitmap
    If assigned a value, this bitmap will be used to draw the border around
    the board to display the dark squares. SquareColorDark will then be
    ignored.

TBitmap SquareLight
SquareLight: TBitmap
    If assigned a value, this bitmap will be used to display the light
    squares. SquareColorLight will then be ignored.

StandardSet StandardSize
StandardSize: StandardSet
   Sets the size of the standard pieceset. The standard pieceset will
   only be used if no value has been assigned to CustomPieceSet.
   Legal values are: size32, size40, size64 and size80

bool WhiteOnTop
WhiteOnTop: Boolean
    Controls whether the white pieces are being
    displayed on top of the board. Use: WhiteOnTop=!WhiteOnTop to flip the
    board.

bool WhiteToMove
WhiteToMove: Boolean
    Readonly. Sets the turn to white if TRUE and to black if FALSE;

---------------------------------------------------------------------------
Methods of the Public Interface:

-Pieces can contain the following (char) values:
p,b,n,r,q or k for a black pawn, knight bishop, rook queen or king
P,B,N,R,Q or K for a white pawn, knight bishop, rook queen or king

bool __fastcall BlackInCheckAfter(Square oldSq, Square newSq)
function BlackInCheckAfter(oldsq, newsq: Square): Boolean
      returns TRUE if black is in check after the indicated move

bool __fastcall ClearSquare(int sqn)
function ClearSquare(sq: Square): Boolean
      will empty the square with number sqn

static int inline __fastcall ColorOfPiece (char piece)
function ColorOfPiece (piece: Char): Integer
      returns BLACK (0) or WHITE  (1) if piece is a legal piece
      otherwise NOPIECE (-1)

static int inline __fastcall ColorOfSquare (Square sqno)
function ColorOfSquare (sq: Square): Integer
      returns BLACK or WHITE according to the color of square sqno.

void __fastcall DrawChessPiece(TCanvas *canvas, int x, int y,char piece)
procedure DrawChessPiece (canvas: TCanvas; x,y: Integer; piece: Char)
      Draws the Chess piece, indicated by 'piece'  on the given canvas,
      at the given offset (x,y).
      This method uses some kind of MaskBlt, and draws only in the place
      where the mask has its bits set so drawing on a patterned surface
      is possible.

MoveInfo& __fastcall GetMove (int moveno, bool WhiteMoves)
function GetMove (moveno: Integer; whiteMoves: Boolean): MoveInfo
      Returns a MoveInfo structure filled with the information
      about the indicated move. Returns a structure with all
      zero values and an initial position in the case the
      move could not be found in the movelist.

TStringList* __fastcall GetMoveList (void)
function GetMoveList: TStringList
      Returns a TStringList with all the moves of the current game.

bool __fastcall GotoMove (int moveno, bool WhiteMoves)
function GotoMove (moveno: Integer; whiteMoves:Boolean): Boolean
      Jump to the indicated move in the game and
      set the position accordingly. Returns FALSE if
      the move cannot be found in the movelist.

bool __fastcall LegalMoveAvailable (void)
function LegalMoveAvailable: Boolean;
      Returns TRUE if a move can be made from the current position.

static Square inline __fastcall MouseToSquare (int x, int y)
function MouseToSquare (x, y: Integer): Square;
      converts coordinates to a square value.
      For instance CoordsToSquare (1,4) will return A4.

bool __fastcall Move (Square oldSq, Square newSq)
function Move (oldsq, newsq: Square): Boolean
      will make a move and return TRUE if the move is legal.
      The move will be both displayed on the board and registered in
      memory. For castling: pass the move of the king.
      Example: Move (E2,E4)

bool __fastcall MoveBackward (void)
function MoveBackward: Boolean
      Moves backward in the list of played moves and sets the position
      accordingly. Returns FALSE if there's no move available.

void __fastcall MoveForward (void)
function MoveForward: Boolean
      Moves forward in the list of played moves and sets the position
      accordingly. Returns FALSE if there's no move available.

void __fastcall NewGame(void)
procedure NewGame
      Resets the position to the initial state.

bool __fastcall SetUpPosition (MoveInfo &pos, int moveno, bool whitemoves)
function SetUpPosition (pos: MoveInfo; moveno: Integer; whiteMoves:Boolean): Boolean
      Sets up the ChessBoard according to a given position. The first
      move in the game will be moveno.

void __fastcall UpdateChessBoard (String oldpos)
procedure UpdateChessBoard (char *oldpos);
      Ensures all pieces are displayed on the right position.
      Can be used if you change property Position manually.

bool __fastcall WhiteInCheckAfter(Square oldsq, Square newsq)
function WhiteInCheckAfter(oldsq, newsq: Square):Boolean
      returns TRUE if white is in check after the indicated move

Square  __fastcall WindowToSquare (int x, int y)
function WindowToSquare (x, y: Integer): Square
      returns the square at the position of (x,y).
      x and y must be relative to the current window.

static int inline __fastcall XPos (int sqno)
function XPos (sq: Square): Integer
      returns the x-Coordinate (as an integer number in the range 1-8)
      of the square.

static int inline __fastcall YPos (int sqno)
function YPos (sq: Square): Integer
      returns the x-Coordinate (as an integer number in the range 1-8)
      of the square.

---------------------------------------------------------------------------
Event Handlers:

The following event handlers can be used.

virtual void __fastcall Capture (System::TObject *Sender,
   int oldSq, int newSq, char CapturedPiece)
procedure Capture (Sender: TObject;oldSq,newSq: Square;CapturedPiece:Char)

virtual void __fastcall Castle (System::TObject *Sender, Square oldSq,
   Square newSq)
procedure Castle (Sender: TObject;oldSq,newSq: Square)

virtual void __fastcall Check (System::TObject *Sender,
   Square oldSq, Square newSq)
procedure Check (Sender: TObject; oldSq, newSq: Square)

virtual void __fastcall Click(void)
procedure Click; override

virtual void __fastcall DragCanceled(void)
procedure DragCanceled; override;

virtual void __fastcall DragDrop(System::TObject *Source,int X, int Y)
procedure DragDrop(Source: TObject;X,Y: Integer);override

virtual void __fastcall DragOver(System::TObject* Source, int X, int Y,
       TDragState State, bool &Accept )
procedure DragOver(Source: TObject;X,Y: Integer; State: TDragState;var Accept: Boolean );override

virtual void __fastcall EndDrag(bool drop)
procedure EndDrag(drop:Boolean)

virtual void __fastcall IllegalMove (System::TObject *Sender,  Square sq)
procedure IllegalMove (Sender:TObject; sq: Square)

virtual void __fastcall LegalMove (System::TObject *Sender,
       Square oldSq, Square newSq)
procedure LegalMove (Sender:TObject;oldSq,newSq: Square)

virtual void __fastcall Mate (System::TObject *Sender,
       Square oldSq, Square newSq)
procedure Mate (Sender:TObject;     oldSq,newSq: Square)

virtual void __fastcall MouseDown(TMouseButton Button,
   Classes::TShiftState Shift, int X, int Y)
procedure MouseDown(Button:TMouseButton; Shift:TShiftState;X,Y: Integer); override

virtual void __fastcall MouseMove(Classes::TShiftState Shift, int X, int Y)
procedure MouseMove(Shift:TShiftState; X,Y: Integer); override

virtual void __fastcall MouseUp(TMouseButton Button,
   Classes::TShiftState Shift, int X, int Y)
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);override

virtual void __fastcall OnlyTwoKingsLeft (System::TObject *Sender)
procedure OnlyTwoKingsLeft (Sender:TObject)

virtual void __fastcall Paint(void)
procedure Paint; override

virtual void __fastcall Promotion
   (System::TObject *Sender,  Square oldSq, Square newSq, char &NewPiece)
procedure Promotion (Sender: TObject;oldSq,newSq: Square; var NewPiece: Char)
     Note: you can choose your piece by assigning a new value to NewPiece.

virtual void __fastcall StaleMate (System::TObject *Sender,
   Square oldSq, Square newSq)
procedure StaleMate (Sender: TObject; oldSq,newSq: Square)

---------------------------------------------------------------------------
Copyright, Liability and Author:

The Chessboard component may be freely used and distributed by anyone.
The author does not accept liability for the software in any way.

Note that the standard pieceset that's being used comes straight out of
Fritz4 for I thought I would never be able to design such clear and charming
pieces. So take care not to break any laws with copyrighted material.
If you would like to receive some Chess pieces from some other popular
Chess programs, just drop me a line, which you can do as well if you
have any bug reports, comments, suggestions, or wanted features:

Daniel Terhell
Amsterdam
Tel: +31 20 4866128
[email protected]
http://ourworld.compuserve.com/homepages/kr8m8pr8
-----------------------------------------------------------------------------