]> git.sesse.net Git - stockfish/log
stockfish
11 years agoRetire history.h
Marco Costalba [Sat, 2 Feb 2013 15:04:41 +0000 (16:04 +0100)]
Retire history.h

And move the contents to movepick.cpp, where they are
mostly used.

Idea from DiscoCheck.

No functional change (bench 5379503)

11 years agoRestore "fail-low of reduced" and close regression
Marco Costalba [Sat, 2 Feb 2013 05:44:20 +0000 (06:44 +0100)]
Restore "fail-low of reduced" and close regression

This reverts "Threat Extensions" and is the last of
this revert series.

In single-thread tests we should now be on par with 2.3.1

11 years agoRevert "Simplify Evaluation"
Marco Costalba [Sat, 2 Feb 2013 05:43:11 +0000 (06:43 +0100)]
Revert "Simplify Evaluation"

This reverts commit 496c7497cb81de4383

11 years agoRevert "Extend full 3 fold detection to PvNodes"
Marco Costalba [Mon, 28 Jan 2013 16:24:01 +0000 (17:24 +0100)]
Revert "Extend full 3 fold detection to PvNodes"

11 years agoRewrite do_castle_move()
Marco Costalba [Sun, 27 Jan 2013 17:48:27 +0000 (18:48 +0100)]
Rewrite do_castle_move()

And handle the castle directly in do/undo_move().
This allow to greatly simplify the code.

Here the beast is the nasty Chess960 that is
really tricky to get it right because could be
that 'from' and 'to' squares are the same or
that king's 'to' square is rook's 'from' square.

Anyhow should work: verified on all Chess960
starting positions.

No functional and no speed change also in Chess960.

11 years agoRewrite do_null_move()
Marco Costalba [Sun, 27 Jan 2013 10:45:01 +0000 (11:45 +0100)]
Rewrite do_null_move()

Use a more traditional approach, along the same lines
of do_move().

It is true that we copy more in do_null_move(), but we
save the work in undo_null_move(). Speed test shows the
new code to be even a bit faster.

No functional change.

11 years agoGet rid of some locals in do_castle_move()
Marco Costalba [Sun, 27 Jan 2013 09:56:03 +0000 (10:56 +0100)]
Get rid of some locals in do_castle_move()

Rewrite the logic to get rid of kBefore and rBefore.

No functional change.

11 years agoDon't prefetch if not needed
Marco Costalba [Sun, 27 Jan 2013 09:15:59 +0000 (10:15 +0100)]
Don't prefetch if not needed

Prefetch access to hash tables only in case we
have changed pawn or material hash keys.

No functional change.

11 years agoRetire generate_king_moves()
Marco Costalba [Sat, 26 Jan 2013 21:07:28 +0000 (22:07 +0100)]
Retire generate_king_moves()

We have only one call place so inline its content.
BTW, function is already declared as FORCE_INLINE.

Also some small refactoring while there.

No functional change.

11 years agoClarify slavesMask usage
Marco Costalba [Sat, 26 Jan 2013 13:23:37 +0000 (14:23 +0100)]
Clarify slavesMask usage

When a thread is allocated a bit is set in slavesMask.
This bit corresponds to the thread's index field that,
because it happens to be the position in the threads
array, eventually it is equal to the loop index 'i'.

But instead of relying on this 'coincidence', explicitly
use the 'idx' field so to clarify slavesMask usage.

Backported from c++11 branch.

No functional change.

11 years agoRevert "Further push singular extension"
Marco Costalba [Mon, 21 Jan 2013 22:14:10 +0000 (23:14 +0100)]
Revert "Further push singular extension"

This reverts commit 4c91dbc28e8bb6265f8

Seems a regression on extended test by both Gary and me.

11 years agoMerge branch 'simplify_eval' of https://github.com/glinscott/Stockfish
Marco Costalba [Fri, 25 Jan 2013 20:01:24 +0000 (21:01 +0100)]
Merge branch 'simplify_eval' of https://github.com/glinscott/Stockfish

Test results are looking good after 12500 games.

ELO: 6.55 +- 99%: 8.02 95%: 6.09
LOS: 99.99%
Wins: 1968 Losses: 1732 Draws: 8813

Also, here are the noise.py results, which seem to have stabilized:
Games: 12526 , result: [1969, 1734, 8823]
Estimated ELO: 6.94963842777
Noise as function of number of games:
['81.89', '565.26', '110.87', '104.39', '38.22', '49.98', '18.56', '16.76',
'11.02', '8.90', '17.36', '9.84', '10.81', '5.13', '6.22', '3.32', '5.83',
'7.21', '15.27', '1.63', '4.04', '9.51', '0.54', '0.75', '1.06', '2.93',
'4.59', '6.85', '13.62', '9.87', '14.74', '20.46', '22.18', '24.33', '31.02',
'34.99', '35.22', '33.22', '32.46', '37.02', '29.10', '36.34', '42.11', '39.33',
'26.16', '28.25', '35.42', '31.04', '29.26', '23.91', '22.52', '23.49', '20.00',
'24.39', '17.22', '16.50', '10.69', '9.15', '9.57', '4.77', '6.67', '3.87', '2.57',
'2.84', '2.60', '3.32', '2.08', '2.93', '4.47', '4.41', '4.83', '4.86', '6.40',
'5.98', '6.10', '6.83', '5.83', '6.22', '5.71', '8.52', '9.25', '5.98', '7.52',
'7.76', '8.76', '8.55', '8.64', '7.19', '5.83', '4.59', '4.77', '4.26', '4.98',
'5.29', '5.41', '4.92', '5.59']

