]> git.sesse.net Git - stockfish/log
stockfish
14 years agoDocument index[] and pieceList[] are not invariants
Marco Costalba [Mon, 31 Aug 2009 08:59:33 +0000 (10:59 +0200)]
Document index[] and pieceList[] are not invariants

Array index[] and pieceList[] are not guaranteed to be
invariant to a do_move() + undo_move() sequence when a
capture move is involved.

The reason is that the captured piece is removed form
the list and substituted with the last one in do_move()
while in undo_move() is added again but at the end of
the list.

Because index[] and pieceList[] are used in move generation
to scan the pieces it means that moves will be generated
in a different order before and after a do_move() + undo_move()
sequence as, for instance, the one in Position::has_mate_threat()

After latest patches, move generation could now be invoked
also by MovePicker c'tor and this explains why order of
picked moves is different if MovePicker object is istantiated
before or after a Position::has_mate_threat() call.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoWorkaround a bug in Position::has_mate_threat()
Marco Costalba [Sun, 30 Aug 2009 18:12:08 +0000 (19:12 +0100)]
Workaround a bug in Position::has_mate_threat()

It seems that pos.has_mate_threat() changes the position !

So that calling MovePicker c'tor before or after the
has_mate_threat() call changes the things !

Bug was unhidden by previous patch that makes MovePicker c'tor
to generate, score and sort good captures under some circumstances.

Because scoring the captures is position dependent it seems that
the moves returned by MovePicker are different when c'tor is
called before has_mate_threat()

