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

  1. {************************************************}
  2. {                                                }
  3. {   Chess - Shared DLL Example                   }
  4. {   CHESS.DLL Game record and internal types.    }
  5. {   Copyright (c) 1992 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. unit GameRec;
  10. { contains all internal types and the big game context record }
  11.  
  12. interface
  13.  
  14. uses ChessInf, LTimer, TaskMgr;
  15.  
  16. type
  17.   LevelType = (Normal, PlySearch, MateSearch);
  18.  
  19. const
  20.   Back = -104;                   { Number of stored moves }
  21.   MaxPly = 23;                   { Maximal search depth }
  22.   MaxGames = 5;                  { Max number of simultaneous games }
  23.  
  24. type
  25.  
  26.   { Squarenumbers. a1=0, b1=1,..., a2=$10,..., h8=$77 }
  27.  
  28.   { The 64 squares }
  29.   SquareType = $00..$77;
  30.   EdgeSquareType = -$21..$98;
  31.  
  32.   ColorType = (White, Black);
  33.   PieceType = (Empty, King, Queen, Rook, Bishop, Knight, Pawn);
  34.  
  35.   IndexType = 0..15;       { Index in PieceTab }
  36.  
  37.   BoardType = record
  38.     Piece: PieceType;      { PieceType }
  39.     Color: ColorType;      { Color }
  40.     Index: 0..16;          { Index to PieceTab }
  41.   end;
  42.  
  43.   { The MoveType, which is used to represent all moves in the program }
  44.   MoveType = record
  45.     New1, Old : SquareType; { New1 and Old Square }
  46.     Spe:      Boolean;      { Indicates special Move:
  47.                               case MovPiece of
  48.                                 King: Castling
  49.                                 Pawn: E.p. capture
  50.                               else : Pawnpromotion }
  51.     MovPiece,               { Moving Piece }
  52.     Content :  PieceType;   { Evt. captured Piece }
  53.   end;
  54.  
  55. const
  56.   { The undefined Move. Testing is Done using MovPiece=Empty }
  57.   ZeroMove : MoveType = (
  58.     New1: 8;
  59.     Old: 8;
  60.     Spe: False;
  61.     MovPiece: Empty;
  62.     Content: Empty);
  63.  
  64.   Pieces : array[0..7] of PieceType =
  65.     (Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook);
  66.  
  67.   PieceLetter : array[Empty..Pawn] of char = ' KQRBNP';
  68.  
  69. { The played moves. MovTab[Back..Depth] contains all the moves played
  70.   so far }
  71. type
  72.   DepthType = Back..MaxPly;
  73.   MoveTabType = array[depthtype] of movetype;
  74.  
  75.   { Evaluation type }
  76.   MaxType  = Integer;
  77.  
  78.   { Principal variation type }
  79.   LineType = array[0..MaxPly] of MoveType;
  80.  
  81.   NodeVal = LongInt;
  82.  
  83.   StateTypes = (GameOver, InLibrary, Analysis, OppAnalysis, MovePending);
  84.  
  85.   StateSet = set of StateTypes;
  86.  
  87.   { GameOver    = A checkmate or stalemate has been detected.
  88.     InLibrary   = Using the opening library to make moves.
  89.     Analysis    = Currently searching for a move.
  90.     OppAnalysis = Performing look-ahead search.
  91.     MovePending = }
  92.  
  93. const
  94.   { Magic number used for safety checking }
  95.   gmGameMagic = $4246;
  96.  
  97. type
  98.   PGameData = ^TGameData;
  99.   TGameData = record
  100.  
  101.     { Magic number should always equal gmGameMagic.  Used for a safety
  102.       check }
  103.     Magic: Word;
  104.  
  105.     { Board contains the Content of each Square, Square by Square }
  106.     Board: array[SquareType] of BoardType;
  107.  
  108.     { PieceTab contains the squares of all the Pieces,
  109.       Piece by Piece.
  110.       Board and PieceTab is two different representations of the
  111.       same position, and they are always changed simultaniously.
  112.  
  113.       No. 0 is the King,
  114.       No. 1 - OfficerNo is the officers and evt. Pawns,
  115.       No. OfficerNo + 1 - PawnNo is the pawns }
  116.  
  117.     PieceTab: array[ColorType,IndexType] of record
  118.       ISquare: SquareType;  { Square and Index to Board }
  119.       IPiece:  PieceType;                   { PieceType }
  120.     end;
  121.  
  122.     { Indexes to PieceTab, used to speed Up the program a Bit }
  123.     OfficerNo, PawnNo: array[ColorType] of - 1..15;
  124.  
  125.     { Player is always Next to Move }
  126.     Player,
  127.     Opponent: ColorType;
  128.  
  129.     Depth: DepthType;
  130.     MovTab: MoveTabType;
  131.  
  132.     { The Piece-Value-table }
  133.     PVTable: array[ColorType, King..Pawn, SquareType] of -64..191;
  134.  
  135.     NextMove: MoveType;                     { The generated move }
  136.     Buffer: array[1..80] of MoveType;       { Buffer of generated moves }
  137.     BufCount,
  138.     BufPnt: 0..80;                          { Counters for Buffer    }
  139.  
  140.     ProgramColor: ColorType;                { Color of program }
  141.     MaxDepth: Integer;                      { Search Depth counter }
  142.     LegalMoves: Integer;                    { Number of Legal moves }
  143.     MoveNo: Integer;                        { Move Number }
  144.     MainLine: LineType;                     { Principal variation }
  145.     MainEvalu: MaxType;                     { Evaluation for principal
  146.                                               variation }
  147.     Nodes: NodeVal;                           { Number of analysed Nodes }
  148.     Clock: TTaskTimer;                      { Time limit per complete turn }
  149.     TaskTimer: TTaskTimer;                  { Time limit per Think period  }
  150.  
  151.     PlayerMove: MoveType;
  152.  
  153.     { The two chess clocks. Running indicates that the Clock for RunColor
  154.       is Running }
  155.     ChessTime: array[ColorType] of TStopWatch;
  156.     RunColor: ColorType;
  157.     Running: Boolean;
  158.     KeyMove: MoveType;
  159.     HintLine: LineType;                    { Suggested Hint Line }
  160.     HintEvalu: MaxType;                    { Evaluation for HintLine }
  161.  
  162.     OpCount:  -1..61;                      { Opening library }
  163.     LibNo: Integer;
  164.     UseLib: Integer;                       { program uses library
  165.                                              if MoveNo < UseLib }
  166.  
  167.     Level: LevelType;                      { LevelType }
  168.     MaxLevel: Byte;                        { Maximum Search Depth }
  169.     AverageTime: Longint;
  170.  
  171.     State: StateSet;                       { State transitions }
  172.  
  173.     Engaged: Boolean;                      { Game task managment variables }
  174.     AppStack,
  175.     GameStack: TTaskInfo;
  176.    end;
  177.  
  178. var
  179.   GameList: array [1..MaxGames] of TGameData;
  180.  
  181.   { Index of current game context in the GameList }
  182.   CCHandle: HChess;
  183.  
  184.   { Current game context, set by exported DLL functions before performing
  185.     any game-related operations.  All game operations are done relative to
  186.     this game context }
  187.   CC: TGameData;
  188.  
  189. implementation
  190.  
  191. end.