bench: 5229106

11 years agoSimplify evaluation
Gary Linscott [Thu, 24 Jan 2013 13:54:13 +0000 (08:54 -0500)]
Simplify evaluation

11 years agoSmall reformat of split()
Marco Costalba [Mon, 21 Jan 2013 16:22:31 +0000 (17:22 +0100)]
Small reformat of split()

No functional chhange.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix an idiotic icc warning
Marco Costalba [Sun, 20 Jan 2013 16:24:06 +0000 (17:24 +0100)]
Fix an idiotic icc warning

Intel Compiler has 'invented' this pearl:

warning #1476: field uses tail padding of a base class

Just becuase we have subclassed MainThread and added
the field 'bool thinking'.

Pure nosense. Silence the warning.

No functional change.

11 years agoFuther renaming in thread.cpp
Marco Costalba [Sun, 20 Jan 2013 10:54:30 +0000 (11:54 +0100)]
Futher renaming in thread.cpp

No functional change.

11 years agoBig renaming in thread stuff
Marco Costalba [Wed, 16 Jan 2013 08:28:41 +0000 (09:28 +0100)]
Big renaming in thread stuff

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix race while exiting
Marco Costalba [Wed, 16 Jan 2013 08:26:10 +0000 (09:26 +0100)]
Fix race while exiting

Fix again TimerThread::idle_loop() to prevent a
theoretical race with 'exit' flag in ~Thread().

Indeed in Thread d'tor we raise 'exit' and then
call notify() that is lock protected, so we
have to check again for 'exit' before going to
sleep in idle_loop().

Also same change in Thread::idle_loop() where we
now check for 'exit' before to go to sleep.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRemove Threat Extension
Lucas Braesch [Tue, 1 Jan 2013 03:51:35 +0000 (11:51 +0800)]
Remove Threat Extension

Great code simplification: - instead do not futility
prune threat refutations. allows_move() is therefore removed.

4000 games at 50,000 nodes/move:
1085-989-1926 [51.2%] LOS=98.3%

4000 games in 10"+0.1"
756-751-2493 [50.1%] LOS=55.1%

EDIT: I have retested the patch of Lucas in a slightly different form
(without pruning in PvNode) and test mre or less confirms that
60 lines of code are totally unuseful:

After 6195 games at 15"+0.05"
1333 - 1325 - 3537 ELO 0

bench 5140990

11 years agoFix a bug in timer loop
Marco Costalba [Mon, 14 Jan 2013 18:32:30 +0000 (19:32 +0100)]
Fix a bug in timer loop

Silly logic bug introduced in dda7de17e74d7e8

Timer thread, when msec = 0, instead of going
to sleep, calls check_time() in an endless loop.

Spotted and reported by snino64 due to abnormally
high CPU usage.

No functional change.

11 years agoPolymorphic Thread hierarchy
Marco Costalba [Sun, 13 Jan 2013 23:32:30 +0000 (00:32 +0100)]
Polymorphic Thread hierarchy

Subclass MainThread and TimerThread and declare
idle_loop() virtual. This allow us to cleanly
remove a good bunch of hacks, relying on C++
polymorphism to do the job.

No functional change.

11 years agoDon't use do_sleep flag
Marco Costalba [Sun, 13 Jan 2013 17:38:44 +0000 (18:38 +0100)]
Don't use do_sleep flag

Rename it is_finished and use it only in main
thread to signal search is finished. This allows
us to simplify the complex SMP logic.

Ultra tricky patch: deep test is required under
wide conditions like pondering on and option
"Use Sleeping Threads" set to false.

No functional change.

11 years agoRe-add the hack
Marco Costalba [Sun, 13 Jan 2013 22:51:15 +0000 (23:51 +0100)]
Re-add the hack

This reverts commit 869c9244101

I misunderstood here. Actually it can happen that
thread is created but still not entered idle_loop
and at the same time start_searching() is called.

Becuase 'do_sleep' is set start_searching() will
set it to false and start the search, but when,
at last, the thread enters idle_loop(), resets
the flag and goes to sleep: not what we want.

Revert the hack waiting for a better solution
in the next patches.

No functional change.

11 years agoRetire set_timer()
Marco Costalba [Sun, 13 Jan 2013 17:22:33 +0000 (18:22 +0100)]
Retire set_timer()

Also assure in Thread::timer_loop() that when
timer interval is 0 (timer is disabled) we
never call check_time()

No functional change.

11 years agoRetire obsolete race hack
Marco Costalba [Sun, 13 Jan 2013 16:04:39 +0000 (17:04 +0100)]
Retire obsolete race hack

This hack was introduced in d282cf6964d493
to workaround a race with start_searching(),
but these days is no more needed.

No functional change.

11 years agoRetire Threads wake_up() and sleep()
Marco Costalba [Sun, 13 Jan 2013 14:50:57 +0000 (15:50 +0100)]
Retire Threads wake_up() and sleep()

These functions are used in just one place.
And generalize wait_for_stop()

No functional change.

11 years agoRename wake_up() to notify_one()
Marco Costalba [Sun, 13 Jan 2013 14:35:38 +0000 (15:35 +0100)]
Rename wake_up() to notify_one()