Of course this is only a workaround because the real bug is still
hidden :-(

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSkip TT_MOVES phase when possible
Marco Costalba [Sun, 30 Aug 2009 16:17:44 +0000 (17:17 +0100)]
Skip TT_MOVES phase when possible

If we don't have tt moves to search skip the
useless loop associated with TT_MOVES phase.

Another 1% speed boost that brings this series
to a +6.2% against original revision 595a90df

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMovepicker: take move's loop out of switch statement
Marco Costalba [Sun, 30 Aug 2009 08:42:55 +0000 (09:42 +0100)]
Movepicker: take move's loop out of switch statement

This not only cleans up the code but gives another
speed boost of 1.8%

From revision 595a90dfd0 we have increased pgo compiled binary
speed of a whopping +5.2% without any functional change !!

This is really awsome considering that we have also
cut line count by 25 lines.

Sometime we spend days for getting an extra 1% from move
generation while instead the biggest optimizations come
from anonymous and apparently dull parts of the code.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRevert "null move reorder" series
Marco Costalba [Sat, 29 Aug 2009 19:19:09 +0000 (20:19 +0100)]
Revert "null move reorder" series

Does not seem to improve on the standard, latest results
from Joona after 2040 games are negative:

Orig - Mod: 454 - 424 - 1162

And is more or less the same I got few days ago.

So revert for now.

Verified same functionality of 595a90dfd

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoConvert handling of tt moves and killers to standard form
Marco Costalba [Sat, 29 Aug 2009 07:02:30 +0000 (08:02 +0100)]
Convert handling of tt moves and killers to standard form

Use the same way of loop along the move list used for
the others move kinds so to be consistent in get_next_move()

And a bit of the usual clean up too, but just a bit.

It is even a bit (+0.3%) faster now. ;-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoTry null move before captures
Marco Costalba [Thu, 27 Aug 2009 19:22:20 +0000 (20:22 +0100)]
Try null move before captures

Always after TT move but before captures.

This seems a better setup against version before this
patch.

After 999 games at 1+0

Mod - Orig +252 =527 -220 +11 ELO

Unfortunatly it does not seems to improve on the standard
version, with null move outside of movepicker (595a90df) with
the latest speed-up patches added in.

After 999 games at 1+0

Mod - Standard +244 =506 -249 -2 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse pointers instead of array indices in MovePicker
Marco Costalba [Fri, 28 Aug 2009 06:57:52 +0000 (08:57 +0200)]
Use pointers instead of array indices in MovePicker

This avoids calculating the array entry position
at each access and gives another boost of almost 1%.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoChange the flow in wich moves are generated and picked
Marco Costalba [Thu, 27 Aug 2009 07:12:51 +0000 (09:12 +0200)]
Change the flow in wich moves are generated and picked

In MovePicker we get the next move with pick_move_from_list(),
then check if the return value is equal to MOVE_NONE and
in this case we update the state to the new phase.

This patch reorders the flow so that now from pick_move_from_list()
renamed get_next_move() we directly call go_next_phase() to
generate and sort the next bunch of moves when there are no more
move to try. This avoids to always check for pick_move_from_list()
returned value and the flow is more linear and natural.

Also use a local variable instead of a pointer dereferencing in a
time critical switch statement in get_next_move()

With this patch alone we have an incredible speed up of 3.2% !!!

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDisable again null move at depth == OnePly
Marco Costalba [Wed, 26 Aug 2009 15:59:58 +0000 (16:59 +0100)]
Disable again null move at depth == OnePly

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse special null move technique in low depth.
Joona Kiiski [Mon, 24 Aug 2009 17:06:09 +0000 (20:06 +0300)]
Use special null move technique in low depth.

Try good captures before null move when depth < 3 * OnePly.
Use this kind of null move also in Depth == OnePly.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse nullMove only through MovePicker.
Joona Kiiski [Mon, 24 Aug 2009 15:08:31 +0000 (18:08 +0300)]
Use nullMove only through MovePicker.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd Null move support to MovePicker.
Joona Kiiski [Mon, 24 Aug 2009 15:00:35 +0000 (18:00 +0300)]
Add Null move support to MovePicker.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCreate useNullMove local variable
Joona Kiiski [Mon, 24 Aug 2009 14:46:03 +0000 (17:46 +0300)]
Create useNullMove local variable

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoClean killers handling in movepicker
Marco Costalba [Wed, 26 Aug 2009 13:33:17 +0000 (14:33 +0100)]
Clean killers handling in movepicker

Original patch from Joona with added optimizations
by me.

Great cleanup of MovePicker with speed improvment of 1%

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMicro-optimze extension()
Marco Costalba [Mon, 24 Aug 2009 16:41:24 +0000 (17:41 +0100)]
Micro-optimze extension()

Explicitly write the conditions for pawn to 7th
and passed pawn instead of wrapping in redundant
helpers.

Also retire the now unused move_is_pawn_push_to_7th()
and the never used move_was_passed_pawn_push() and
move_is_deep_pawn_push()

Function extension() is so time critical that this
simple patch speeds up the pgo compile of 0.5% and
it is also more clear what actually happens there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMerge branch 'master' of git-Stockfish@free2.projectlocker.com:sf
Marco Costalba [Sun, 23 Aug 2009 17:57:11 +0000 (18:57 +0100)]
Merge branch 'master' of git-Stockfish@free2.projectlocker.com:sf

14 years agoRemove a local variable from pop_1st_bit()
Marco Costalba [Sun, 23 Aug 2009 16:20:02 +0000 (17:20 +0100)]
Remove a local variable from pop_1st_bit()

Remove the 'b' uint32_t local variable.
Optimized assembly is more or less the same
(one 'mov' instruction less), but now it is
written in a way more similar to the final assembly
flow so it should be easier for compiler to optimize.

Also guarantee that BitTable[] is always aligned.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoPoly ampli+bias values after 73831 games
Marco Costalba [Sat, 22 Aug 2009 11:10:02 +0000 (12:10 +0100)]
Poly ampli+bias values after 73831 games

Verified correct against tuning branch.

After 999 games at 1+0

Mod vs Orig +257 =510 -232 51.20%  +9 ELO

Very small increase but an increase anyway !

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdded a few new targets to the Makefile for OS X with icpc.
Tord Romstad [Fri, 21 Aug 2009 08:50:34 +0000 (10:50 +0200)]
Added a few new targets to the Makefile for OS X with icpc.

The following new targets were added:
   * osx-icc32: 32-bit x86 compiled with icpc.
   * osx-icc64: 64-bit x86 compiled with icpc.
   * osx-icc32-profile: 32-bit x86 compiled with icpc and pgo.
   * osx-icc64-profile: 64-bit x86 compiled with icpc and pgo.

14 years agoFix some asserts raised by is_ok()
Marco Costalba [Thu, 20 Aug 2009 15:30:34 +0000 (16:30 +0100)]
Fix some asserts raised by is_ok()

There were two asserts.

The first was raised because is_ok() was called at the
beginning of do_castle_move() and this is wrong after
the last code reformatting because at that point the state
is already modified by the caller do_move().

The second, raised by debugIncrementalEval, was due to a
rounding error in compute_value() that occurs because
TempoValueEndgame was updated in an odd number by patch

"Merge Joona Kiiski evaluation tweaks" (3ed603cd) of 13/3/2009

This line in compute_value() is the guilty one:

result += (side_to_move() == WHITE)? TempoValue / 2 : -TempoValue / 2;

The fix is to increment TempoValueEndgame so to be even.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFixed incorrect material key update when making promotion moves.
Tord Romstad [Thu, 20 Aug 2009 14:54:20 +0000 (16:54 +0200)]
Fixed incorrect material key update when making promotion moves.

14 years agoMore use of memset() in Position::clear()
Marco Costalba [Tue, 18 Aug 2009 15:54:46 +0000 (16:54 +0100)]
More use of memset() in Position::clear()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoLittle do_move() micro optimizations
Marco Costalba [Tue, 18 Aug 2009 00:21:01 +0000 (01:21 +0100)]
Little do_move() micro optimizations

Also a few remaining style touches.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoBetter clarify how pieceList[] and index[] work
Marco Costalba [Mon, 17 Aug 2009 22:12:38 +0000 (23:12 +0100)]
Better clarify how pieceList[] and index[] work

Rearrange the code a bit to be more self-documenting.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUnify patch series summary
Marco Costalba [Mon, 17 Aug 2009 07:57:09 +0000 (08:57 +0100)]
Unify patch series summary

This patch seems bigger then what actually is.

It just moves some code around and adds a bit of coding style fixes
to do_move() and undo_move() so to have uniformity of naming in both
functions.

The diffstat for the whole patch series is

239 insertions(+), 426 deletions(-)

And final MSVC pgo build is even a bit faster:

Before 448.051 nodes/sec

After 453.810  nodes/sec (+1.3%)

No functional change (tested on more then 100M of nodes)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUnify undo_ep_move(m)
Marco Costalba [Sun, 16 Aug 2009 16:58:24 +0000 (17:58 +0100)]
Unify undo_ep_move(m)

Integrate undo_ep_move in undo_move() this reduces line count
and code readibility.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUnify undo_promotion_move()
Marco Costalba [Sun, 16 Aug 2009 16:07:10 +0000 (17:07 +0100)]
Unify undo_promotion_move()

Integrate do_ep_move in undo_move() this reduces line count
and code readibility.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUnify do_promotion_move()
Marco Costalba [Sun, 16 Aug 2009 13:49:15 +0000 (14:49 +0100)]
Unify do_promotion_move()

Integrate do_promotion_move() in do_move() this reduces line count
and code readibility.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUnify do_ep_move()
Marco Costalba [Sun, 16 Aug 2009 13:07:34 +0000 (14:07 +0100)]
Unify do_ep_move()

Integrate do_ep_move in do_move() this reduces line count
and code readibility.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoL1/L2 friendly PhaseTable[]
Marco Costalba [Sat, 15 Aug 2009 14:18:17 +0000 (15:18 +0100)]
L1/L2 friendly PhaseTable[]

In Movepicker c'tor we access during initialization one of
MainSearchPhaseIndex..QsearchWithoutChecksPhaseIndex globals.

Postpone definition of PhaseTable[] just after them so that
when PhaseTable[] will be accessed later in get_next_move()
it will be already present in L1/L2.

It works like an implicit prefetching of PhaseTable[].

Also shrink PhaseTable[] to fit an L1 cache line of 16 bytes
using uint8_t instead of int.

This apparentely innocuous patch gives an astonish speed
up of 1.6% under MSVC 2010 beta, pgo optimized !

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse optimized pop_1st_bit() under Windows 64 with icc
Marco Costalba [Fri, 14 Aug 2009 11:47:49 +0000 (12:47 +0100)]
Use optimized pop_1st_bit() under Windows 64 with icc

Intel compiler can handle this code even under Windows.

So lift the costrain.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoBetter naming and document some endgame functions
Marco Costalba [Thu, 13 Aug 2009 10:45:35 +0000 (12:45 +0200)]
Better naming and document some endgame functions

In particular the generic scaling functions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFinally fix prefetch on Linux
Marco Costalba [Wed, 12 Aug 2009 07:40:03 +0000 (09:40 +0200)]
Finally fix prefetch on Linux

It was due to a missing -msse compiler option !

Without this option the CPU silently discards
prefetcht2 instructions during execution.

Also added a (gcc documented) hack to prevent Intel
compiler to optimize away the prefetches.

Special thanks to Heinz for testing and suggesting
improvments. And for Jim for testing icc on Windows.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoReuse 5 slots instead of 4
Marco Costalba [Tue, 11 Aug 2009 07:30:19 +0000 (08:30 +0100)]
Reuse 5 slots instead of 4

But this time with the guarantee of an always aligned
access so that prefetching is not adversely impacted.

On Joona PC
1+0, 64Mb hash:

Orig - Mod: 174 - 237 - 359

Instead after 1000 games at 1+0 with 128MB hash size
we are at + 1 ELO (just 4 games of difference).

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDouble prefetch on Windows
Marco Costalba [Mon, 10 Aug 2009 13:23:19 +0000 (14:23 +0100)]
Double prefetch on Windows

After fixing the cpu frequency with RightMark tool I was
able to test speed all the different prefetch combinations.

Here the results:

OS Windows Vista 32bit, MSVC compile
CPU Intecl Core 2 Duo T5220 1.55 GHz
bench on depth 12, 1 thread, 26552844 nodes searched
results in nodes/sec

no-prefetch
402486, 402005, 402767, 401439, 403060

single prefetch (aligned 64)
410145, 409159, 408078, 410443, 409652

double prefetch (aligned 64) 0+32
414739, 411238, 413937, 414641, 413834

double prefetch (aligned 64) 0+64
413537, 414337, 413537, 414842, 414240

And now also some crazy stuff:

single prefetch (aligned 128)
410145, 407395, 406230, 410050, 409949

double prefetch (aligned 64) 0+0
409753, 410044, 409456

single prefetch (aligned 64) +32
408379, 408272, 406809

single prefetch (aligned 64) +64
408279, 409059, 407395

So it seems the best is a double prefetch at the addres + 32 or +64,
I will choose the second one because it seems more natural to me.

It is still a mystery why it doesn't work under Linux :-(

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAvoid Intel compiler optimizes away prefetching
Marco Costalba [Mon, 10 Aug 2009 10:59:07 +0000 (12:59 +0200)]
Avoid Intel compiler optimizes away prefetching

Without this hack Intel compiler happily optimizes
away the gcc builtin call.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse aligned prefetch address
Marco Costalba [Mon, 10 Aug 2009 07:35:46 +0000 (09:35 +0200)]
Use aligned prefetch address

Prefetch always form a chache line boundary. It seems
that if prefetch address is not cache line aligned then
performance is adversely impacted.

Hopefully we will resuse that 32 bits of padding for something
useful in the future.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove old BishopPairBonus constants
Marco Costalba [Mon, 10 Aug 2009 06:43:39 +0000 (08:43 +0200)]
Remove old BishopPairBonus constants

Now that we have poly imbalance these ones
are no more used.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoEnable prefetch also for gcc
Marco Costalba [Sun, 9 Aug 2009 23:20:54 +0000 (01:20 +0200)]
Enable prefetch also for gcc

This fix a compile error under Linux with gcc when
there aren't the intel dev libraries.

Also simplify the previous patch moving TT definition
from search.cpp to tt.cpp so to avoid using passing a
pointer to TT to the current position.

Finally simplify do_move(), now we miss a prefetch in the
rare case of setting an en-passant square but code is
much cleaner and performance penalty is almost zero.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoTry to prefetch as soon as position key is ready
Marco Costalba [Sun, 9 Aug 2009 14:53:51 +0000 (15:53 +0100)]
Try to prefetch as soon as position key is ready

Move prefetching code inside do_move() so to allow a
very early prefetching and to put as many instructions
as possible between prefetching and following retrieve().

With this patch retrieve() times are cutted of another 25%

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd TT prefetching support
Marco Costalba [Sun, 9 Aug 2009 12:44:55 +0000 (13:44 +0100)]
Add TT prefetching support

TT.retrieve() is the most time consuming function
because almost always involves a very slow RAM access.

TT table is so big that is never cached. This patch
prefetches TT data just after a move is done, so that
subsequent TT.retrieve will be very  fast.

Profiling with VTune shows that TT:retrieve() times are
almost cutted in half !

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse 5 TTEntry slots instead of 4
Marco Costalba [Sun, 9 Aug 2009 03:35:46 +0000 (04:35 +0100)]
Use 5 TTEntry slots instead of 4

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse 32 bit key in TT
Marco Costalba [Sun, 9 Aug 2009 03:19:32 +0000 (04:19 +0100)]
Use 32 bit key in TT

Shrink key to 32 bits instead of 64. To still avoid
collisions use the high 32 bits of position key as the
TT key and the low 32 bits to retrieve the correct
cluster index in the table.

With this patch size og TTentry shrinks to 96 bits instead
of 128 and the cluster of 4 TTEntry sums to 48 bytes instead
of 64.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMakefile: added 'make strip' target
Marco Costalba [Sat, 8 Aug 2009 16:37:13 +0000 (17:37 +0100)]
Makefile: added 'make strip' target

Binaries are always built with symbol table in to easy
debugging and profiling.

It is now possible to run:

make strip

To remove symbol table from the compiled binary. This
could be useful to prepare the release version.

Patch by Heinz van Saanen.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoLet LMR at root be independent of MultiPV value
Marco Costalba [Sat, 8 Aug 2009 16:04:01 +0000 (17:04 +0100)]
Let LMR at root be independent of MultiPV value

Current formula enable LMR when

i + MultiPV >= LMRPVMoves

It means that, for instance, if MultiPV == 1 then LMR
will be started to be considered at move i = LMRPVMoves - 1,
while if MultiPV == 3 then it will start before,
at move i = LMRPVMoves - 3.

With this patch the formula becomes

i >= MultiPV + LMRPVMoves - 2

So that LMR will always start after LMRPVMoves - 1 moves
from the last PV move.

No functional change when MultiPV == 1

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSpeed up polynomial material imbalance loop
Marco Costalba [Sat, 8 Aug 2009 12:06:50 +0000 (13:06 +0100)]
Speed up polynomial material imbalance loop

Access pos.piece_count() only once and avoid some
branches in the inner loop.

Profiling with VTune shows a 20% speed improvement in
get_material_info(), and it is also a bit more cleaned
up this way ;-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoThere is no need to special case KNNK ending
Marco Costalba [Sat, 8 Aug 2009 11:28:03 +0000 (12:28 +0100)]
There is no need to special case KNNK ending

It is always draw, so use the corresponding proper
evaluation function.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMove halfOpenFiles[] calculation out of a loop
Marco Costalba [Mon, 27 Jul 2009 09:28:29 +0000 (11:28 +0200)]
Move halfOpenFiles[] calculation out of a loop

And put it in an already existing one so to
optimze a bit.

Also additional cleanups and code shuffles
all around the place.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCompile without DEBUG flag by default
Marco Costalba [Sat, 8 Aug 2009 07:12:31 +0000 (09:12 +0200)]
Compile without DEBUG flag by default

And build also symbol table. It can easily stripped
after .exe is done and it is necessary for profiling.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRevert material balance values after 100000 games
Marco Costalba [Sat, 8 Aug 2009 02:46:43 +0000 (03:46 +0100)]
Revert material balance values after 100000 games

After Joona's direct testing with ~2000 games it seems
values after 100.000 games does not give any advantage,
so revert for now.

Score of Stockfish_0 vs Stockfish_15: 491 - 392 - 1102
Score of Stockfish_0 vs Stockfish_40: 461 - 439 - 1076
Score of Stockfish_0 vs Stockfish_65: 442 - 518 - 1018 (13 elo)
Score of Stockfish_0 vs Stockfish_100: 504 - 502 - 984

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDo not adjust Minimum Split Depth automatically
Joona Kiiski [Fri, 24 Jul 2009 14:34:41 +0000 (17:34 +0300)]
Do not adjust Minimum Split Depth automatically

Currently minimum split depth is set automatically to 6
when number of CPUs is more than 4. I believe this is a bad
idea since for example my quad (4CPU with hyperthreading) is
detected as 8CPU computer. I've manually lowered down the number
of Threads, but so far I have played all games with Minimum
Split Depth set to 6!

Since 4CPU computers with hyperthreading are quite common and
8 CPU computers extremely rear (I expect we can get a direct
jump to 16 or 32 cores), this automatic adjusting is likely
to do more harm than good. Add a note in Readme.txt, so that
those rear 8CPU owners can manually tweak the "Minimum Split
Depth" parameter

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoPolished Makefile for *nix
Marco Costalba [Sat, 8 Aug 2009 02:30:27 +0000 (03:30 +0100)]
Polished Makefile for *nix

Greately improved Makefile from Heinz van Saanen

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSupply the "upperbound" and "lowerbound" parameters in UCI search
Tord Romstad [Fri, 7 Aug 2009 14:26:24 +0000 (16:26 +0200)]
Supply the "upperbound" and "lowerbound" parameters in UCI search
output when the score is outside the root window.

14 years agoFixed a bug in PV extraction from the transposition table: The
Tord Romstad [Thu, 6 Aug 2009 16:07:32 +0000 (18:07 +0200)]
Fixed a bug in PV extraction from the transposition table: The
previous used move_is_legal to verify that the move from the TT
was legal, and the old version of move_is_legal only works when
the side to move is not in check. Fixed this by adding a separate,
slower version of move_is_legal which works even when the side to
move is in check.

14 years agoMoved the code for extracting the PV from the TT to tt.cpp, where
Tord Romstad [Thu, 6 Aug 2009 12:02:53 +0000 (14:02 +0200)]
Moved the code for extracting the PV from the TT to tt.cpp, where
it belongs.

14 years agoAdded a new function build_pv(), which extends a PV by walking
Tord Romstad [Thu, 6 Aug 2009 11:27:49 +0000 (13:27 +0200)]
Added a new function build_pv(), which extends a PV by walking
down the transposition table.

When the search was stopped before a fail high at the root was
resolved, Stockfish would often print a very short PV, sometimes
consisting of just a single move. This was not only a little
user-unfriendly, but also harmed the strength a little in
ponder-on games: Single-move PVs mean that there is no ponder
move to search.

It is perhaps worth considering to remove the pv[][] array
entirely, and always build the entire PV from the transposition
table. This would simplify the source code somewhat and probably
make the program infinitesimally faster, at the expense of
sometimes getting shorter PVs or PVs with rubbish moves near
the end.

14 years agoInitial work towards adjustable playing strength.
Tord Romstad [Tue, 4 Aug 2009 09:31:25 +0000 (11:31 +0200)]
Initial work towards adjustable playing strength.

Added the UCI_LimitStrength and the UCI_Elo options, with an Elo
range of 2100-2900. When UCI_LimitStrength is enabled, the number
of threads is set to 1, and the search speed is slowed down according
to the chosen Elo level.

Todo:

1. Implement Elo levels below 2100 by blundering on purpose and/or
   crippling the evaluation.
2. Automatically calibrate the maximum Elo by measuring the CPU speed
   during program initialization, perhaps by doing some bitboard
   computations and measuring the time taken.

No functional change when UCI_LimitStrength is false (the default).

14 years agoAdded LMR at the root.
Tord Romstad [Mon, 3 Aug 2009 07:08:59 +0000 (09:08 +0200)]
Added LMR at the root.

After 2000 games at 1+0

Mod vs Orig +534 =1033 -433 52.525%  1050.5/2000  +18 ELO

14 years agoRemove useless mate value special handling in null search
Joona Kiiski [Mon, 20 Jul 2009 12:47:05 +0000 (15:47 +0300)]
Remove useless mate value special handling in null search

After 1200 games (1CPU), time control 1+0:

Mod vs Orig: +331 =564 -277  +16 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoYet another small touch to endgame functions handling
Marco Costalba [Sun, 26 Jul 2009 16:42:48 +0000 (17:42 +0100)]
Yet another small touch to endgame functions handling

It is like a never finished painting. Everyday a little touch
more.

But this time it is very little ;-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove unused members in Application class
Marco Costalba [Sun, 26 Jul 2009 15:04:19 +0000 (16:04 +0100)]
Remove unused members in Application class

Also rearrange a bit the remining methods.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix a spurious extra space
Marco Costalba [Sun, 26 Jul 2009 08:07:42 +0000 (09:07 +0100)]
Fix a spurious extra space

This morning it seems there is nothing better to do...

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMicro optimize extension() in search.cpp
Marco Costalba [Sat, 25 Jul 2009 15:16:28 +0000 (16:16 +0100)]
Micro optimize extension() in search.cpp

Small micro-optimization in this very
time critical function.

Use bitwise 'or' instead of logic 'or' to avoid branches
in the assembly and use the result to skip an handful of checks.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoPolynomial material balance after 100.000 games
Marco Costalba [Fri, 24 Jul 2009 13:26:49 +0000 (14:26 +0100)]
Polynomial material balance after 100.000 games

Verified it is equivalent to the tuning branch results
with parameter values sampled after 100.000 games.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRevert Makefile changes
Marco Costalba [Fri, 24 Jul 2009 13:18:03 +0000 (14:18 +0100)]
Revert Makefile changes

Some unwanted changes to Makefile slept in in patch
"Introduced the UCI_AnalyseMode option".

Revert them. No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSimplify king shelter cache handling
Marco Costalba [Fri, 24 Jul 2009 10:16:18 +0000 (12:16 +0200)]
Simplify king shelter cache handling

This is more similar to how get_material_info() and
get_pawn_info() work and also removes some clutter from
evaluate_king().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoDelay costly SEE call during captures ordering in MovePicker
Marco Costalba [Thu, 23 Jul 2009 06:13:06 +0000 (07:13 +0100)]
Delay costly SEE call during captures ordering in MovePicker

When ordering moves we push all captures with negative SEE values
to badCaptures[] array during the scoring phase.

This patch delays the costly SEE call up to when the move has been
picked up in pick_move_from_list(), this way we save some SEE calls
in case we get a cutoff.

It seems we have a speed gain of about 1-1.5 % in terms of nodes/sec
and profiling seems to confirm the small but real speed increase.

Idea from Pablo Vazquez on talkchess.com
http://www.talkchess.com/forum/viewtopic.php?t=29018&start=20

It would be a no functional change but actually it is not because
now sorting set is different and so std::sort(), that is not a
stable sort, does not guarantees the order of same scored moves to
remain the same as before.

After 952 games at 1+0 we are below error bar, almost equal just
6 games of difference (+2 ELO)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMicroptimization in do_evaluate()
Marco Costalba [Thu, 23 Jul 2009 17:30:56 +0000 (18:30 +0100)]
Microptimization in do_evaluate()

Do not call count_1s_max_15() if not necessary, as is
not in the common case (>95%).

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse do_move_bb() helpers when doing a castle
Marco Costalba [Thu, 23 Jul 2009 09:29:13 +0000 (10:29 +0100)]
Use do_move_bb() helpers when doing a castle

Small cleanup.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoAdd Tord's polynomial material balance
Marco Costalba [Mon, 20 Jul 2009 08:56:21 +0000 (09:56 +0100)]
Add Tord's polynomial material balance

Use a polynomial weighted evaluation to calculate
material value.

This is far more flexible and elegant then applying
a series of single euristic rules as before.

Also correct a design issue in which we returned two
values, one for middle game and one for endgame, while
instead, because game phase is a function of board
material itself, only one value should be calculated and
used both for mid and end game.

Verified it is equivalent to the tuning branch results with
parameter values sampled after 40.000 games.

After 999 games at 1+0

Mod vs Orig +277 =482 -240 51.85%  518.0/999  +13 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRename int32 in int32_t
Marco Costalba [Mon, 20 Jul 2009 09:50:18 +0000 (10:50 +0100)]
Rename int32 in int32_t

To use the same naming rule of the other types and
to be compatible with inttypes.h, used under Linux.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCorrectly set mateThreat in search()
Marco Costalba [Sat, 18 Jul 2009 10:28:09 +0000 (11:28 +0100)]
Correctly set mateThreat in search()

We do not accept null search returned mate values,
but we always do a full search in those cases.

So the variable mateThreat that is set only if null move
search returns a mate value is always false.

Restore the functionality of mateThreat moving the
assignement where it can be triggered.

After 999 games at 1+0

Mod vs Orig +253 =517 -229 51.20%  +8 ELO

Bug reported by xiaozhi

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse increased LMR horizont also in PV search
Marco Costalba [Fri, 17 Jul 2009 16:07:45 +0000 (17:07 +0100)]
Use increased LMR horizont also in PV search

Tord says that using a lower horizon at PV nodes
looks strange and inconsistent with the general
philosophy of our search (i.e. always being more
conservative at PV nodes). So set LMR at 3 also
on search_pv().

Test result after 601 games seems to confirm this.

Mod vs Orig +156 =318 -127 52.41%  315.0/601  +17 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoReintroduce null move dynamic reduction
Marco Costalba [Thu, 16 Jul 2009 06:05:54 +0000 (07:05 +0100)]
Reintroduce null move dynamic reduction

Test extension of LMR horizon to 3 plies alone, without
touching null move search. To keep the patch minimal we still
don't change LMR horizon in PV search. This will be the object
of the next patch.

Result seems good after 998 games:

Mod vs Orig  +252/=518/-228 51.20%  511.0/998 +8 ELO

So dynamic null move reduction seems a bit stronger then
fixed reduction even with LMR horizon set to 3.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoUse increased LMR horizont only after a null move
Marco Costalba [Wed, 15 Jul 2009 07:43:09 +0000 (08:43 +0100)]
Use increased LMR horizont only after a null move

Revert to LMR horizont of 2 plies. Only if parent move
is a null move increase to 3 so to avoid the bad combination
of null move reduction + LMR reduction. This is a more
aggressive patch then previous one, but it seems we are
going in the wromg direction.

After 531 games result is not good:

Mod vs Orig  +123/=265/-143 48.12%  255.5/531  -13 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCombine increased LMR horizont and fixed null move reduction
Marco Costalba [Mon, 13 Jul 2009 12:35:29 +0000 (13:35 +0100)]
Combine increased LMR horizont and fixed null move reduction

Set null move reduction to R=4, but increase the LMR horizon
to 3 plies. The two tweaks are related and should compensate
the combined effect of null move + LMR reduction at shallow
depths.

Idea from Tord.

After 999 games at 1+0

Mod vs Orig  +251 =522 -225 51.30% + 9 ELO

On Tord iMac Core 2 Duo 2.8 GHz, one thread,
Mac OS X 10.6, at 1+0 time control we have:

Mod vs Orig 994-1006  -1.4 ELO

But Orig version is pgo compiled and Mod is not.
The PGO compiled version is about 8% faster, which
corresponds to about 7 Elo points. This means that
results are reasonably consistent.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoIntroduced the UCI_AnalyseMode option, and made the evaluation function
Tord Romstad [Fri, 17 Jul 2009 20:26:01 +0000 (22:26 +0200)]
Introduced the UCI_AnalyseMode option, and made the evaluation function
symmetrical in analyse mode.

No functional change when playing games.

14 years agoFix two compile errors in new endgame code
Marco Costalba [Fri, 17 Jul 2009 17:16:20 +0000 (19:16 +0200)]
Fix two compile errors in new endgame code

Code that compiles cleanly under MSVC triggers one
compile error (correct) under Intel C++ and two(!)
under gcc.

The first is the same complained by Intel, but the second
is an interesting corner case of C++ standard (there are many)
that is correctly spotted only by gcc.

Both MSVC and Intel pass this silently, probably to avoid
breaking people code.

Now we are fully C++ compliant ;-)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMove constant bitboard arrays from header to cpp file
Marco Costalba [Fri, 17 Jul 2009 15:18:33 +0000 (16:18 +0100)]
Move constant bitboard arrays from header to cpp file

