home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / CHESSTV.ZIP / STATUS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  3.0 KB  |  128 lines

  1. unit Status;
  2.  
  3. interface
  4.  
  5. {$IFDEF DLL}
  6. uses Objects, Views, Dialogs, ChessDLL, CTimers;
  7. {$ELSE}
  8. uses Objects, Views, Dialogs, ChessInf, CTimers;
  9. {$ENDIF}
  10.  
  11. type
  12.   PBestLine = ^TBestLine;
  13.   TBestLine = object(TParamText)
  14.     function GetPalette: PPalette; virtual;
  15.   end;
  16.  
  17.   PStatusDialog = ^TStatusDialog;
  18.   TStatusDialog = object(TDialog)
  19.     constructor Init(var Bounds: TRect);
  20.     function GetPalette: PPalette; virtual;
  21.     procedure Update(Game: HChess; ATimers: array of PChessTimer);
  22.   end;
  23.  
  24.   PGameStatus = ^TGameStatus;
  25.   TGameStatus = record
  26.     ToMove:   PString;
  27.     WhtTime:  PString;
  28.     BlkTime:  PString;
  29.     Nodes:    Longint;
  30.     MainLine: PString;
  31.   end;
  32.  
  33. const
  34.   StatusDialog: PStatusDialog = nil;
  35.  
  36.   CurPlayer: String[5] = '';
  37.   BestLine: String = '';
  38.   TimeStrs: array [TColor] of String[11] = ('', '');
  39.   GameStatus: TGameStatus = (
  40.     ToMove:   @CurPlayer;
  41.     WhtTime:  @TimeStrs[cWhite];
  42.     BlkTime:  @TimeStrs[cBlack];
  43.     Nodes:    0;
  44.     MainLine: @BestLine
  45.   );
  46.  
  47. implementation
  48. uses Strings, ChessCmd, Drivers;
  49.  
  50. function TBestLine.GetPalette: PPalette;
  51. const
  52.   P: string[Length(CBestLine)] = CBestLine;
  53. begin
  54.   GetPalette := @P;
  55. end;
  56.  
  57. constructor TStatusDialog.Init(var Bounds: TRect);
  58. var
  59.   R: TRect;
  60. begin
  61.   inherited Init(Bounds, '');
  62.   Flags := 0;
  63.   R.Assign(1, 2, Size.X - 1, 7);
  64.   Insert(New(PParamText, Init(R,
  65.     'To Move:  %s'#13 +
  66.     'White:    %s'#13 +
  67.     'Black:    %s'#13 +
  68.     'Nodes:    %d'#13, 4)));
  69.   R.Assign(1, Size.Y - 10, Size.X - 1, Size.Y - 9);
  70.   Insert(New(PStaticText, Init(R, 'Bestline:')));
  71.   R.Assign(1, Size.Y - 9, Size.X - 1, Size.Y - 1);
  72.   Insert(New(PBestLine, Init(R, '%s', 1)));
  73.   SetData(GameStatus);
  74. end;
  75.  
  76. function TStatusDialog.GetPalette: PPalette;
  77. const
  78.   P: string[Length(CStatusDialog)] = CStatusDialog;
  79. begin
  80.   GetPalette := @P;
  81. end;
  82.  
  83. {$V-}
  84. procedure TStatusDialog.Update(Game: HChess;
  85.   ATimers: array of PChessTimer);
  86. var
  87.   MLine: array[0..10] of TMove;
  88.   MainValue: Integer;
  89.   Str: array[0..20] of Char;
  90.   I: Integer;
  91.   Params: array[0..3] of Longint;
  92.  
  93.   procedure GetTime(ATimer: PChessTimer;
  94.     var Hours, Minutes, Seconds, Ticks: Longint);
  95.   var
  96.     H, M, S, T: Word;
  97.   begin
  98.     ConvertTicks(ATimer^.GetCurrentTicks, H, M, S, T);
  99.     Hours := H;
  100.     Minutes := M;
  101.     Seconds := S;
  102.     Ticks := T;
  103.   end;
  104.  
  105. begin
  106.   if GetPlayer(Game) = cWhite then
  107.     CurPlayer := 'White'
  108.   else CurPlayer := 'Black';
  109.   GameStatus.Nodes := GetNodes(Game);
  110.   for I := Low(ATimers) to High(ATimers) do
  111.   begin
  112.     GetTime(ATimers[I], Params[0], Params[1], Params[2], Params[3]);
  113.     FormatStr(TimeStrs[TColor(I)], '%02d:%02d:%02d.%02d', Params);
  114.   end;
  115.   GetMainLine(Game, MainValue, MLine);
  116.   BestLine := '';
  117.   for I := Low(MLine) to High(MLine) do
  118.   begin
  119.     if MLine[I].Change.Piece <> pEmpty then
  120.     begin
  121.       MoveToStr(MLine[I], Str);
  122.       BestLine := BestLine + StrPas(Str) + ' ';
  123.     end else Break;
  124.   end;
  125.   SetData(GameStatus);
  126. end;
  127.  
  128. end.