To align to C++ std::thread conventions.

No functional change.

11 years agoUnify 'ponderhit' handling
Marco Costalba [Sun, 13 Jan 2013 13:36:27 +0000 (14:36 +0100)]
Unify 'ponderhit' handling

Finally we can now merge the 'ponderhit' case with
'stop' and 'quit'.

The patches have been done step by step to help debugging
becuase this is really tricky code.

No functional change.

11 years agoSmall change to "ponderhit" handling
Marco Costalba [Sun, 13 Jan 2013 13:28:22 +0000 (14:28 +0100)]
Small change to "ponderhit" handling

Reset Limits.ponder only if search continue, but if
we are going to stop the search there is no need
(and is also confusing) to clear the 'ponder' flag.

This mimics the behaviour upon rceiving 'stop' when
pondering.

No functional change.

11 years agoSimplify and rename wait_for_stop_or_ponderhit()
Marco Costalba [Sun, 13 Jan 2013 13:15:19 +0000 (14:15 +0100)]
Simplify and rename wait_for_stop_or_ponderhit()

Setting stopOnPonderhit is now done by the caller.

No functional change.

11 years agoSimplify a condition in search()
Marco Costalba [Sun, 13 Jan 2013 11:34:31 +0000 (12:34 +0100)]
Simplify a condition in search()

And rearrange best value update in case of SpNode.

No functional change.

11 years agoClarify SAN disambiguation in case of a pinned piece
Marco Costalba [Sat, 12 Jan 2013 12:19:06 +0000 (13:19 +0100)]
Clarify SAN disambiguation in case of a pinned piece

In SAN notation when two pieces of the same type can
move to a given destination square, a disambiguation
additional info (like starting file) shall be added
to the SAN move.

If one of the two pieces is pinned, the corresponding
move _could_ be illegal and in this case disambiguation
is not needed. But to be pinned alone it is not enough
to deduce that the move is illegal, for instance in this
position:

R3rk2/2r6/8/8/8/8/8/K7 b - - 0 1

The move Rc8 is ambiguous although the rook in e8 is pinned
and the correct SAN notation should be Rcc8.

No functional change.

11 years agoAsync 'stop' command
Marco Costalba [Sun, 6 Jan 2013 11:49:01 +0000 (12:49 +0100)]
Async 'stop' command

Don't wait for the search to finish after a 'stop'
command, but keep processing the GUI input if any.

Also explicitly wake up the main thread (that could be
sleeping) after a 'stop' or 'quit' command and do not
rely on wait_for_search_finished() doing it for us.

This patch cleans up the code and functions's definitions,
but it is risky and needs a good test under different
conditions to be sure it does not introduces hungs up.

No functional change.

11 years agoRevert so called "fromNull patch"
Marco Costalba [Sun, 6 Jan 2013 21:55:35 +0000 (22:55 +0100)]
Revert so called "fromNull patch"

Revert patch c581b7ea3627482

Seems a regression after testing from Gary:
ELO: 7.24 +- 99%: 17.03 95%: 12.93
LOS: 97.86%
Wins: 439 Losses: 381 Draws: 1962

And mine:
After 5410 games at 15"+0.05
Wins: 936 Losses: 1141 Draws: 3333  ELO -13

Moreover we know that there is a regression in the range
of patches which include the fromNull patch.

Probably this is not the only regression since 2.3.1 and
perhaps the idea under fromNull is good, but at the moment,
while in deep regression hunting, better to be on the safe
side and revert it entirely.

My guess on why this is a regression is that using the
negated evaluation of previous ply in case of null search
fails to take in account the king safety asymmetry between
the two colors. This is of course just a guess.

bench 5503830

11 years agoHave fun with union in book.cpp
Marco Costalba [Sat, 5 Jan 2013 14:24:18 +0000 (15:24 +0100)]
Have fun with union in book.cpp

Fancy way to use an union to map polyglot
zobrist keys in one go.

Also some renaming while there.

No functional change.

11 years agoRetire 'Cowardice' and 'Aggressiveness' UCI options
Marco Costalba [Fri, 4 Jan 2013 15:49:24 +0000 (16:49 +0100)]
Retire 'Cowardice' and 'Aggressiveness' UCI options

They are not self-describing and create a lot of user
requests about them.

Given that the values are already well tuned there
is no need to expose them as UCI options.

No functional change.

11 years agoRetire 'mate in x' hack
Marco Costalba [Fri, 4 Jan 2013 15:29:13 +0000 (16:29 +0100)]
Retire 'mate in x' hack

Sometimes is faster, but not always and on very long mates
produces strange scores probably due to truncation of PV
artifacts.

So simply perform normal search also in case of UCI 'mate x'
command, with the only difference that when a mate in x is
found search returns immediately.

No functional change.

11 years agoDon't exit if unable to find bench file
Marco Costalba [Fri, 4 Jan 2013 13:52:21 +0000 (14:52 +0100)]
Don't exit if unable to find bench file

Now that we can call 'bench' command also from
interactive terminal it makes no more sense to
exit the application if the user types a wrong
file name.

No functional change.

11 years agoTeach file_to_char() about upper/lower case
Marco Costalba [Fri, 4 Jan 2013 13:10:35 +0000 (14:10 +0100)]
Teach file_to_char() about upper/lower case