This avoid to duplicate storage allocation for every file
where they are used.

Note that simple numeric constant can remain in header because
are automatically folded by the compiler.

Patch suggested by Tord.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemove even more redundancy in endgame functions handling
Marco Costalba [Fri, 17 Jul 2009 12:32:27 +0000 (14:32 +0200)]
Remove even more redundancy in endgame functions handling

Push on the templatization even more to chip out some code
and take the opportunity to show some neat template trick ;-)

Ok. I would say we can stop here now....it is quickly becoming
a style exercise but we are not boost developers so give it a stop.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRemoved an incorrect assert() statement in search.cpp, which asserted that
Tord Romstad [Fri, 17 Jul 2009 07:12:59 +0000 (09:12 +0200)]
Removed an incorrect assert() statement in search.cpp, which asserted that
a static eval cached in the transposition table would always equal the static
eval of the current position. This is in general not true, because the cached
value could be from a previous search with different evaluation parameter
settings, or from a search from the opposite side (Stockfish's evaluation
function is assymmetric by default).

14 years agoSimplify endgame functions handling
Marco Costalba [Thu, 16 Jul 2009 12:31:32 +0000 (14:31 +0200)]
Simplify endgame functions handling

We really don't need to have global endgame functions. We can
allocate them on the heap at initialization time and store the
corresponding pointer directly in the functions maps. To avoid
leaks we just need to remember to deallocate them in map d'tor.

