home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D11 / CHESSDLL.ZIP / GAMEREC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  6.5 KB  |  178 lines

  1. unit GameRec;
  2. { contains all internal types and the big game context record }
  3.  
  4. interface
  5.  
  6. uses ChessInf, LTimer, TaskMgr;
  7.  
  8. type
  9.   LevelType = (Normal,FullGameTime,DemoGame,
  10.                Infinite,PlySearch,MateSearch);
  11.  
  12. const
  13.   Back = -104;    { Number of stored moves }
  14.   MaxPly = 23;    { Maximal search depth }
  15.   MaxGames = 5;  { Max number of simultaneous games }
  16.  
  17. type
  18.  
  19.   { Squarenumbers. a1=0, b1=1,..., a2=$10,..., h8=$77 }
  20.  
  21.   SquareType     = $00..$77;   { The 64 squares }
  22.   EdgeSquareType = -$21..$98;
  23.  
  24.   ColorType      = (White, Black);
  25.   PieceType      = (Empty, King, Queen, Rook, Bishop, Knight, Pawn);
  26.  
  27.   IndexType      = 0..15;       { Index in PieceTab }
  28.  
  29.   BoardType      = record
  30.                       Piece : PieceType;   { PieceType }
  31.                       Color : ColorType;   { Color }
  32.                       Index : 0..16;       { Index to PieceTab }
  33.                    end;
  34.  
  35. { The MoveType, which is used to represent all moves in the program }
  36.   MoveType = record
  37.                 New1, Old : SquareType; { New1 and Old Square }
  38.                 Spe:      boolean;    { Indicates special Move:
  39.                                         case MovPiece of
  40.                                          King: Castling
  41.                                          Pawn: E.p. capture
  42.                                          else : Pawnpromotion }
  43.                 MovPiece,              { Moving Piece }
  44.                 Content :  PieceType;  { Evt. captured Piece }
  45.              end;
  46.  
  47. const
  48.          { The undefined Move. Testing is Done using MovPiece=Empty }
  49.   ZeroMove : MoveType = (New1    : 8;
  50.                         Old      : 8;
  51.                         Spe      : False;
  52.                         MovPiece : Empty;
  53.                         Content  : Empty);
  54.  
  55.   Pieces : array[0..7] of PieceType =
  56.        ( Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook );
  57.  
  58.   PieceLetter : array[Empty..Pawn] of char = ' KQRBNP';
  59.  
  60. { The played moves.
  61.   MovTab[Back..Depth] contains all the moves played so far }
  62. type
  63.   DepthType = Back..MaxPly;
  64.   MoveTabType = array[depthtype] of movetype;
  65.  
  66.   MaxType  = integer;                               { Evaluation type }
  67.   LineType = array[0..MaxPly] of MoveType; { Principal variation type }
  68.  
  69.   NodeVal = LongInt;
  70.  
  71.   StateTypes = (GameOver, InLibrary, Analysis, OppAnalysis, MovePending);
  72.  
  73.   StateSet = set of StateTypes;
  74.  
  75.   { ReadyForMove = Computer's turn is complete.
  76.                    This may be combined with ThinkAhead.
  77.     StartGameMove= First pass in computer's turn.
  78.                     Exclusive of ReadyForMove
  79.     ThinkAhead   = Computer looks beyond the next turn to better select its
  80.                  next turn, while waiting for human to respond with his
  81.                  next turn.  Compatible with ReadyForMove.
  82.     GameOver   = The game is over.  No more moves will be accepted.
  83.     AutoPlay   = Game plays itself
  84.     MultiMove  = User plays both sides
  85.     SingleStep = Single steps through move searches, for debugging
  86.     InLibrary  = Opening library is being used for move selection
  87.     Analysis   = We're analyzing our moves
  88.     OppAnalysis= We're analyzing the oponent's moves
  89.   }
  90.  
  91. const
  92.   gmGameMagic = $4246;
  93.    
  94. type
  95.   PGameData = ^TGameData;
  96.   TGameData = record
  97.       Magic: Word;
  98.       { Board contains the Content of each Square,
  99.         Square by Square }
  100.       Board : array[SquareType] of BoardType;
  101.  
  102.       { PieceTab contains the squares of all the Pieces,
  103.         Piece by Piece.
  104.         Board and PieceTab is two different representations of the
  105.         same position, and they are always changed simultaniously.
  106.  
  107.         No. 0 is the King,
  108.         No. 1 - OfficerNo is the officers and evt. Pawns,
  109.         No. OfficerNo + 1 - PawnNo is the pawns }
  110.  
  111.       PieceTab : array[ColorType,IndexType] of
  112.                    record
  113.                       ISquare : SquareType;  { Square and Index to Board }
  114.                       IPiece :  PieceType;                   { PieceType }
  115.                    end;
  116.  
  117.       { Indexes to PieceTab, used to speed Up the program a Bit }
  118.       OfficerNo, PawnNo : array[ColorType] of - 1..15;
  119.  
  120.       Player,
  121.       Opponent : ColorType;     { Player is always Next to Move }
  122.       Depth  : DepthType;
  123.       MovTab : MoveTabType;
  124.                                  { The Piece-Value-table }
  125.       PVTable: array[ColorType, King..Pawn, SquareType] of -64..191;
  126.  
  127.       NextMove : MoveType;                  { The generated move }
  128.       Buffer   : array[1..80] of MoveType;  { Buffer of generated moves }
  129.       BufCount,
  130.       BufPnt : 0..80;                     { Counters for Buffer    }
  131.  
  132.       ProgramColor :   ColorType;     { Color of program }
  133.       MaxDepth :       integer;       { Search Depth counter }
  134.       LegalMoves :     integer;       { Number of Legal moves }
  135.       MoveNo :         integer;       { Move Number }
  136.       MainLine :       LineType;      { Principal variation }
  137.       MainEvalu :      MaxType;       { Evaluation for
  138.                                         principal variation }
  139.       Nodes :          NodeVal;       { Number of analysed Nodes }
  140.       Clock :          TTaskTimer;    { Time limit per complete turn }
  141.       TaskTimer:       TTaskTimer;    { Time limit per Think period  }
  142.  
  143.       PlayerMove :     MoveType;
  144.  
  145.       { The two chess clocks. Running indicates
  146.         that the Clock for RunColor is Running }
  147.       ChessTime :      array[ColorType] of TStopWatch;
  148.       RunColor :       ColorType;
  149.       Running : Boolean;
  150.       KeyMove   : MoveType;
  151.       HintLine  : LineType;   { Suggested Hint Line }
  152.       HintEvalu : MaxType;    { Evaluation for HINTLINT }
  153.  
  154.       OpCount :  -1..61;            { Opening library }
  155.       LibNo   : integer;
  156.       UseLib  : integer;     { program uses library if MoveNo < UseLib }
  157.  
  158.       Level        : LevelType;     { LevelType }
  159.       MaxLevel     : byte;          { Maximum Search Depth }
  160.       AverageTime  : Longint;
  161.  
  162.       Command : string[10];      { text command from user }
  163.       State : StateSet;  { state transitions }
  164.       Engaged: Boolean;
  165.       AppStack,
  166.       GameStack: TTaskInfo;
  167.    end;
  168.  
  169. var
  170.   GameList: array [1..MaxGames] of TGameData;
  171.   CCHandle: HChess;  { Index of current game context in the GameList }
  172.   CC: TGameData; { Current game context, set by exported DLL functions
  173.                  before performing any game-related operations.  All
  174.                  game operations are done relative to this game context }
  175.  
  176. implementation
  177.  
  178. end.