This allows to further simplify Position::fen()

No functional change.

11 years agoReformat FEN construction
Marco Costalba [Fri, 4 Jan 2013 11:32:13 +0000 (12:32 +0100)]
Reformat FEN construction

Simplify and shrink code.

No functional change.

11 years agoRemove some obsolete asserts on TT values
Marco Costalba [Mon, 31 Dec 2012 15:28:40 +0000 (16:28 +0100)]
Remove some obsolete asserts on TT values

Now that insert_pv_in_tt() stores VALUE_NONE in
TT's position evaluation those 2 asserts are
obselete.

No functional change.

11 years agoAllow to pass a 'seed' to RKISS
Marco Costalba [Mon, 31 Dec 2012 10:57:49 +0000 (11:57 +0100)]
Allow to pass a 'seed' to RKISS

This somewhat simplifies the code.

Suggested by Lucas Braesch.

No functional change.

11 years agoMicro-optimization in evaluate_space()
Marco Costalba [Mon, 31 Dec 2012 10:26:12 +0000 (11:26 +0100)]
Micro-optimization in evaluate_space()

Since &-ing with SpaceMask restricts the set to the home
half of the board, it is possible to use just one popcount
instead of 2 by shifting "safe" to the other half of the
board. This gives a small speedup especially on systems
where hardware popcount is not available.

Patch kindly sent by Richard Vida.

No functional change.

11 years agoAdd 'mate' limit to 'bench' command
Marco Costalba [Sun, 30 Dec 2012 14:48:37 +0000 (15:48 +0100)]
Add 'mate' limit to 'bench' command

It is now possible to run SF on a 'mate in x' testsuite.

For instance in case of a file with fen strings of
positions with mate in 10 we can now 'bench' on it:

stockfish bench 128 1 10 mate_in_10.epd mate

No functional change.

11 years agoHandle UCI command "mate in x moves"
Marco Costalba [Sun, 30 Dec 2012 10:40:20 +0000 (11:40 +0100)]
Handle UCI command "mate in x moves"

Following a user request I added the handling of UCI:

go mate x

Currently we just return from a PV node if x moves have been
done. Probably not the best approach. I have looked at Fruit/Toga
sources and there is even simpler: engine falls back on a fixed
depth search.

No functional change.

11 years agoRevert evaluation cache
Marco Costalba [Thu, 27 Dec 2012 11:13:31 +0000 (12:13 +0100)]
Revert evaluation cache

And return on using TT as backing store for position
evaluations.

Tests (even on single thread) show eval cache was a regression.
In multi thread result should be even worst because eval cache
is a per-thread struct, while TT is shared.

After 4957 games at 15"+0.05 (single thread)
eval cache vs master 969 - 1093 - 2895  -9 ELO

So previous reported result of +18 ELO was probably due to an
issue in the testing framework (a bug in cutechess-cli) that
has been fixed in the meanwhile.

bench: 5386711

11 years agoAdd list of legal moves to Position::pretty()
Marco Costalba [Thu, 27 Dec 2012 10:08:20 +0000 (11:08 +0100)]
Add list of legal moves to Position::pretty()

Along the same lines of previous patch now we add
the list of the legal moves in the given position.

No functional change.

11 years agoAdd checkers info to Position::pretty()
Marco Costalba [Wed, 26 Dec 2012 17:22:56 +0000 (18:22 +0100)]
Add checkers info to Position::pretty()

In case current position is under check, list the
squares of the checker(s) pieces.

This should satisfy a specific user request.

No functional change.

11 years agoRemove two obsolete asserts in prevents_move
Marco Costalba [Wed, 26 Dec 2012 11:27:09 +0000 (12:27 +0100)]
Remove two obsolete asserts in prevents_move

Now that this function is called also to calculate
move's extensions the asserts are no more valid.

No functional change.

11 years agoRename yields_to_threat and prevents_threat
Marco Costalba [Wed, 26 Dec 2012 11:15:55 +0000 (12:15 +0100)]
Rename yields_to_threat and prevents_threat

Follow Lucas suggestions and better name these
two functions.

No functional change.

11 years agoIntroduce Null Threat extension
Marco Costalba [Mon, 24 Dec 2012 08:07:17 +0000 (09:07 +0100)]
Introduce Null Threat extension

In case of null search at low depths returns a fail low
due to a threat then, rather than return beta-1 (to cause
a re-search at full depth in the parent node), we set a flag
threatExtension = true (false by default) that will cause
moves that prevent the threat to be extended of one ply
in the following search.

Idea and patch is by Lucas Braesch.

Lucas also did the tests:
1500 games in 5"+0.05":
SF_threatExtension vs SF_20121222: 366 - 331 - 803 [51.2%] LOS=90.8%

3000 games in 10"+0.1":
SF_threatExtension vs SF_20121222: 610 - 559 - 1831 [50.8%] LOS=93.2%

Tests confirmed by Gary after 10570 games,
ELO: 2.79 +- 99%: 8.72 95%: 6.63
LOS: 94.08%
Wins: 1523 Losses: 1438 Draws: 7607

And finally by me at 15"+0.05, single thread, 3824 games
threatExtension vs master 768 - 692 - 2364  +7 ELO

bench 4918443

11 years agoFix a couple of extra spaces
Marco Costalba [Tue, 25 Dec 2012 17:48:41 +0000 (18:48 +0100)]
Fix a couple of extra spaces

