From 29952d0959525036dd3eae235fbde31249227b6f Mon Sep 17 00:00:00 2001 From: Roland Chastain Date: Mon, 6 Jan 2020 09:05:03 +0100 Subject: [PATCH] Add command stop --- source/eschecs.pas | 14 ++++++++++++++ source/uci.pas | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/source/eschecs.pas b/source/eschecs.pas index 7a4d237..31926e1 100644 --- a/source/eschecs.pas +++ b/source/eschecs.pas @@ -98,6 +98,8 @@ TMainForm = class(TfpgForm) FXLegend, FYLegend, FXLegendInv, FYLegendInv: TBGRABitmap; FChess960: boolean; FOpeningName: string; + FSendMsgGoTime: cardinal; + FCheckTimeElapsed: boolean; procedure HandleKeyPress(var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); override; public destructor Destroy; override; @@ -527,6 +529,7 @@ procedure TMainForm.InitForm; BGRABitmapVersionStr ])); + FCheckTimeElapsed := FALSE; FTimer := TfpgTimer.Create(10); FTimer.OnTimer := @InternalTimerFired; FTimer.Enabled := TRUE; @@ -786,6 +789,14 @@ procedure TMainForm.InternalTimerFired(Sender: TObject); var LAnimationTerminated: boolean; begin + if FWaiting and FCheckTimeElapsed then + begin + if GetTickCount64 - FSendMsgGoTime > FMoveTime then + begin + Send(MsgStop); + FCheckTimeElapsed := FALSE; + end; + end; if FChessboard.Animate(LAnimationTerminated) or FComputerCastling then FChessboardWidget.Invalidate else @@ -803,6 +814,7 @@ procedure TMainForm.InternalTimerFired(Sender: TObject); end; 1: begin + FCheckTimeElapsed := FALSE; end; 2: begin @@ -812,6 +824,8 @@ procedure TMainForm.InternalTimerFired(Sender: TObject); FWaiting := TRUE; FStatusBar.Text := GetText(txWaiting); FWaitingForUserMove := FALSE; + FCheckTimeElapsed := TRUE; + FSendMsgGoTime := GetTickCount64; end; end; end; diff --git a/source/uci.pas b/source/uci.pas index 1315a17..d5ec0ec 100644 --- a/source/uci.pas +++ b/source/uci.pas @@ -9,6 +9,7 @@ function MsgNewGame: string; function MsgIsReady: string; function MsgPosition(const AFenPosition: string): string; function MsgGo(const AMoveTime: integer): string; +function MsgStop: string; function MsgQuit: string; function IsMsgUciOk(const AMsg: string; out AEngineName, AAuthor: string; out AOptChess960: boolean): boolean; @@ -28,6 +29,7 @@ implementation ucIsReady, ucPosition, ucGo, + ucStop, ucQuit ); @@ -39,6 +41,7 @@ implementation 'isready', 'position fen %s', 'go movetime %d', + 'stop', 'quit' ); @@ -72,6 +75,11 @@ function MsgGo(const AMoveTime: integer): string; result := Format(CPatterns[ucGo], [AMoveTime]); end; +function MsgStop: string; +begin + result := CPatterns[ucStop]; +end; + function MsgQuit: string; begin result := CPatterns[ucQuit];