home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 10.ddi / CHESS.ZIP / CHESSDLL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  10.4 KB  |  272 lines

  1. {************************************************}
  2. {                                                }
  3. {   Chess - Shared DLL Example                   }
  4. {   CHESS.DLL Interface file.                    }
  5. {   Copyright (c) 1992 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. unit ChessDll;
  10.  
  11. interface
  12.  
  13. type
  14.   TPiece = (pEmpty, pKing, pQueen, pRook, pBishop, pKnight, pPawn);
  15.   TColor = (cWhite, cBlack);
  16.   TKind  = (kNormal, kEnPassant, kCastling, kPawnPromote);
  17.   HChess = Word;
  18.  
  19. type
  20.   TSquare = record
  21.     Piece: TPiece;
  22.     Color: TColor;
  23.   end;
  24.   TBoard = array[1..8,1..8] of TSquare;
  25.  
  26.   TLocation = record
  27.     X: 0..8;            { 0 is off-board or empty }
  28.     Y: 0..8;            { 0 is off-board or empty }
  29.   end;
  30.  
  31.   PChange = ^TChange;
  32.   TChange = record
  33.     Piece: TPiece;
  34.     Source: TLocation;
  35.     Dest: TLocation;
  36.   end;
  37.  
  38.   PMove = ^TMove;
  39.   TMove = record
  40.     Change: TChange;
  41.     Capture: Boolean;
  42.     Contents: TPiece;
  43.     case Kind: TKind of
  44.       kEnPassant: (EPCapture: TLocation);
  45.       kCastling: (RookSource, RookDest: TLocation);
  46.   end;
  47.  
  48. type
  49.   TSearchStatus = (
  50.     ssComplete,                 { Completed last opperation }
  51.     ssMoveSearch,               { Searching for a move for the current
  52.                                   player }
  53.     ssThinkAhead,               { Thinking ahead while waiting for a
  54.                                   SubmitMove }
  55.     ssGameOver                  { Game is complete }
  56.   );
  57.  
  58.   TChessStatus = (
  59.     csNormal,                   { Nothing is special about the current state }
  60.     csCheck,                    { The current player is in check }
  61.     csCheckMate,                { The current player is in checkmate }
  62.     csStaleMate,                { The game is a stalemate }
  63.     csResigns,                  { The opponent is so far ahead there is no
  64.                                   point in playing the game further }
  65.     csMateFound,                { Checkmate will happen in a maximum of
  66.                                   Count moves (Count is a parameter of
  67.                                   GetChessStatus) }
  68.     csFiftyMoveRule,            { The game violates the 50 move rule
  69.                                   (stalemate) }
  70.     csRepetitionRule);          { The game violates the 3 repetition rule
  71.                                   (stalemate) }
  72.  
  73. type
  74.   TChessError = (
  75.                                 { General results }
  76.     ceOK,                       { Request sucessful }
  77.     ceInvalidHandle,            { Handle passed is not valid }
  78.     ceIllegalState,             { Call not legal in current state }
  79.  
  80.                                 { NewGame results }
  81.     ceOutOfMemory,              { Not enough memory to allocate game context }
  82.     ceTooManyGames,             { Not enough game handles for new game }
  83.  
  84.                                 { SubmitMove/VarifyMove/ParseMove results }
  85.     ceInvalidMove,              { Cannot move specified piece there }
  86.     ceIllegalMove,              { Move into or does not prevent check or
  87.                                   castling through check }
  88.  
  89.                                 { VerifyMove results }
  90.     ceInvalidSyntax,            { Move syntax cannot be determined }
  91.     ceAmbiguousMove,            { More then one piece fits move (i.e. if you
  92.                                   pass in NF3 and two Knights can be there) }
  93.  
  94.                                 { RetractMove results }
  95.     ceNoMovesLeft);             { No moves left to retract }
  96.  
  97. { Game handle management }
  98.  
  99. { Allocates a game handle }
  100. function NewGame(var GameHandle: HChess): TChessError;
  101.  
  102. { Frees the game handle }
  103. function DisposeGame(CH: HChess): TChessError;
  104.  
  105.  
  106. { Move management }
  107.  
  108. { Parses the given Move into a change record. The syntax is as follows:
  109.  
  110.      <Location> | <Piece name><Location> | <Location><Location>
  111.  
  112.   where <Location> is in the form A3 or F5 and <Piece letter> is one of:
  113.  
  114.     P = Pawn, R = Rook, N = Knight, B = Biship, Q = Queen, K = King
  115.  
  116.   If only a Location is given and the move is ambigious it is assumed the
  117.   piece being moved is a pawn }
  118.  
  119. function ParseMove(Move: PChar; var Change: TChange): TChessError;
  120.  
  121. { Retracts the last move.  NOTE: Retract move should not be called
  122.   during a search! }
  123. function RetractMove(CH: HChess; const Move: TMove): TChessError;
  124.  
  125. { Submits a move for the current player.  Both the "Piece" field and
  126.   the "From" field can be empty if the move is unambigious.  This is
  127.   only legal to call while idle or during a "think ahead" }
  128. function SubmitMove(CH: HChess; const Change: TChange): TChessError;
  129.  
  130. { Verify the legality of the given change but do not perform the
  131.   change.  The "Source" and "Piece" fields can be empty if move is
  132.   unambigious. This is only legal to call while complete or during a
  133.   "think ahead" }
  134. function VerifyMove(CH: HChess; const Change: TChange): TChessError;
  135.  
  136.  
  137. { Search management }
  138.  
  139. { Starts a move search.  It will always return immediately.  You need
  140.   to call Think to perform the actual search. TimeLimit is in 1/18ths
  141.   of a second. }
  142. function ComputerMove(CH: HChess; TimeLimit: LongInt): TChessError;
  143.  
  144. { Force the computer to make a move with the information it has now.
  145.   The move will be completed with the next call to Think. This is only
  146.   legal while performing a move search }
  147. function ForceMove(CH: HChess): TChessError;
  148.  
  149. { Start using the Think time to begin a search assuming the opponent is
  150.   going to follow the main line.  If the opponent does, the next search
  151.   will start at the think-ahead point, otherwise a new search is started.
  152.   This is only legal to call while idle }
  153. function ThinkAhead(CH: HChess): TChessError;
  154.  
  155.  
  156. { Aborts the current search being performed whether started with ThinkAhead
  157.   or ComputerMove.  The move under consideration is not performed and the
  158.   player is unchanged.  This call is ignored if no search is active }
  159. function AbortSearch(CH: HChess): TChessError;
  160.  
  161. { Chess process management }
  162.  
  163. { Gives TimeLimit ticks to the computer to think (1/18'ths of a second).
  164.   This call performs the move search.  Think should be called whenever
  165.   the chess program is idle, even while waiting for the opponent.
  166.   The engine utilizes the opponents idle time to "look ahead" to
  167.   improve the results of the next move. The number given in TimeLimit
  168.   should be small (below 10 when searching for a computer move, below
  169.   5 when waiting for the opponent) to allow the rest of the app to be
  170.   responsive.  This is especially important in Windows.  }
  171. function Think(CH: HChess; TimeLimit: LongInt;
  172.   var Status: TSearchStatus): TChessError;
  173.  
  174.  
  175. { Board editing }
  176.  
  177. { !!! NOTE: Board editing routines are not valid during a search }
  178.  
  179. { Replace the current board with the given board }
  180. function SetBoard(CH: HChess; const ABoard: TBoard): TChessError;
  181.  
  182. { Set the current player to Player }
  183. function SetPlayer(CH: HChess; APlayer: TColor): TChessError;
  184.  
  185. { Make the following modification to the board.  If the "Source" Location
  186.   is blank the piece is new, if the "Dest" Location is blank the piece is
  187.   taken from the board. If neither are blank the piece is moved.  If the
  188.   piece type does not match the piece in the Source location, the piece
  189.   is changed to be the given type }
  190. function MakeChange(CH: HChess; Color: TColor;
  191.   const Change: TChange): TChessError;
  192.  
  193.  
  194. { Status interface }
  195.  
  196. { Returns the status of the move search }
  197. function GetSearchStatus(CH: HChess): TSearchStatus;
  198.  
  199. { Returns the current status of the game }
  200. function GetChessStatus(CH: HChess; var Count: Integer): TChessStatus;
  201.  
  202. { Format the move as a text string }
  203. function MoveToStr(const Move: TMove; var Str: array of Char): TChessError;
  204.  
  205. { !!! NOTE: These functions are not valid to call during a search. }
  206.  
  207. { Returns the last move }
  208. function GetLastMove(CH: HChess; var Move: TMove): TChessError;
  209.  
  210. { Returns the hint move }
  211. function GetHintMove(CH: HChess; var Move: TMove): TChessError;
  212.  
  213. { Returns the current state of the board.  If a search is being performed
  214.   it is the state of the board that is being searched. }
  215. function GetBoard(CH: HChess; var ABoard: TBoard): TChessError;
  216.  
  217. { Return the whose turn it is }
  218. function GetPlayer(CH: HChess): TColor;
  219.  
  220. { Returns a list of the valid given Change.  Empty fields in the change
  221.   record are used as wildcards in the search.  For example, if you
  222.   want all the legal pawn moves only fill in the Piece field leaving
  223.   the Location fields blank.  If you want all the legal moves for the
  224.   piece on A4, fill in Source with A4 and leave Piece and Dest blank.
  225.   Leaving all fields of Change blank will return all legal moves }
  226. function GetValidMoves(CH: HChess; Change: TChange;
  227.   var Moves: array of TMove): TChessError;
  228.  
  229. { !!! NOTE: This function are only meaningful during a search }
  230.  
  231. { Returns the current move being searched by the computer }
  232. function GetCurrentMove(CH: HChess; var Move: TMove): TChessError;
  233.  
  234. { Returns the current priciple line being used by the computer. }
  235. function GetMainLine(CH: HChess; var Value: Integer;
  236.   var Line: array of TMove): TChessError;
  237.  
  238. { Returns the number of nodes processed during the last (or current)
  239.   search }
  240. function GetNodes(CH: HChess): LongInt;
  241.  
  242.  
  243. implementation
  244.  
  245. function NewGame;         external 'CHESS';
  246. function DisposeGame;     external 'CHESS';
  247. function ParseMove;       external 'CHESS';
  248. function RetractMove;     external 'CHESS';
  249. function SubmitMove;      external 'CHESS';
  250. function VerifyMove;      external 'CHESS';
  251. function ComputerMove;    external 'CHESS';
  252. function ForceMove;       external 'CHESS';
  253. function ThinkAhead;      external 'CHESS';
  254. function AbortSearch;     external 'CHESS';
  255. function Think;           external 'CHESS';
  256. function SetBoard;        external 'CHESS';
  257. function SetPlayer;       external 'CHESS';
  258. function MakeChange;      external 'CHESS';
  259. function GetChessStatus;  external 'CHESS';
  260. function GetSearchStatus; external 'CHESS';
  261. function GetLastMove;     external 'CHESS';
  262. function GetHintMove;     external 'CHESS';
  263. function MoveToStr;       external 'CHESS';
  264. function GetBoard;        external 'CHESS';
  265. function GetPlayer;       external 'CHESS';
  266. function GetCurrentMove;  external 'CHESS';
  267. function GetMainLine;     external 'CHESS';
  268. function GetValidMoves;   external 'CHESS';
  269. function GetNodes;        external 'CHESS';
  270.  
  271. end.
  272.