No functional change.

11 years agoRetire Position::in_check()
Marco Costalba [Tue, 25 Dec 2012 16:59:35 +0000 (17:59 +0100)]
Retire Position::in_check()

It is redundant with Position::checkers()

No functional change.

11 years agoRetire Position::move_is_legal()
Marco Costalba [Tue, 25 Dec 2012 10:40:28 +0000 (11:40 +0100)]
Retire Position::move_is_legal()

Use the new contains() method of struct MoveList

No functional change.

11 years agoSmall tweak in is_pseudo_legal()
Marco Costalba [Tue, 25 Dec 2012 10:22:55 +0000 (11:22 +0100)]
Small tweak in is_pseudo_legal()

This is difficult code becuase a bug here could lead
to very subtle crashes in case of SMP games where we
have TT move corruption due to concurrent access.

Anyhow I have fully verified te code throwing at it
random moves. It shoudl work.

No functional change.

11 years agoIntroduce namespace Pawns
Marco Costalba [Sat, 22 Dec 2012 10:21:06 +0000 (11:21 +0100)]
Introduce namespace Pawns

And retire old struct PawnTable along the same lines
of previous patch.

No functional change.

11 years agoIntroduce namespace Material
Marco Costalba [Sun, 16 Dec 2012 11:00:54 +0000 (12:00 +0100)]
Introduce namespace Material

And retire old struct MaterialTable simplifying the code.

No functional change.

11 years agoDon't need to check for bestValue < beta to split
Marco Costalba [Sat, 15 Dec 2012 12:11:10 +0000 (13:11 +0100)]
Don't need to check for bestValue < beta to split

With rearrangement of fail high code this condition
is no more necessary.

Found by Jörg Oster.

No fuctional change.

11 years agoRemove an extra semicolon
Marco Costalba [Sat, 15 Dec 2012 10:20:04 +0000 (11:20 +0100)]
Remove an extra semicolon

No functional change.

11 years agoRevert store of distinct upper and lower bounds
Marco Costalba [Sat, 15 Dec 2012 10:11:38 +0000 (11:11 +0100)]
Revert store of distinct upper and lower bounds

Test by Joona prooves the new feature don't value 70 added lines of code.

Grand totals after 10040 games (crashes: 0) for tt_both

master_9edc7 - 6a93488_6a934: 1756 - 1688 - 6596 ELO +2 (+- 2.7)

Confirmed by test of Gary:

After 8680 games:
ELO: 0.80 +- 99%: 9.62 95%: 7.31
LOS: 65.38%
Wins: 1288 Losses: 1268 Draws: 6130

Thanks a lot to both for testing it !!!

bench 5149248

11 years agoMerge branch 'eval_cache'
Marco Costalba [Mon, 10 Dec 2012 08:22:13 +0000 (09:22 +0100)]
Merge branch 'eval_cache'

Unusually good result. Defenitly needs further verifications.

After 2160 games at 15"+0.05
Mod vs Orig 486 - 367 - 1307 ELO +19

bench: 6261882

11 years agoFix comparison with alpha, not beta
Marco Costalba [Sun, 9 Dec 2012 13:19:21 +0000 (14:19 +0100)]
Fix comparison with alpha, not beta

This silly bug seems the reason of the unsual bench
value.

bench: 6261882

11 years agoEnsure valueLower <= valueUpper
Marco Costalba [Sun, 9 Dec 2012 12:43:04 +0000 (13:43 +0100)]
Ensure valueLower <= valueUpper

In case a TTEntry stores both an upper and a lower bound
ensure that upper bound is not smaller than lower bound.

bench 1813815

11 years agoStore distinct upper and lower bound scores
Marco Costalba [Sun, 9 Dec 2012 10:08:37 +0000 (11:08 +0100)]
Store distinct upper and lower bound scores

This is more complex than what I'd like but I
was unable to split in small chunks.

Here we add 2 slots to TTEntry (valueUpper and depthUpper)
so that sizeof(TTEntry) returns to the original 16 bytes
and we can pack exactly 4 entries in a 64 bytes cache line.

Now we save an upper bound score alongside a lower (exact)
score. The idea is to increase TT cut-offs rates becuase
there is now an higher probability for a node to use TT info.

This patch is highly experimental and probably needs further
steps as is hinted by an unrealistic bench number:

bench: 2022385

11 years agoMicro-optimize color_of()
Marco Costalba [Wed, 5 Dec 2012 10:05:32 +0000 (11:05 +0100)]
Micro-optimize color_of()

In almost all cases we already know in advance that
color_of() argument is different from NO_PIECE.

So avoid the check for NO_PIECE in color_of() and
test at caller site in the very few places where
this case could occur.

As a nice side effect, this patch fixes a (bogus)
warning under some versions of gcc.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoUpdate Readme.txt now that we support 64 threads
thaspel [Tue, 4 Dec 2012 10:29:26 +0000 (11:29 +0100)]
Update Readme.txt now that we support 64 threads

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoMerge branch 'eval_cache'
Marco Costalba [Tue, 4 Dec 2012 06:57:46 +0000 (07:57 +0100)]
Merge branch 'eval_cache'

Use an eval cache instead of TT to store node
position evaluations.

It is already an improvment and, because it frees
two TT entry slots, paves the way to extend TT to
store both upper and lower bounds.