These functions are always created in couple, one for each color,
so remove a lot of redundant hard coded info and just use the minimum
required: the type and the corresponding named string.

This greatly simplifies the code and also it is less error prone,
now is much simpler to add a new endgame specialized function: just
add the corresponding enum in endgame.h and the obvious add_xx()
call in EndgameFunctions c'tor, and of course, the most important part,
the EvaluationFunction<xxx>::apply() specialization in endgame.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRenamed the variable 'looseOnTime' to 'loseOnTime', because I'm a pedant.
Tord Romstad [Wed, 15 Jul 2009 09:01:49 +0000 (11:01 +0200)]
Renamed the variable 'looseOnTime' to 'loseOnTime', because I'm a pedant.

No functional change.

14 years agoRemove "Last seconds noise" filtering UCI option
Marco Costalba [Mon, 13 Jul 2009 10:44:33 +0000 (11:44 +0100)]
Remove "Last seconds noise" filtering UCI option

This feature makes sense during development, but
It doesn't seem to make sense for normal users.

Also fix a possible race where the GUI adjudicates
the game a fraction of second before the engine sets
looseOnTime flag so that it will bogusly waits until
it ran out of time at the beginning of the next new game.

The fix is to always reset looseOnTime at the beginning
of a new game.

Race condition spotted by Tord.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoIntroduce SERIALIZE_MOVES_D() macro and use it for pawn moves
Marco Costalba [Tue, 14 Jul 2009 08:07:30 +0000 (10:07 +0200)]
Introduce SERIALIZE_MOVES_D() macro and use it for pawn moves

