Skip to content

Commit

Permalink
Change search thread priority
Browse files Browse the repository at this point in the history
  • Loading branch information
rchastain committed Mar 27, 2020
1 parent d7916e9 commit 52740ea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 4 additions & 3 deletions alouette.pas
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ procedure TSearchThread.Execute;
if not Terminated then
begin
Send(Format('bestmove %s', [LMove]));
Log.Append(Format('Meilleur coup trouvé en %0.3f s.', [LTimeUsed / 1000]));
Log.Append(Format('Meilleur coup trouvé en %0.3f s.', [LTimeUsed / 1000]), TRUE);
end;
end;

Expand Down Expand Up @@ -163,15 +163,16 @@ procedure TSearchThread.Execute;
with LThread do
begin
FreeOnTerminate := TRUE;
Priority := tpHigher;
//Priority := tpHigher;
Priority := tpNormal;
Start;
end;
end else
if LCmd = 'stop' then
begin
Send(Format('bestmove %s', [Player.InstantMove]));
if Assigned(LThread) then
LThread.Terminate;
Send(Format('bestmove %s', [Player.InstantMove]));
end else
if BeginsWith('setoption name UCI_Chess960 value ', LCmd) then
SetVariant(WordPresent('true', LCmd))
Expand Down
4 changes: 3 additions & 1 deletion best.pas
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ function GetBestMove(const APos: TPosition; const AVariant: boolean; const ATime
for i := 0 to Pred(n) do
LEval[i] := PositionalEval(APos, LListe[i]);
SortMoves(LListe, LEval, n);
LMove := LListe[0];
//LMove := LListe[0];
n := CountBestMoves(LEval, n);
LMove := LListe[Random(n)];
if IsCastling(APos, LMove) and not AVariant then
begin
Assert(((LMove and $FF00) shr 8) mod 8 = CColE);
Expand Down
2 changes: 1 addition & 1 deletion castling.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ procedure Search(const AKingTarget, ARookTarget: integer); { Colonnes d'arrivée
k := ToIndex(AKingTarget, LRow);
j := ToIndex(LRookStart, LRow);
l := ToIndex(ARookTarget, LRow);
Log.Append(Format('Vérifications pour roi %s tour%s...', [MoveToStr(i, k), MoveToStr(j, l)]));
Log.Append(Format('Vérifications pour roi %s tour %s...', [MoveToStr(i, k), MoveToStr(j, l)]));
if IsOn(APos.Pieces[APos.SideToMove] and APos.Rooks, CIndexToSquare[j]) then
Log.Append('Position tour vérifiée (condition 1/3).')
else
Expand Down
18 changes: 11 additions & 7 deletions player.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface
procedure Reset;
procedure LoadStartPosition;
procedure DoMove(const AMove: string);
function BestMove(const ATimeForMove: integer): string;
function BestMove(const ATimeAvailable: integer): string;
function InstantMove: string;
procedure SetVariant(const AValue: boolean);
function CurrentVariant: boolean;
Expand All @@ -32,38 +32,41 @@ implementation

procedure Reset;
begin
//Log.Append(Format('%s %s %s', [{$I %FILE%}, {$I %LINE%}, 'Reset']));
LPos := CZeroPosition;
end;

procedure LoadStartPosition;
begin
//Log.Append(Format('%s %s %s', [{$I %FILE%}, {$I %LINE%}, 'LoadStartPosition']));
LPos := EncodePosition;
NewHistory;
end;

procedure DoMove(const AMove: string);
begin
//Log.Append(Format('%s %s %s(%s)', [{$I %FILE%}, {$I %LINE%}, 'DoMove', AMove]));
if TryDoMove(LPos, AMove) then
History.AppendMove(AMove)
else
Log.Append(Format('ImIsMovePossible de jouer %s.', [AMove]));
Log.Append(Format('Impossible de jouer %s.', [AMove]));
end;

function BestMove(const ATimeForMove: integer): string;
function BestMove(const ATimeAvailable: integer): string;
begin
result := GetBestMove(LPos, LVariant, ATimeForMove);
//Log.Append(Format('%s %s %s(%d)', [{$I %FILE%}, {$I %LINE%}, 'BestMove', ATimeAvailable]));
result := GetBestMove(LPos, LVariant, ATimeAvailable);
end;

function InstantMove: string;
begin
//Log.Append(Format('%s %s %s', [{$I %FILE%}, {$I %LINE%}, 'InstantMove']));
result := LTempMove;
end;

procedure SetVariant(const AValue: boolean);
const
CPrefix: array[boolean] of string = ('dés', '');
begin
Log.Append(Format('Option échecs 960 %sactivée.', [CPrefix[AValue]]));
Log.Append(Format('%s %s %s(%d)', [{$I %FILE%}, {$I %LINE%}, 'SetVariant', Ord(AValue)]));
LVariant := AValue;
end;

Expand All @@ -74,6 +77,7 @@ function CurrentVariant: boolean;

procedure SetPosition(const APos: string);
begin
//Log.Append(Format('%s %s %s(%s)', [{$I %FILE%}, {$I %LINE%}, 'SetPosition', APos]));
LPos := EncodePosition(APos, LVariant);
NewHistory;
end;
Expand Down

0 comments on commit 52740ea

Please sign in to comment.