After 4855 games, single thread, 15"+0.05
Mod vs Orig 1165 -920 - 2770 ELO +18

bench: 5149248

11 years agoIncrease MAX_THREADS to 64
Marco Costalba [Mon, 3 Dec 2012 13:13:16 +0000 (14:13 +0100)]
Increase MAX_THREADS to 64

And document why this is an hard limit. It
seems for some (lucky) people 32 threads
are not enough.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoReintroduce eval optimizaion from null search
Marco Costalba [Sat, 1 Dec 2012 17:06:29 +0000 (18:06 +0100)]
Reintroduce eval optimizaion from null search

Now that conversion to eval cache is finished
we can reintroduce this optimization.

bench: 5149248

11 years agoDon't save eval score in TT
Marco Costalba [Sat, 1 Dec 2012 14:18:08 +0000 (15:18 +0100)]
Don't save eval score in TT

This patch completes the removal of eval info
in TT table.

No functional change.

11 years agoDon't use TT just to save a node evaluation
Marco Costalba [Sat, 1 Dec 2012 14:12:18 +0000 (15:12 +0100)]
Don't use TT just to save a node evaluation

In search(), after we evalute the position, in case there
isn't any TT entry we create one with just the evaluation
score.

This patches removes that code. The reason becuase the patch
deserves a single commit it is becuase introduces a (very small)
functional change due to the fact that the total number of
TT stores is less now and this slightly alters the TT hits
of our benchmark.

bench: 4983262

11 years agoDon't read eval from TT anymore
Marco Costalba [Sat, 1 Dec 2012 13:51:49 +0000 (14:51 +0100)]
Don't read eval from TT anymore

Rely fully on eval cache. Note that we still save eval
info to TT, this is not needed at this moment and will be
removed in future patches. We keep it so to have a "non
functional change" patch.

No functional change.

11 years agoRetire eval optimization from null search
Marco Costalba [Sat, 1 Dec 2012 13:48:13 +0000 (14:48 +0100)]
Retire eval optimization from null search

Simplify things preparing for further changes.

bench: 4983282

11 years agoAdd eval cache infrastructure
Marco Costalba [Sat, 1 Dec 2012 12:51:14 +0000 (13:51 +0100)]
Add eval cache infrastructure

With this patch series we want to introduce a per-thread
evaluation cache to store node evaluation and do not
rely anymore on the TT table for this.

This patch just introduces the infrastructure.

No functional change.

11 years agoDon't double check for move legality
Marco Costalba [Tue, 27 Nov 2012 19:05:03 +0000 (20:05 +0100)]
Don't double check for move legality

In case of a RootNode or a SpNode move has
been already checked for legality so we can
skip a redundant check.

Spotted by Frank Genot.

No functional change.

11 years agoUpdate bestValue when futility pruning
Marco Costalba [Mon, 26 Nov 2012 15:13:36 +0000 (16:13 +0100)]
Update bestValue when futility pruning

In qsearch we should update the bestValue as we do
in case of futilityValue < beta, also when pruning
moves with non-positive see.

Spotted by Lucas Braesch

Bench: 5695710

11 years agoAvoid spamming the GUI in multipv search
Marco Costalba [Sun, 18 Nov 2012 10:33:14 +0000 (11:33 +0100)]
Avoid spamming the GUI in multipv search

Send the PV lines to GUI only once at the end of the
PV search loop or just in case of long searches.

We need to sync also sending of "currmove" info to
avoid sending info on current move without first
informing the GUI on the PV line we are searching on.

No functional change.

11 years agoTriviality in move_gives_check()
Marco Costalba [Sat, 17 Nov 2012 11:57:58 +0000 (12:57 +0100)]
Triviality in move_gives_check()

It seems even a bit faster, although handling of the special
cases is not the hot path.

No functional change.

11 years agoBetter document fail-high condition
Marco Costalba [Sat, 17 Nov 2012 11:44:19 +0000 (12:44 +0100)]
Better document fail-high condition

At this point we have already verified (value > alpha)
and this implies, in case of a non-PV node, where search
window size is zero, that value >= beta.

This is not so self-evident, so document the code with
an assert condition.

No functional change.

11 years agoDon't access std::cout from Position::print()
Marco Costalba [Sun, 11 Nov 2012 12:18:10 +0000 (13:18 +0100)]
Don't access std::cout from Position::print()

Let the caller to decide where to redirect (cout or cerr) the
ASCII representation of the position. Rename the function to
reflect this.

Renamed also from_fen() and to_fen() to set() and fen() respectively.

No functional change.

11 years agoRestore old BOUND_EXACT logic in qsearch
Marco Costalba [Sun, 11 Nov 2012 10:49:02 +0000 (11:49 +0100)]
Restore old BOUND_EXACT logic in qsearch

In case a PvNode node has a static evaluation above alpha but
no available moves we want to flag the node as BOUND_EXACT,
not as BOUND_UPPER as is currently.

The behaviour was recently introduced with patch d471c49700fbe8281
of 3/10/2012

Spotted by Hongzhi Cheng.

bench: 5558464

11 years agoRevert "Don't prune discovered checks"
Marco Costalba [Sun, 11 Nov 2012 10:04:58 +0000 (11:04 +0100)]
Revert "Don't prune discovered checks"

Both Lucas re-test and Jean-Francois confirrm it
is a regression.