This is another moves serialization macro but this time
focused on pawn moves where the 'from' square is given as
a delta from the 'to' square.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMicro optimize pawn moves generation
Marco Costalba [Tue, 14 Jul 2009 06:53:22 +0000 (08:53 +0200)]
Micro optimize pawn moves generation

It is very rare we have pawns on 7(2) rank, so we
can skip the promotion handling stuff in most cases.

With this patch pawn moves generation is almost 20% faster.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoIntroduce see_sign() and use it to shortcut full see()
Marco Costalba [Sat, 11 Jul 2009 08:54:30 +0000 (09:54 +0100)]
Introduce see_sign() and use it to shortcut full see()

Mostly of times we are interested only in the sign of SEE,
namely if a capture is negative or not.

If the capturing piece is smaller then the captured one we
already know SEE cannot be negative and this information
is enough most of the times. And of course it is much
faster to detect then a full SEE.

Note that in case see_sign() is negative then the returned
value is exactly the see() value, this is very important,
especially for ordering capturing moves.

With this patch the calls to the costly see() are reduced
of almost 30%.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoMove some global variables to local scope in search.cpp
Marco Costalba [Sat, 11 Jul 2009 07:02:31 +0000 (08:02 +0100)]
Move some global variables to local scope in search.cpp

Some variables were global due to some old and now removed code,
but now can be moved in local scope.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoJoona tweaks of Weights and limits
Marco Costalba [Fri, 10 Jul 2009 20:41:23 +0000 (21:41 +0100)]
Joona tweaks of Weights and limits

