---------------------------------------------------------------------------
Welcome to the Chessboard component v1.00 for Borland C++ Builder
version 1.0 - June 11th 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 Borland C++ Builder. Select "Component", "Install" ,"Add" and
"Browse" and then browse to the file Chess.cpp. The component will
appear on a new tab called Chess.

---------------------------------------------------------------------------
Property Descriptions:

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

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

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

CastleSet CastlingAllowed
    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
   Sets the font eventually used to display the coordinates around the board.

int CurrentMove (read-only)
    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
    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
    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
    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
    Contains the linestyle eventually used to display lines between
    the squares and around the board.

String Position
    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
    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
    The minimum allowed size of the ChessBoard (it's Width and Height)
    while it is in the resizing state.

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

int SizeOfBorder
    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
    Determines the squaresize. Changing its value may change the size of
    the chessboard as well. (Width and Height)

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

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

TBitmap SquareDark
    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
    If assigned a value, this bitmap will be used to display the light
    squares. SquareColorLight will then be ignored.

StandardSet StandardSize
   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
    Controls whether the white pieces are being
    displayed on top of the board. Use: WhiteOnTop=!WhiteOnTop to flip the
    board.

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

Note that TChessBoard also has all methods that TGraphicControl has.
---------------------------------------------------------------------------
Methods of the Public Interface:

-Note that squares are numbered from 1-64 and represent
the squares on the chessboard in the order A8.. H8.. H1.

-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(int oldsq, int newsq)
      returns TRUE if black is in check after the indicated move

bool __fastcall ClearSquare(int sqn)
      will empty the square with number sqn

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

static int inline __fastcall ColorOfSquare (int sqno)
      returns BLACK or WHITE according to the color of square sqno.

MoveInfo& __fastcall GetMove (int moveno, bool WhiteMoves)
      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)
      Returns a TStringList with all the moves of the current game.

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

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

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

bool __fastcall Move (int oldsq, int newsq)
      will make a move and return TRUE if the move is legal.
      For castling: pass the move of the king.
      Example: Move (E2,E4)

bool __fastcall MoveBackward (void)
      Moves backward in the list of played moves and sets the position
      accordingly. Returns FALSE if

void __fastcall MoveForward (void);

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

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

bool __fastcall WhiteInCheckAfter(int oldsq, int newsq)
      returns TRUE if white is in check after the indicated move

int  __fastcall WindowToSquare (int x, int y)
      returns the square at the position of (x,y).
      x and y must be relative to the current window/form.

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

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


Note that TChessBoard has also all methods that  TGraphicControl has.
---------------------------------------------------------------------------
Event Handlers:

The following event handlers can be used.
For the Chess event handlers counts that olSq and newSq contain
the values of the squares of the move involved.

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

virtual void __fastcall Castle (System::TObject *Sender, int oldSq, int newSq)

virtual void __fastcall Check (System::TObject *Sender,  int oldSq, int newSq)

virtual void __fastcall Click(void)

virtual void __fastcall DragCanceled(void)

virtual void __fastcall DragDrop(System::TObject *Source,int X, int Y)

virtual void __fastcall DragOver(System::TObject* Source, int X, int Y,
       TDragState State, bool &Accept )

virtual void __fastcall EndDrag(bool drop)

virtual void __fastcall IllegalMove (System::TObject *Sender,  int square)

virtual void __fastcall LegalMove (System::TObject *Sender,
       int oldSq, int newSq)

virtual void __fastcall Mate (System::TObject *Sender,  int oldSq, int newSq)

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

virtual void __fastcall MouseMove(Classes::TShiftState Shift, int X, int Y)

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

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

virtual void __fastcall Paint(void)

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


virtual void __fastcall StaleMate (System::TObject *Sender,
   int oldSq, int newSq)

----------------------------------------------------------------------------
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 comments, suggestions, bugs or wanted features:

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