Class TChessBrd (unit ChessBrd)

Inherits from

TGraphicControl

Constructors


constructor Create(AOwner: TComponent);



Functions

procedure Animate (oldsq,newsq: Square; delay: Integer);

Displays an move animation It's up to the to user ensure there is a piece on oldSq

function BlackInCheckAfter(oldsq, newsq: Square): Boolean;

Checks whether black is in check after the specified move

procedure CancelThinking;

----------------------------------------------------------------------- PUBLIC, Chess -----------------------------------------------------------------------

procedure ClearSquare(sq: Square);


function ColorOfPiece (piece: Char): Integer;


function ColorOfPieceOnSquare (sq: Square): Integer;

returns color of the PIECE on a square

function ColorOfSquare (sq: Square): Integer;

Squares are numbered from 1 - 64 (a8,b8.

destructor Destroy;


procedure DrawChessPiece (canvas: TCanvas; x,y: Integer; piece: Char);

--------------------------------------------------------------------- -------PUBLIC Graphic Routines----------------------------------------------- ---------------------------------------------------------------------

function GetMove (moveno: Integer; whiteMoves: Boolean): MoveInfo;


procedure GetMoveList(var list: TStringList);


function GotoMove (moveno: Integer; whiteMoves:Boolean): Boolean;


function LegalMoveAvailable: Boolean;


function MouseToSquare (x, y: Integer): Square;


function Move (oldsq, newsq: Square): Boolean;


function MoveBackward: Boolean;

Or a Threefold Position in the game

function MoveForward: Boolean;


function MoveIsLegal (oldsq, newsq: Square):Boolean;


procedure NewGame;


function PerformMove (oldsq, newsq: Square): Boolean;


function SetUpPosition (pos: MoveInfo; moveno: Integer; whiteMoves:Boolean): Boolean;


procedure SquareToCoords (sq: Square; var x,y: Integer);

Retrieves the coords of the upperleft corner of a square writes into x and y

function StringToSquare (str: String): Square;

Expects a two character string, for instance 'e4' and returns a Square value

procedure Think;


procedure UpdateChessBoard (oldpos: String);


function WhiteInCheckAfter(oldsq, newsq: Square):Boolean;

Checks whether white is in check after the specified move

function WindowToSquare (x, y: Integer): Square;

Converts from Window Coordinates to square returns 0 if invalid else 1-64 as a int number

function XPos (sq: Square): Integer;

Returns XPos of a int according to ChessBoard coordinates (A-H

function YPos (sq: Square): Integer;

Returns YPos of a int according to ChessBoard coordinates (1-8

procedure Click;


procedure DragCanceled;


procedure DragDrop(Source: TObject;X,Y: Integer);


procedure DragOver(Source: TObject;X,Y: Integer; State: TDragState;var Accept: Boolean );


procedure EndDrag(drop:Boolean);


procedure MouseDown(Button:TMouseButton; Shift:TShiftState;X,Y: Integer);


procedure MouseMove(Shift:TShiftState; X,Y: Integer);


procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);


procedure Paint;


procedure Promotion (Sender: TObject;oldSq,newSq: Square; var NewPiece: Char);


procedure WndProc(var Message: TMessage);


procedure AnimateDiagonally (x1,y1,x2,y2,delay: Integer);


procedure AnimateHorizontally (x1,x2,y,delay: Integer);

Knights don't go diagonally

procedure AnimateVertically (y1,y2,x,delay: Integer);


function BitmapExists (bmp: TBitmap) :Boolean;

-PRIVATE Graphic Routines ----------------------------------------------- //

function BitmapIsValidPieceSet(bmp: TBitmap) :Boolean;


function CheckForThreefoldPosition: Boolean;

------------------------------------------------------------- -------------------PRIVATE Stuff here------------------------ -------------------------------------------------------------

function CheckLegalBishopMove (oldsq, newsq: Square):Boolean;

Checks whether a bishop move is legal, assuming the king isn't in check

function CheckLegalKingMove (oldsq, newsq: Square):Boolean;

Checks whether a king move is legal, assuming the king isn't in check

function CheckLegalKnightMove (oldsq, newsq: Square):Boolean;

Checks whether a knight move is legal, assuming the king isn't in check

function CheckLegalPawnMove (oldsq, newsq: Square):Boolean;

Checks whether a pawn move is legal, assuming the king isn't in check

function CheckLegalQueenMove (oldsq, newsq: Square):Boolean;

Checks whether a queen move is legal, assuming the king isn't in check

function CheckLegalRookMove (oldsq, newsq: Square):Boolean;

Checks whether a rook move is legal, assuming the king isn't in check

procedure DoPromotion (sq: Square);


procedure DrawBoard;


procedure DrawBoardLines;


procedure DrawBorder;


procedure DrawPiece (sq: Square; piece: Char);


procedure DrawPieces;


function Get_Position: String;

--Boring Write Methods--------------------------------------

----------------------------------------------------------------------- Boring Write Methods -----------------------------------------------------------------------


function Get_Thinking: Boolean;


procedure InitializeBitmap;


procedure OrganizeBitmaps;


function PieceToInt (piece: Char): Integer;


procedure SetNewGame;


procedure Set_BoardLines (show: Boolean);


procedure Set_BorderBitmap (bmp: TBitmap);


procedure Set_BorderColor (c: TColor);


procedure Set_ComputerPlaysBlack (plays: Boolean);


procedure Set_ComputerPlaysWhite (plays: Boolean);


procedure Set_CoordFont (f: TFont);


procedure Set_CurrentMove (moveno: Integer);


procedure Set_CustomEngine (use: Boolean);


procedure Set_CustomPieceSet (bmp: TBitmap);


procedure Set_DarkSquare(bmp: TBitmap);


procedure Set_DisplayCoords (cset: CoordSet);


procedure Set_EnPassant(sq: Square);

Read-Only

procedure Set_LightSquare(bmp: TBitmap);


procedure Set_LineStyle (pen: TPen);


procedure Set_Position (pos: String);


procedure Set_ResizeMaxSize (size: Integer);


procedure Set_ResizeMinSize (size: Integer);


procedure Set_SearchDepth (depth: Integer);


procedure Set_SizeOfBorder (border: Integer);


procedure Set_SizeOfSquare (size: Integer);


procedure Set_SquareColorDark (c: TColor);


procedure Set_SquareColorLight (c: TColor);


procedure Set_Thinking (thinking: Boolean);


procedure Set_ThinkingPriority (priority: TThreadPriority);

Read-Only

procedure Set_Version (str: String);


procedure Set_WhiteOnTop (wabove: Boolean);

Read-only

procedure Set_WhiteToMove (wmove: Boolean);


procedure ThinkingComplete(Sender:TObject);


procedure TimerCallback (Sender: TObject);


Properties

property AnimateMoves : Boolean


property AnimationDelay : Integer


property BoardLines : Boolean


property BorderBitmap : TBitmap


property BorderColor : TColor


property CastlingAllowed : CastleSet


property ComputerPlaysBlack : Boolean


property ComputerPlaysWhite : Boolean


property CoordFont : TFont


property CurrentMove : Integer


property CustomEngine : Boolean


property CustomPieceSet : TBitmap


property DisplayCoords : CoordSet


property DragCursor :


property DragMode :


property Enabled :


property EnPassant : Square


property LineStyle : TPen


property Position : String


property Resizable : Boolean


property ResizeMaxSize : Integer


property ResizeMinSize : Integer


property SearchDepth : Integer


property SizeOfBorder : Integer


property SizeOfSquare : Integer


property SquareColorDark : TColor


property SquareColorLight : TColor


property SquareDark : TBitmap


property SquareLight : TBitmap


property Thinking : Boolean


property ThinkingPriority : TThreadPriority


property Version : String


property Visible :


property WhiteOnTop : Boolean


property WhiteToMove : Boolean


Events

event OnCalculateMove : TThinkEvent


event OnCalculationFailed : TMoveEvent


event OnCapture : TCaptureEvent


event OnCastle : TMoveEvent


event OnCheck : TMoveEvent


event OnClick :


event OnDblClick :


event OnDragDrop :


event OnDragOver :


event OnDraw : TNotifyEvent


event OnEndDrag :


event OnIllegalMove : TOneSquareEvent


event OnLegalMove : TMoveEvent


event OnMate : TMoveEvent


event OnMouseDown :


event OnMouseMove :


event OnMouseUp :


event OnNoMatingMaterial : TNotifyEvent


event OnPaint : TNotifyEvent


event OnPromotion : TPromotionEvent


event OnStaleMate : TMoveEvent


event OnStartDrag :


event OnThreefoldPosition : TNotifyEvent


Variables

FirstMove : Integer;


FirstTurn : Boolean;


LastMove : Integer;


LastTurn : Boolean;


Boardx : Integer;


Boardy : Integer;


buf : Array[0..MAX_PATH] of Char;


Default : TBitmap;


FirstTime : Boolean;


GameEnded : Boolean;


list : TImageList;


MoveList : Array[0..256,0..2]of MoveInfo;


Now : TChessThread;


OldCursor : TCursor;


PieceIndex : Array[0..2,0..6] of Integer;


PieceSize : Integer;


PromoteTo : Char;


ResizeState : Boolean;


SquareClick1 : Square;


SquareClick2 : Square;


stopThinking : Boolean;


temp : MoveInfo;


timer : TTimer;

Class members starting with a _ represent internal storage variables of properties

_animateMoves : Boolean;


_animationDelay : Integer;


_boardlines : Boolean;


_borderBitmap : TBitmap;


_bordercolor : TColor;


_calculate : TThinkEvent;


_capture : TCaptureEvent;


_castle : TMoveEvent;


_castlingAllowed : CastleSet;


_check : TMoveEvent;


_ComputerPlaysBlack : Boolean;


_ComputerPlaysWhite : Boolean;


_coordFont : TFont;


_CurrentMove : Integer;


_customEngine : Boolean;


_custompieceset : TBitmap;


_displayCoords : CoordSet;


_draw : TNotifyEvent;


_enPassant : Square;


_failed : TMoveEvent;


_illegalMove : TOneSquareEvent;


_legalMove : TMoveEvent;


_lineStyle : TPen;


_mate : TMoveEvent;


_noMatingMaterial : TNotifyEvent;


_paint : TNotifyEvent;


_position : Array[0..65] of Char;


_promotion : TPromotionEvent;


_resizable : Boolean;


_ResizeMaxSize : Integer;


_ResizeMinSize : Integer;


_SearchDepth : Integer;


_SizeOfBorder : Integer;


_SizeOfSquare : Integer;


_squareColorDark : TColor;


_squareColorLight : TColor;


_squareDark : TBitmap;


_squareLight : TBitmap;


_staleMate : TMoveEvent;


_ThinkingPriority : TThreadPriority;


_threefoldPosition : TNotifyEvent;


_version : String;


_whiteOnTop : Boolean;


_whiteToMove : Boolean;



Constructors


constructor Create(AOwner: TComponent);


Functions


procedure Animate (oldsq,newsq: Square; delay: Integer);

Displays an move animation It's up to the to user ensure there is a piece on oldSq


function BlackInCheckAfter(oldsq, newsq: Square): Boolean;

Checks whether black is in check after the specified move


procedure CancelThinking;

----------------------------------------------------------------------- PUBLIC, Chess -----------------------------------------------------------------------


procedure ClearSquare(sq: Square);


function ColorOfPiece (piece: Char): Integer;


function ColorOfPieceOnSquare (sq: Square): Integer;

returns color of the PIECE on a square


function ColorOfSquare (sq: Square): Integer;

Squares are numbered from 1 - 64 (a8,b8...h1


destructor Destroy;


procedure DrawChessPiece (canvas: TCanvas; x,y: Integer; piece: Char);

--------------------------------------------------------------------- -------PUBLIC Graphic Routines----------------------------------------------- ---------------------------------------------------------------------


function GetMove (moveno: Integer; whiteMoves: Boolean): MoveInfo;


procedure GetMoveList(var list: TStringList);


function GotoMove (moveno: Integer; whiteMoves:Boolean): Boolean;


function LegalMoveAvailable: Boolean;


function MouseToSquare (x, y: Integer): Square;


function Move (oldsq, newsq: Square): Boolean;


function MoveBackward: Boolean;

Or a Threefold Position in the game


function MoveForward: Boolean;


function MoveIsLegal (oldsq, newsq: Square):Boolean;


procedure NewGame;


function PerformMove (oldsq, newsq: Square): Boolean;


function SetUpPosition (pos: MoveInfo; moveno: Integer; whiteMoves:Boolean): Boolean;


procedure SquareToCoords (sq: Square; var x,y: Integer);

Retrieves the coords of the upperleft corner of a square writes into x and y


function StringToSquare (str: String): Square;

Expects a two character string, for instance 'e4' and returns a Square value


procedure Think;


procedure UpdateChessBoard (oldpos: String);


function WhiteInCheckAfter(oldsq, newsq: Square):Boolean;

Checks whether white is in check after the specified move


function WindowToSquare (x, y: Integer): Square;

Converts from Window Coordinates to square returns 0 if invalid else 1-64 as a int number


function XPos (sq: Square): Integer;

Returns XPos of a int according to ChessBoard coordinates (A-H


function YPos (sq: Square): Integer;

Returns YPos of a int according to ChessBoard coordinates (1-8


procedure Click;


procedure DragCanceled;


procedure DragDrop(Source: TObject;X,Y: Integer);


procedure DragOver(Source: TObject;X,Y: Integer; State: TDragState;var Accept: Boolean );


procedure EndDrag(drop:Boolean);


procedure MouseDown(Button:TMouseButton; Shift:TShiftState;X,Y: Integer);


procedure MouseMove(Shift:TShiftState; X,Y: Integer);


procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);


procedure Paint;


procedure Promotion (Sender: TObject;oldSq,newSq: Square; var NewPiece: Char);


procedure WndProc(var Message: TMessage);


procedure AnimateDiagonally (x1,y1,x2,y2,delay: Integer);


procedure AnimateHorizontally (x1,x2,y,delay: Integer);

Knights don't go diagonally


procedure AnimateVertically (y1,y2,x,delay: Integer);


function BitmapExists (bmp: TBitmap) :Boolean;

-PRIVATE Graphic Routines ----------------------------------------------- //


function BitmapIsValidPieceSet(bmp: TBitmap) :Boolean;


function CheckForThreefoldPosition: Boolean;

------------------------------------------------------------- -------------------PRIVATE Stuff here------------------------ -------------------------------------------------------------


function CheckLegalBishopMove (oldsq, newsq: Square):Boolean;

Checks whether a bishop move is legal, assuming the king isn't in check


function CheckLegalKingMove (oldsq, newsq: Square):Boolean;

Checks whether a king move is legal, assuming the king isn't in check


function CheckLegalKnightMove (oldsq, newsq: Square):Boolean;

Checks whether a knight move is legal, assuming the king isn't in check


function CheckLegalPawnMove (oldsq, newsq: Square):Boolean;

Checks whether a pawn move is legal, assuming the king isn't in check


function CheckLegalQueenMove (oldsq, newsq: Square):Boolean;

Checks whether a queen move is legal, assuming the king isn't in check


function CheckLegalRookMove (oldsq, newsq: Square):Boolean;

Checks whether a rook move is legal, assuming the king isn't in check


procedure DoPromotion (sq: Square);


procedure DrawBoard;


procedure DrawBoardLines;


procedure DrawBorder;


procedure DrawPiece (sq: Square; piece: Char);


procedure DrawPieces;


function Get_Position: String;

--Boring Write Methods--------------------------------------

----------------------------------------------------------------------- Boring Write Methods -----------------------------------------------------------------------


function Get_Thinking: Boolean;


procedure InitializeBitmap;


procedure OrganizeBitmaps;


function PieceToInt (piece: Char): Integer;


procedure SetNewGame;


procedure Set_BoardLines (show: Boolean);


procedure Set_BorderBitmap (bmp: TBitmap);


procedure Set_BorderColor (c: TColor);


procedure Set_ComputerPlaysBlack (plays: Boolean);


procedure Set_ComputerPlaysWhite (plays: Boolean);


procedure Set_CoordFont (f: TFont);


procedure Set_CurrentMove (moveno: Integer);


procedure Set_CustomEngine (use: Boolean);


procedure Set_CustomPieceSet (bmp: TBitmap);


procedure Set_DarkSquare(bmp: TBitmap);


procedure Set_DisplayCoords (cset: CoordSet);


procedure Set_EnPassant(sq: Square);

Read-Only


procedure Set_LightSquare(bmp: TBitmap);


procedure Set_LineStyle (pen: TPen);


procedure Set_Position (pos: String);


procedure Set_ResizeMaxSize (size: Integer);


procedure Set_ResizeMinSize (size: Integer);


procedure Set_SearchDepth (depth: Integer);


procedure Set_SizeOfBorder (border: Integer);


procedure Set_SizeOfSquare (size: Integer);


procedure Set_SquareColorDark (c: TColor);


procedure Set_SquareColorLight (c: TColor);


procedure Set_Thinking (thinking: Boolean);


procedure Set_ThinkingPriority (priority: TThreadPriority);

Read-Only


procedure Set_Version (str: String);


procedure Set_WhiteOnTop (wabove: Boolean);

Read-only


procedure Set_WhiteToMove (wmove: Boolean);


procedure ThinkingComplete(Sender:TObject);


procedure TimerCallback (Sender: TObject);


Properties


property AnimateMoves : Boolean


property AnimationDelay : Integer


property BoardLines : Boolean


property BorderBitmap : TBitmap


property BorderColor : TColor


property CastlingAllowed : CastleSet


property ComputerPlaysBlack : Boolean


property ComputerPlaysWhite : Boolean


property CoordFont : TFont


property CurrentMove : Integer


property CustomEngine : Boolean


property CustomPieceSet : TBitmap


property DisplayCoords : CoordSet


property DragCursor :


property DragMode :


property Enabled :


property EnPassant : Square


property LineStyle : TPen


property Position : String


property Resizable : Boolean


property ResizeMaxSize : Integer


property ResizeMinSize : Integer


property SearchDepth : Integer


property SizeOfBorder : Integer


property SizeOfSquare : Integer


property SquareColorDark : TColor


property SquareColorLight : TColor


property SquareDark : TBitmap


property SquareLight : TBitmap


property Thinking : Boolean


property ThinkingPriority : TThreadPriority


property Version : String


property Visible :


property WhiteOnTop : Boolean


property WhiteToMove : Boolean


Events


event OnCalculateMove : TThinkEvent


event OnCalculationFailed : TMoveEvent


event OnCapture : TCaptureEvent


event OnCastle : TMoveEvent


event OnCheck : TMoveEvent


event OnClick :


event OnDblClick :


event OnDragDrop :


event OnDragOver :


event OnDraw : TNotifyEvent


event OnEndDrag :


event OnIllegalMove : TOneSquareEvent


event OnLegalMove : TMoveEvent


event OnMate : TMoveEvent


event OnMouseDown :


event OnMouseMove :


event OnMouseUp :


event OnNoMatingMaterial : TNotifyEvent


event OnPaint : TNotifyEvent


event OnPromotion : TPromotionEvent


event OnStaleMate : TMoveEvent


event OnStartDrag :


event OnThreefoldPosition : TNotifyEvent


Variables


FirstMove : Integer;


FirstTurn : Boolean;


LastMove : Integer;


LastTurn : Boolean;


Boardx : Integer;


Boardy : Integer;


buf : Array[0..MAX_PATH] of Char;


Default : TBitmap;


FirstTime : Boolean;


GameEnded : Boolean;


list : TImageList;


MoveList : Array[0..256,0..2]of MoveInfo;


Now : TChessThread;


OldCursor : TCursor;


PieceIndex : Array[0..2,0..6] of Integer;


PieceSize : Integer;


PromoteTo : Char;


ResizeState : Boolean;


SquareClick1 : Square;


SquareClick2 : Square;


stopThinking : Boolean;


temp : MoveInfo;


timer : TTimer;

Class members starting with a _ represent internal storage variables of properties


_animateMoves : Boolean;


_animationDelay : Integer;


_boardlines : Boolean;


_borderBitmap : TBitmap;


_bordercolor : TColor;


_calculate : TThinkEvent;


_capture : TCaptureEvent;


_castle : TMoveEvent;


_castlingAllowed : CastleSet;


_check : TMoveEvent;


_ComputerPlaysBlack : Boolean;


_ComputerPlaysWhite : Boolean;


_coordFont : TFont;


_CurrentMove : Integer;


_customEngine : Boolean;


_custompieceset : TBitmap;


_displayCoords : CoordSet;


_draw : TNotifyEvent;


_enPassant : Square;


_failed : TMoveEvent;


_illegalMove : TOneSquareEvent;


_legalMove : TMoveEvent;


_lineStyle : TPen;


_mate : TMoveEvent;


_noMatingMaterial : TNotifyEvent;


_paint : TNotifyEvent;


_position : Array[0..65] of Char;


_promotion : TPromotionEvent;


_resizable : Boolean;


_ResizeMaxSize : Integer;


_ResizeMinSize : Integer;


_SearchDepth : Integer;


_SizeOfBorder : Integer;


_SizeOfSquare : Integer;


_squareColorDark : TColor;


_squareColorLight : TColor;


_squareDark : TBitmap;


_squareLight : TBitmap;


_staleMate : TMoveEvent;


_ThinkingPriority : TThreadPriority;


_threefoldPosition : TNotifyEvent;


_version : String;


_whiteOnTop : Boolean;


_whiteToMove : Boolean;