Verification test give unusless result

After 999 games at 1+0
Mod vs Orig +250 =503 -246 50.20% +1 ELO

So we are well below our radar level. Neverthless
there are 100.000 games on Joona QUAD that we could
take in account and that shows that this tweak perhaps
has something good in it, altough very little.

Verification tests shows should not be a regression, at
least not a big one even in the worst case, so apply the
change anyway and keep the finger crossed ;-)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSmall tidy up of previous patch
Marco Costalba [Fri, 10 Jul 2009 17:50:43 +0000 (18:50 +0100)]
Small tidy up of previous patch

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoStrip whitespace from beginning of string sent to set_option_value().
Tord Romstad [Fri, 10 Jul 2009 16:34:56 +0000 (18:34 +0200)]
Strip whitespace from beginning of string sent to set_option_value().

It turned out that the input sent to set_option_value() when it is called by
set_option() in uci.cpp always started with at least one whitespace. In most
cases, this is not a problem, because the majority of UCI options have numeric
values. It did, however, cause a problem for UCI options with non-numerical
values, like options of type CHECK and COMBO. In particular, changing the
value of an option of type CHECK didn't work, because the comparisons with
"true" and "false" would always return false. This means that the "Ponder"
and "UCI_Chess960" options haven't been working for a while.

14 years agoRevert last tweaks
Marco Costalba [Thu, 9 Jul 2009 12:36:08 +0000 (14:36 +0200)]
Revert last tweaks
Tests show no improvment, so revert for now.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoJoona tweaks of tempos and misc parameters
Marco Costalba [Mon, 6 Jul 2009 09:55:55 +0000 (10:55 +0100)]
Joona tweaks of tempos and misc parameters

