This is strange ?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

This is strange ?

Post by lauriet »

I have found that in one game, my program locked up when it reaches depth = 11 in the iterative search.

If I change the first block of code to the second block it then works ???
But the code gives the same logic/conditions ???
(I'm using Free Pascal).
Have I missed something ?

(the indenting has been mangled by 'talkchess' Doh !)


This code fails:
{----- now try a null move looking for a cutoff and an early exit -----}
IF NullAllowed AND
NOT Check AND {-- you cant pass when in check }
NOT OnlyPawns(Wtm) AND {-- risk zugswag....it will be rare }
(Depth > 2) THEN
BEGIN
SwapSides;
Score := -Search(-Beta, -Beta + 1, Depth - 2, False); {-- shallow null window search }
SwapSides; {-- we only want to know if its > Beta }

IF (Score >= Beta) THEN {-- we beat beta so we wont be going down this line }
BEGIN
Inc(BetaCuts);
Inc(NullCuts);
AddToTT(Data[Ply].ZorbistKey, Score, FailHigh, Depth, 'NULL');
Exit(Beta);
END;
END;


This code works:
{----- now try a null move looking for a cutoff and an early exit -----}
IF NullAllowed AND
NOT Check AND {-- you cant pass when in check }
NOT OnlyPawns(Wtm) THEN {-- risk zugswag....it will be rare }
BEGIN
IF Depth > 2 THEN
BEGIN
SwapSides;
Score := -Search(-Beta, -Beta + 1, Depth - 2, False); {-- shallow null window search }
SwapSides; {-- we only want to know if its > Beta }

IF (Score >= Beta) THEN {-- we beat beta so we wont be going down this line }
BEGIN
Inc(BetaCuts);
Inc(NullCuts);
AddToTT(Data[Ply].ZorbistKey, Score, FailHigh, Depth, 'NULL');
Exit(Beta);
END;
END;
END;
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: This is strange ?

Post by Pio »

lauriet wrote: Tue May 26, 2020 5:00 am I have found that in one game, my program locked up when it reaches depth = 11 in the iterative search.

If I change the first block of code to the second block it then works ???
But the code gives the same logic/conditions ???
(I'm using Free Pascal).
Have I missed something ?

(the indenting has been mangled by 'talkchess' Doh !)


This code fails:
{----- now try a null move looking for a cutoff and an early exit -----}
IF NullAllowed AND
NOT Check AND {-- you cant pass when in check }
NOT OnlyPawns(Wtm) AND {-- risk zugswag....it will be rare }
(Depth > 2) THEN
BEGIN
SwapSides;
Score := -Search(-Beta, -Beta + 1, Depth - 2, False); {-- shallow null window search }
SwapSides; {-- we only want to know if its > Beta }

IF (Score >= Beta) THEN {-- we beat beta so we wont be going down this line }
BEGIN
Inc(BetaCuts);
Inc(NullCuts);
AddToTT(Data[Ply].ZorbistKey, Score, FailHigh, Depth, 'NULL');
Exit(Beta);
END;
END;


This code works:
{----- now try a null move looking for a cutoff and an early exit -----}
IF NullAllowed AND
NOT Check AND {-- you cant pass when in check }
NOT OnlyPawns(Wtm) THEN {-- risk zugswag....it will be rare }
BEGIN
IF Depth > 2 THEN
BEGIN
SwapSides;
Score := -Search(-Beta, -Beta + 1, Depth - 2, False); {-- shallow null window search }
SwapSides; {-- we only want to know if its > Beta }

IF (Score >= Beta) THEN {-- we beat beta so we wont be going down this line }
BEGIN
Inc(BetaCuts);
Inc(NullCuts);
AddToTT(Data[Ply].ZorbistKey, Score, FailHigh, Depth, 'NULL');
Exit(Beta);
END;
END;
END;
Hi Lauriet!
In Free Pascal the order of evaluating expressions might not be in the order you have written the expressions (the optimiser might decide differently). See https://www.freepascal.org/docs-html/ref/refch12.html. I guess one (or more) of your Boolean functions/properties has a side effect or throws an exception but in the second code block you got lucky and the optimiser changed the execution order and the problematic function was not called.

/Pio
zenpawn
Posts: 349
Joined: Sat Aug 06, 2016 8:31 pm
Location: United States

Re: This is strange ?

Post by zenpawn »

lauriet wrote: Tue May 26, 2020 5:00 am (the indenting has been mangled by 'talkchess' Doh !)
To maintain formatting, etc., you can use a code block:

Code: Select all

no indent
  two space indent
    four space indent
	tab indent
Erin Dame
Author of RookieMonster
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: This is strange ?

Post by Joost Buijs »

These are bugs in Free Pascal.

I maintain a Pascal version of my engine too and noticed several times that Free-Pascal has not the quality like most C compilers have.
On several occasions I had quirks like this, usually I could fix them the same way you did by using an additional begin-end block.

Currently I use Lazarus 2.1 with Free Pascal 3.3.1 (64 bit), this gives me the least headache.