Skip to content

Commit

Permalink
Add command stop
Browse files Browse the repository at this point in the history
  • Loading branch information
rchastain committed Jan 6, 2020
1 parent a2c3b95 commit 29952d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/eschecs.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -527,6 +529,7 @@ procedure TMainForm.InitForm;
BGRABitmapVersionStr
]));

FCheckTimeElapsed := FALSE;
FTimer := TfpgTimer.Create(10);
FTimer.OnTimer := @InternalTimerFired;
FTimer.Enabled := TRUE;
Expand Down Expand Up @@ -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
Expand All @@ -803,6 +814,7 @@ procedure TMainForm.InternalTimerFired(Sender: TObject);
end;
1:
begin
FCheckTimeElapsed := FALSE;
end;
2:
begin
Expand All @@ -812,6 +824,8 @@ procedure TMainForm.InternalTimerFired(Sender: TObject);
FWaiting := TRUE;
FStatusBar.Text := GetText(txWaiting);
FWaitingForUserMove := FALSE;
FCheckTimeElapsed := TRUE;
FSendMsgGoTime := GetTickCount64;
end;
end;
end;
Expand Down
8 changes: 8 additions & 0 deletions source/uci.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@ implementation
ucIsReady,
ucPosition,
ucGo,
ucStop,
ucQuit
);

Expand All @@ -39,6 +41,7 @@ implementation
'isready',
'position fen %s',
'go movetime %d',
'stop',
'quit'
);

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 29952d0

Please sign in to comment.