Here Jean-Francois's results after 3600 games :
Score of 96d3b1c92b8 vs 3b87314: 690 - 729 - 2181 [0.495] 3600
ELO: -3.86 +- 99%: 14.94 95%: 11.35
LOS: 15.03%
Wins: 690 Losses: 729 Draws: 2181 Total: 3600

Bench: 5404066

11 years agoDon't prune discovered checks
Marco Costalba [Wed, 7 Nov 2012 17:20:39 +0000 (18:20 +0100)]
Don't prune discovered checks

Don't prune and eventually extend check moves of type
DISCO_CHECK (pun intended, Lucas will understand :-) ).

Patch from Lucas Braesch that has also tested it:

Result: 879-661-2137, score=52.96%, LOS=100.00% (time 10"+0.1")

I have started a verification test right now.

bench: 6004966

11 years agoPrevious patch test results
Marco Costalba [Wed, 7 Nov 2012 17:05:45 +0000 (18:05 +0100)]
Previous patch test results

From Jean-Francois's

Final result after 5000 games :
Score of c581b7e vs a878312: 1163 - 970 - 2867 [0.519] 5000
ELO: 13.35 +- 99%: 12.71 95%: 9.65
LOS: 100.00%
Wins: 1163 Losses: 970 Draws: 2867 Total: 5000

From me

After 3266 games at 20"+0,05
Score of c581b7e vs a878312: 612 - 607 - 2047

So no regression at longer TC and perhaps a little gain at
fast TC.

11 years agoAnother attempt at evaluation shortcut
Marco Costalba [Mon, 5 Nov 2012 09:13:48 +0000 (10:13 +0100)]
Another attempt at evaluation shortcut

In this case we try a rather drastic
approach: we simply don't futility prune
in qsearch when arriving from a null move.

So we save evaluating and also save to mess
with eval margins at all because margin is used
only in futility.

Also accuracy should not be affected, actually it
improves because we don't prune anything anymore.

bench: 5404066

11 years agoTemporary revert previous patch
Marco Costalba [Mon, 5 Nov 2012 06:28:42 +0000 (07:28 +0100)]
Temporary revert previous patch

Performs well at very short TC of 40/4+0.05 (courtesy of Jean-Francois):
Wins: 2503 Losses: 2146 Draws: 5581 Total: 10230 +12 ELO

But is poor at longer TC of 20"+0.05
Wins: 321 Losses: 373 Draws: 1141 Total: 1808 -10 ELO

The patch was clearly a tradoff between speed and accuracy and
the most interesting part of it are test results that can be
commented as follows:

- A short TC is very sensible to any speed increase
- A longer TC is more sensible to accuracy and less to speed

So a patch that does not change speed is suitable to be tested at
short TC, while a speed/accuracy compromise patch is IMO better to
be tested at longer TC to verify loss of accuracy can be tolerated.

In this case the revert is only temporary. We will come back again
once we will be able to preserve the evaluation margin.

bench: 5809010

11 years agoSkip evaluate() call after a null move
Marco Costalba [Sun, 4 Nov 2012 09:21:40 +0000 (10:21 +0100)]
Skip evaluate() call after a null move

Reuse the evaluation of the parent with inverted sign and
set margin to zero (this is an hack!).

This is done only in qsearch where almost 15% of calls are
from a null move. In normal search the number of nodes where

(ss-1)->currentMove == MOVE_NULL

is almost zero and so there is no need of using this trick.

The big advantage of this patch is a speed-up due to skipped
evaluate() calls, that are very costly.

Functionality is of course affected and we will need to proper
test it later. For now we just register a 3-4% speed up.

Suggested by Hongzhi Cheng.

bench: 5051328

11 years agoCorrectly fix "break from split" patch
Marco Costalba [Sat, 3 Nov 2012 16:06:49 +0000 (17:06 +0100)]
Correctly fix "break from split" patch

In case split cut-offs we return with still
some moves to go but we really want to break
out from the loop now.

No functional change.

11 years agoRelax constrain in prevents_threat()
Marco Costalba [Sat, 3 Nov 2012 14:48:34 +0000 (15:48 +0100)]
Relax constrain in prevents_threat()

When testing if a move blocks the threat path there is no
reason to require the threat to be a slider. Indeed threat
can be a double pawn push like in this example:

r1bq1rk1/ppp1np1p/4n1p1/3p4/3P2Q1/2P1B3/PPBN2PP/R4RK1 w - - 0 16

Where white's move Rf6 blocks the threat f5.

As a nice side effect we can retire the now useless helper
piece_is_slider().

This patch kicks in only very rare cases, indeed the bench is
still the same!

bench: 5809010

11 years agoSync connected_threat() and yields_to_threat()
Marco Costalba [Sat, 3 Nov 2012 14:33:46 +0000 (15:33 +0100)]
Sync connected_threat() and yields_to_threat()

Rename stuff so to sync as much as posisble the
two related functions.

No functional change.

11 years agoDon't 'break' upon returning from split()
Marco Costalba [Sat, 3 Nov 2012 13:37:10 +0000 (14:37 +0100)]
Don't 'break' upon returning from split()

There is no guarantee that split() consumes all the node's
moves. Indeed split() can return without performing any job
for instance because MAX_SPLITPOINTS_PER_THREAD is reached
or becuase no available threads are found (this latter case
is much more common).

So search must continue in those cases and we cannot force
exiting from move's loop.