Unfortunatly this tweak does not give good results.

After 894 games at 1+0 we have:

Mod vs Orig  +205/-236/=453 48.27%  -12 ELO !!

Perhaps we should test again, but in the mean time
we are going to revert this.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoRestore development versioning and LSN filtering
Marco Costalba [Mon, 6 Jul 2009 10:20:05 +0000 (11:20 +0100)]
Restore development versioning and LSN filtering

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix generation of check blocking promotion
Marco Costalba [Mon, 6 Jul 2009 08:40:50 +0000 (09:40 +0100)]
Fix generation of check blocking promotion

A promotion move is not considered a possible evasion as it could be.

Bug introduced by patch

Convert also generate_pawn_blocking_evasions() to new API (7/5/2009)

Bug spotted by Kenny Dail.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoStockfish 1.4
Marco Costalba [Sat, 4 Jul 2009 17:16:22 +0000 (18:16 +0100)]
Stockfish 1.4

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoSmall Makefile tweaks
Marco Costalba [Sat, 4 Jul 2009 20:56:04 +0000 (21:56 +0100)]
Small Makefile tweaks

Set gcc as default compiler on Linux, also compile
with symbols stripped to shrink binary file.

Original patch by Heinz van Saanen.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoFix bitcount.h compile warnings under Intel compiler
Marco Costalba [Sat, 4 Jul 2009 17:10:39 +0000 (18:10 +0100)]
Fix bitcount.h compile warnings under Intel compiler

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
14 years agoCheck Intel compiler before MSVC in bitcount.h
Marco Costalba [Sat, 4 Jul 2009 17:03:49 +0000 (18:03 +0100)]
Check Intel compiler before MSVC in bitcount.h

Predefined macro __INTEL_COMPILER is defined only for Intel,
while _MSC_VER is defined for both Intel C++ and MSVC.

So rearrange ifdefs to take in account this and test __INTEL_COMPILER
first and only if not defined check _MSC_VER for MSVC.

Patch suggested by Joona.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>