Bug introduced by 1ac417edb845 of 5/10/2012

Spotted by Frank Genot.

No functional change.

11 years agoRemove a redundant condition in connected_moves()
Marco Costalba [Sat, 3 Nov 2012 12:45:10 +0000 (13:45 +0100)]
Remove a redundant condition in connected_moves()

If a previous move attacks the king (with the piece
of the threat move removed) then must be a discovered
check, otherwise it means that first move gave check
and we were not able to do a null move.

Also renamed stuff to better document the function's
context.

No functional change.

11 years agoRelax constrain in connected_moves()
Marco Costalba [Sat, 3 Nov 2012 12:25:23 +0000 (13:25 +0100)]
Relax constrain in connected_moves()

When testing if a piece is moving through the squares
vacated by a previous move there is no reason to require
the piece to be a slider, indeed we can have a double
pawn push like in this example:

r1q2rk1/2p1bppp/2Pp4/pN5b/Q1P1p3/4B2P/PP1R1PP1/1K5R w - - 3 18

Where black's move f5 is connected to previous move Be7 that
frees the path.

Or we can have a castle move:

r1bqkb1r/pppp1ppp/2n1pn2/1B6/4P3/2N2N2/PPPP1PPP/R1BQK2R b KQkq - 5 1

Where a previous move Bb5 allows the white to castle king side.

This time patch is mine ;-)

new bench: 5809010

11 years agoReformat connected_moves()
Marco Costalba [Sat, 3 Nov 2012 11:57:07 +0000 (12:57 +0100)]
Reformat connected_moves()

Prepare code for the next patch that
will affect functionality.

No functional change.

11 years agoFix an off-by-one bug in multi pv print
Marco Costalba [Fri, 2 Nov 2012 23:30:46 +0000 (00:30 +0100)]
Fix an off-by-one bug in multi pv print

We send to GUI multi-pv info after each cycle,
not just once at the end of the PV loop. This is
because at high depths a single root search can
be very slow and we want to update the gui as
soon as we have a new PV score.

Idea is good but implementation is broken because
sort() takes as arguments a pointer to the first
element and one past the last element.

So fix the bug and rename sort arguments to better
reflect their meaning.

Another hit by Hongzhi Cheng.  Impressive!

No functional change.

11 years agoFix a condition in connected_moves()
Marco Costalba [Fri, 2 Nov 2012 16:04:51 +0000 (17:04 +0100)]
Fix a condition in connected_moves()

When checking if the moving piece p1 in a previous
move m1 defends the destination square of a move m2
we have to use the occupancy with the from square of
m2 removed so to take in account the case in which
f2 will block an x-ray attack from p1.

For instance in this position:
r2k3r/p1pp1pb1/qn3np1/1N2P3/1p3P2/2B5/PPP3QP/R3K2R b KQ - 1 9

The move eXf6 is connected to the previous move Bc3 that
defends the destination square f6.

With this patch we have about 10% more moves detected as
'connected'. Anyhow the absolute number is very low, about
4000 more moves out of 6M nodes searched.

Another issue spotted by Hongzhi "Hawk Eye" Cheng ;-)

new bench: 5757373

11 years agoMicro-optimize pop_lsb() for 64bit case
Marco Costalba [Thu, 1 Nov 2012 08:30:03 +0000 (09:30 +0100)]
Micro-optimize pop_lsb() for 64bit case

On Intel, perhaps due to 'lea' instruction this way of
zeroing the lsb of *b seems faster than a shift+negate.

On perft (where any speed difference is magnified) I
got a 6% speed up on my Intel i5 64bit.

Suggested by Hongzhi Cheng.

No functional change.

11 years agoFix a warning under MSVC
Marco Costalba [Fri, 2 Nov 2012 10:41:49 +0000 (11:41 +0100)]
Fix a warning under MSVC

Compiler complies that 'cnt' is initialized but
unused (in !CheckThreeFold case). Moving the
definition of 'cnt'out of the loop  seems to do
the trick.

No functional change.

11 years agoPass InCheck as template parameter of qsearch()
Marco Costalba [Thu, 1 Nov 2012 13:49:54 +0000 (14:49 +0100)]
Pass InCheck as template parameter of qsearch()

Instead of use a variable so to resolve many conditions
already at compile time. In quiesce is also where we
have most of the InCheck nodes and is one of the most
performance critical code paths.

Speed up of 1.5% with Clang and 1% with gcc

Suggested by Hongzhi Cheng.

No functional change.

11 years agoUse correct occupancy in connected_threat()
Marco Costalba [Tue, 30 Oct 2012 19:21:22 +0000 (20:21 +0100)]
Use correct occupancy in connected_threat()

When checking if a move defends the threatened piece
we correctly remove from the occupancy bitboard the
moved piece. This patch removes from the occupancy also
the threatening piece so to consider the cases of moves
that defend the threatened piece x-raying through the
threat move.

As example in this position:
r3k2r/p1ppqp2/Bn4p1/3p1n2/4P1N1/5Q1P/PPP2P1P/R3K2R w KQkq - 1 10

The threat black move is dxe4. With this patch we include
(and so don't prune) white's Bb7 that would be pruned otherwise.

The number of affected position is very low, around 1% of cases,
so we don't expect ELO changes, neverthless this is the logical
and natural thing to do.

Patch suggested by Hongzhicheng.

new bench: 5323798