]> git.sesse.net Git - stockfish/log
stockfish
9 years agoFix compile for some versions of mingw
Gary Linscott [Sun, 14 Dec 2014 19:45:43 +0000 (14:45 -0500)]
Fix compile for some versions of mingw

The bswap intrinsics are specific to the compiler, not the
host platform.

No functional change.

Resolves #155

9 years agoAvoid searching TT twice for the same key/position during probe() and store().
mstembera [Sat, 13 Dec 2014 07:16:35 +0000 (07:16 +0000)]
Avoid searching TT twice for the same key/position during probe() and store().

Just keep the pointer and remove code from tt.cpp

STC
LLR: 2.96 (-2.94,2.94) [-1.50,4.50]
Total: 13620 W: 2810 L: 2665 D: 8145

LTC
LLR: 2.97 (-2.94,2.94) [0.00,6.00]
Total: 13021 W: 2238 L: 2073 D: 8710STC http://tests.stockfishchess.org/tests/view/548436860ebc59331739b90c

STC 4MB
ELO: 2.41 +-2.2 (95%) LOS: 98.6%
Total: 40000 W: 8175 L: 7897 D: 23928

LTC 16MB
ELO: 1.78 +-2.0 (95%) LOS: 96.1%
Total: 39683 W: 6763 L: 6560 D: 26360

Resolves #151

Bench: 8116521

9 years agoOnly use _ReadWriteBarrier on MSVC
Gary Linscott [Thu, 11 Dec 2014 19:56:24 +0000 (14:56 -0500)]
Only use _ReadWriteBarrier on MSVC

It was causing compile errors when cross-compiling using mingw.

No functional change.

9 years agoHalve StormDanger bonus for blocked pawn on A/H file
joergoster [Thu, 11 Dec 2014 18:06:03 +0000 (13:06 -0500)]
Halve StormDanger bonus for blocked pawn on A/H file

STC
LLR: 2.95 (-2.94,2.94) [-1.50,4.50]
Total: 3410 W: 758 L: 641 D: 2011

LTC
LLR: 2.95 (-2.94,2.94) [0.00,6.00]
Total: 33225 W: 5708 L: 5445 D: 22072

Bench: 8465811

Resolves #153

9 years agoMSVC compiling fixes
Gary Linscott [Thu, 11 Dec 2014 18:03:44 +0000 (13:03 -0500)]
MSVC compiling fixes

No functional change.

Resolves #150

9 years agoFix profile build for syzygy
Joona Kiiski [Sun, 7 Dec 2014 19:54:23 +0000 (19:54 +0000)]
Fix profile build for syzygy

Touch source files under syzygy directory to force recompilation
after collecting profile data.

No functional change

Resolves #149

9 years agoRetire 'os' flag from Makefile
Joona Kiiski [Sun, 7 Dec 2014 09:45:36 +0000 (09:45 +0000)]
Retire 'os' flag from Makefile

Appears to be unused

No functional change

Resolves #147

9 years agoAssorted nitpicking code-style
Marco Costalba [Mon, 8 Dec 2014 07:23:09 +0000 (08:23 +0100)]
Assorted nitpicking code-style

No functional change.

9 years agoClarify when forcing the moves loop
Marco Costalba [Mon, 8 Dec 2014 08:46:21 +0000 (09:46 +0100)]
Clarify when forcing the moves loop

In some cases we want to go direcly to the moves loop
without checking for early return. The patch make this
logic more clear and consistent.

Tested for no regression, passed STC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 25282 W: 5136 L: 5022 D: 15124

and LTC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 72007 W: 12133 L: 12095 D: 47779

bench: 9316798

9 years agoSimpler PRNG and faster magics search
Ernesto Gatti [Mon, 8 Dec 2014 00:10:57 +0000 (08:10 +0800)]
Simpler PRNG and faster magics search

This patch replaces RKISS by a simpler and faster PRNG, xorshift64* proposed
by S. Vigna (2014). It is extremely simple, has a large enough period for
Stockfish's needs (2^64), requires no warming-up (allowing such code to be
removed), and offers slightly better randomness than MT19937.

Paper: http://xorshift.di.unimi.it/
Reference source code (public domain):
http://xorshift.di.unimi.it/xorshift64star.c

The patch also simplifies how init_magics() searches for magics:

- Old logic: seed the PRNG always with the same seed,
  then use optimized bit rotations to tailor the RNG sequence per rank.

- New logic: seed the PRNG with an optimized seed per rank.

This has two advantages:
1. Less code and less computation to perform during magics search (not ROTL).
2. More choices for random sequence tuning. The old logic only let us choose
from 4096 bit rotation pairs. With the new one, we can look for the best seeds
among 2^64 values. Indeed, the set of seeds[][] provided in the patch reduces
the effort needed to find the magics:

64-bit SF:
Old logic -> 5,783,789 rand64() calls needed to find the magics
New logic -> 4,420,086 calls

32-bit SF:
Old logic -> 2,175,518 calls
New logic -> 1,895,955 calls

In the 64-bit case, init_magics() take 25 ms less to complete (Intel Core i5).

Finally, when playing with strength handicap, non-determinism is achieved
by setting the seed of the static RNG only once. Afterwards, there is no need
to skip output values.

The bench only changes because the Zobrist keys are now different (since they
are random numbers straight out of the PRNG).

The RNG seed has been carefully chosen so that the
resulting Zobrist keys are particularly well-behaved:

1. All triplets of XORed keys are unique, implying that it
   would take at least 7 keys to find a 64-bit collision
   (test suggested by ceebo)

2. All pairs of XORed keys are unique modulo 2^32

3. The cardinality of { (key1 ^ key2) >> 48 } is as close
   as possible to the maximum (65536)

Point 2 aims at ensuring a good distribution among the bits
that determine an TT entry's cluster, likewise point 3
among the bits that form the TT entry's key16 inside a
cluster.

Details:

     Bitset   card(key1^key2)
     ------   ---------------
RKISS
     key16     64894   = 99.020% of theoretical maximum
     low18    180117   = 99.293%
     low32    305362   = 99.997%

Xorshift64*, old seed
     key16     64918   = 99.057%
     low18    179994   = 99.225%
     low32    305350   = 99.993%

Xorshift64*, new seed
     key16     65027   = 99.223%
     low18    181118   = 99.845%
     low32    305371   = 100.000%

Bench: 9324905

Resolves #148

9 years agoAdd some tablebase positions to bench
Gary Linscott [Sun, 7 Dec 2014 23:55:53 +0000 (07:55 +0800)]
Add some tablebase positions to bench

This makes it easier to check for regressions in the tablebase code.

Bench: 9489202
5-man bench: 8943906

Resolves #145

9 years agoRename some variables for more clarity.
hxim [Sun, 7 Dec 2014 23:53:33 +0000 (07:53 +0800)]
Rename some variables for more clarity.

No functional change.

Resolves #131

9 years agoExplicitly pass RootMoves to TB probes
Marco Costalba [Sun, 30 Nov 2014 13:59:09 +0000 (14:59 +0100)]
Explicitly pass RootMoves to TB probes

Currently Search::RootMoves is accessed and even
modified by TB probing functions in a hidden
and sneaky way.

This is bad practice and makes the code tricky.
Instead explicily pass the vector as function
argument so to clarify that the vector is modified
inside the functions.

No functional change.

9 years agoMove TB stuff under Tablebases namespace
Marco Costalba [Sun, 30 Nov 2014 11:14:14 +0000 (12:14 +0100)]
Move TB stuff under Tablebases namespace

Simplified also some logic while there.

TBLargest needs renaming too, but itis for
a future patch because touches also syzygy
directory stuff.

No functional change.

9 years agoRefactor syzygy code in search
Marco Costalba [Sun, 30 Nov 2014 07:38:46 +0000 (08:38 +0100)]
Refactor syzygy code in search

Move to SF coding style.

Also skip calculating piece count in search()
when TB are not found (!TBCardinality)

No functional change.

9 years agoRetire support for Haiku installation directory from Makefile
Joona Kiiski [Sun, 30 Nov 2014 21:02:39 +0000 (21:02 +0000)]
Retire support for Haiku installation directory from Makefile

- It is out of the scope of the project.
- It is the responsibility of Haiku package maintainer to
  configure this.

No functional change

Resolves #143

9 years agoRetire hackish support for aCC and HP-UX from Makefile
Joona Kiiski [Sun, 30 Nov 2014 20:50:01 +0000 (20:50 +0000)]
Retire hackish support for aCC and HP-UX from Makefile

- It is out of scope of the project.
- We have no way to verify that it even works anymore

No functional change

Resolves #142

9 years agoRetire total_piece_count()
Marco Costalba [Sun, 30 Nov 2014 20:35:22 +0000 (20:35 +0000)]
Retire total_piece_count()

We really don't need to uglify in this way
our nice count() API with this ad-hoc hack.

So remove the hack and use the already
existing infrastructure.

No functional change.

Resolves #134

9 years agoRemove CONNECTED_KINGS from Syzygy code
hxim [Sat, 29 Nov 2014 09:02:32 +0000 (10:02 +0100)]
Remove CONNECTED_KINGS from Syzygy code

No functional change

Resolves #140

9 years agoCleaning Syzygy profiling data
Rodrigo Exterckötter Tjäder [Thu, 27 Nov 2014 18:30:18 +0000 (16:30 -0200)]
Cleaning Syzygy profiling data

Updating the makefile so that the clean and gcc-profile-clean targets also
remove the profiling data files in the syzygy directory.

No functional change.

Resolves #136

9 years agoRewrite TBScore in uci_pv()
Marco Costalba [Wed, 26 Nov 2014 11:56:08 +0000 (12:56 +0100)]
Rewrite TBScore in uci_pv()

Streamline the code and make
it understandable.

No functional change.

Resolves #135

9 years agoRetire #ifdef SYZYGY macro
Marco Costalba [Sat, 29 Nov 2014 08:22:25 +0000 (09:22 +0100)]
Retire #ifdef SYZYGY macro

It just clutters the code for no
real reason.

No functional change.

Resolves #139

9 years agoBitbase index() from ADD to OR.
mstembera [Tue, 25 Nov 2014 23:56:48 +0000 (07:56 +0800)]
Bitbase index() from ADD to OR.

No functional change.

Resolves #132

9 years agoIntroduce ratio operation
lucasart [Tue, 25 Nov 2014 23:53:40 +0000 (07:53 +0800)]
Introduce ratio operation

Just like in Physics, the ratio of 2 things in the same unit, should be
without unit.

Example use case:
- Ratio of a Depth by a Depth (eg. ONE_PLY) should be an int.
- Ratio of a Value by a Value (eg. PawnValueEg) should be an int.

Remove a bunch of useless const while there.

No functional change.

Resolves #128

9 years agoSyzygy tablebases
Ronald de Man [Tue, 25 Nov 2014 23:45:28 +0000 (07:45 +0800)]
Syzygy tablebases

Adds support for Syzygy tablebases to Stockfish.  See
the Readme for information on using the tablebases.

Tablebase support can be enabled/disabled at the Makefile
level as well, by setting syzygy=yes or syzygy=no.

Big/little endian are both supported.

No functional change (if Tablebases are not used).

Resolves #6

9 years agoFix out-of-bound array access printing ponder move
Gary Linscott [Mon, 24 Nov 2014 00:53:00 +0000 (08:53 +0800)]
Fix out-of-bound array access printing ponder move

It is possible that we won't have a ponder move if our PV
is too short.  In that case, just don't print a ponder move.

No functional change

Resolves #130

9 years agoFix pondering
Gary Linscott [Mon, 24 Nov 2014 00:49:53 +0000 (08:49 +0800)]
Fix pondering

The UCI specification states that an engine can never exit the search
while pondering.

No functional change.

Resolves #118

9 years agoAmend defended
Jonathan Calovski [Fri, 21 Nov 2014 21:46:59 +0000 (05:46 +0800)]
Amend defended

Amend defended to remove now redundant condition.

No functional change.

Resolves #125

9 years agoFix doubled pawns asymmetry
Marco Costalba [Thu, 20 Nov 2014 11:13:00 +0000 (12:13 +0100)]
Fix doubled pawns asymmetry

When evaluating double pawns we use always
lsb() to extract the frontmost square.

This breaks evaluation color symmetry as is
possible to verify with an instrumented evaluate()

  Value evaluate(const Position& pos) {

    Value v = do_evaluate<false>(pos);
    Position p = pos;
    p.flip();
    assert(v == do_evaluate<false>(p));
    return v;
  }

Passed no regression test:

STC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 21035 W: 4244 L: 4122 D: 12669

LTC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 39839 W: 6662 L: 6572 D: 26605

bench: 8255966

9 years agoFurther tweak accurate pv
Marco Costalba [Fri, 21 Nov 2014 08:10:52 +0000 (09:10 +0100)]
Further tweak accurate pv

It is a non functional change, but because
we now skip copying of pv[] in SpNode, patch
has been tested for regression with 3 threads:

STC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 54668 W: 9873 L: 9809 D: 34986

No functional change.

9 years agoFix some comments
hxim [Tue, 18 Nov 2014 22:39:17 +0000 (06:39 +0800)]
Fix some comments

No functional change.

Resolves #123

9 years agoFix fen output for castling rights
Gary Linscott [Tue, 18 Nov 2014 22:36:45 +0000 (06:36 +0800)]
Fix fen output for castling rights

This is a regression from 428962a

We have to cast to char here, otherwise the compiler
interprets it as an integer, and writes a number.

No functional change

Resolves #122

9 years agoCodying style in accurate PV
Marco Costalba [Tue, 18 Nov 2014 10:57:57 +0000 (11:57 +0100)]
Codying style in accurate PV

This is the first of a patch series to
rearrange and simplify accurate PV.

In this patch there is simple coding
style and reformatting stuff.

Verified with fishtest it does not crash
with MAX_PLY = 8

No functional change.

9 years agoFix a warning on Intel C++
Marco Costalba [Sun, 16 Nov 2014 15:25:20 +0000 (16:25 +0100)]
Fix a warning on Intel C++

warning #2259: non-pointer conversion from "int" to
"uint8_t={unsigned char}" may lose significant bits

No functional change.

9 years agoUse PHASE_MIDGAME in game_phase()
sf-x [Sun, 16 Nov 2014 23:50:33 +0000 (07:50 +0800)]
Use PHASE_MIDGAME in game_phase()

No functional change

Resolves #117

9 years agoClear token before reading from input
Rodrigo Exterckötter Tjäder [Sun, 16 Nov 2014 23:48:30 +0000 (07:48 +0800)]
Clear token before reading from input

Previously token would keep its value from the previous line when an empty
line was input, leading to unexpected behaviour.

No functional change

Resolves #119

9 years agoHalf History Max
lucasart [Sun, 16 Nov 2014 23:04:58 +0000 (07:04 +0800)]
Half History Max

STC
LLR: 3.35 (-2.94,2.94) [-0.50,3.50]
Total: 17993 W: 3740 L: 3508 D: 10745

LTC
LLR: 3.25 (-2.94,2.94) [0.00,4.00]
Total: 21346 W: 3691 L: 3453 D: 14202

Bench: 7694316

Resolves #120

9 years agoUse DEPTH_MAX instead of MAX_PLY
Marco Costalba [Sat, 15 Nov 2014 04:36:49 +0000 (05:36 +0100)]
Use DEPTH_MAX instead of MAX_PLY

When comparing to a Depth it is more
consistent to use DEPTH_MAX instead
of a int.

This is a subtle difference because we use
ply and depth almost interchangably in SF,
but they are different. FOr counting plies
makes ense to continue using ints, while
for Depth we have our specific enum.

This cleanly fixes a new Clang 3.5 warning:

No functional change.

9 years ago100% accurate PV display
Gary Linscott [Wed, 12 Nov 2014 21:13:55 +0000 (16:13 -0500)]
100% accurate PV display

This gives SF accurate PVs, such that the evaluation of the leaf node in
the PV matches the score backed up to the root (99% of the time.
q-search will use the value stored in the hash table instead of the eval
value sometimes).

One drawback is that fail-high/low only get a minimal 2 move PV.

It doesn't add any additional overhead to the non-PV codepath except an
extra eight bytes to the SearchStack structure in multi-threaded
searches.

A core part of this is not pruning based on TT score in PV nodes. This
was measured as not being a regression at multiple TCs, except for one
exception, fast TC with huge hash, which is not realistic for longer
searches.

STC - 1 thread, 128 mb hash
ELO: 1.42 +-3.1 (95%) LOS: 81.9%
Total: 20000 W: 4078 L: 3996 D: 11926

STC - 3 thread, 128 mb hash
ELO: -3.60 +-2.9 (95%) LOS: 0.8%
Total: 20000 W: 3575 L: 3782 D: 12643

STC - 3 thread, 8 mb hash
ELO: 0.12 +-2.9 (95%) LOS: 53.3%
Total: 20000 W: 3654 L: 3647 D: 12699

LTC - 3 thread, 32mb hash
ELO: 2.29 +-2.0 (95%) LOS: 98.8%
Total: 35740 W: 5618 L: 5382 D: 24740

Bench: 6984058

Resolves #102

9 years agoUse quiet ttMove in qsearch() (7962287)
lucasart [Mon, 10 Nov 2014 11:14:16 +0000 (19:14 +0800)]
Use quiet ttMove in qsearch() (7962287)

Daniel Jose reported that it was an elo gain in his engine:
http://www.talkchess.com/forum/viewtopic.php?t=54290

STC: Hash=16
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 33067 W: 6670 L: 6571 D: 19826

LTC: Hash=64
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 41181 W: 7008 L: 6920 D: 27253

And another one to verify no regression with hash pressure:

STC: Hash=4
LLR: 2.96 (-2.94,2.94) [-4.00,0.00]
Total: 25085 W: 5059 L: 4991 D: 15035

Verified that qsearch does not explode after this patch (recapture threshold).

Bench 7962287

Resolves #112

9 years agoUse if/else instead of goto
Marco Costalba [Mon, 10 Nov 2014 13:46:05 +0000 (14:46 +0100)]
Use if/else instead of goto

Real men jump/branch by hand...but
we prefer the humble way.

Moved also some uci info code where it
belongs, while there.

No functional change.

Resolves #110

9 years agoUse Depth instead of int in search
Marco Costalba [Mon, 10 Nov 2014 14:09:36 +0000 (15:09 +0100)]
Use Depth instead of int in search

And make it more ONE_PLY value independent,
although we are not there yet.

No functional change.

Resolves #111

9 years agoProfile Build with Hash=16
lucasart [Mon, 10 Nov 2014 10:49:13 +0000 (18:49 +0800)]
Profile Build with Hash=16

16MB for 1" searches is more comensurate with the average use case.

And 16 is the default used by stockfish bench, so it makes sense to be
consistent, if only to have the same minimum memory requirement for using
SF and compiling it with PGO.

No functional change.

Resolves #109

9 years agoFix bounds of FutilityMoveCounts
lucasart [Sun, 9 Nov 2014 00:45:27 +0000 (08:45 +0800)]
Fix bounds of FutilityMoveCounts

This is a left-over from ONE_PLY == 2.

No functional change.

Resolves #107

9 years agoRetire pvMove in search()
Marco Costalba [Sat, 8 Nov 2014 10:39:38 +0000 (11:39 +0100)]
Retire pvMove in search()

Now we can directly replace it with
the definition resulting in simpler
and possibly faster code because
PvNode is evaluated at compile time.

No functional change.

9 years agoAssorted code-style triviality
Marco Costalba [Sun, 9 Nov 2014 08:24:06 +0000 (09:24 +0100)]
Assorted code-style triviality

No functional change.

9 years agoIntroduce distance() and unify some API
Marco Costalba [Sat, 8 Nov 2014 13:04:14 +0000 (14:04 +0100)]
Introduce distance() and unify some API

Original work by Lucas.

No functional change.

9 years agoCodestyle massage Search::init()
lucasart [Sat, 8 Nov 2014 15:56:51 +0000 (10:56 -0500)]
Codestyle massage Search::init()

* remove some erroneous comments, that were based on the ONE_PLY == 2.
* rename hd to d, because there's no more half-depth in SF.
* rescope variables into the for loops.
* reindent the for loops correctly.
* add a comment to explain the eval improving part (not so obvious to read
this code as array has 4 dimensions).

No functional change.

9 years agoBe more optimistic in aspiration window
lucasart [Sat, 8 Nov 2014 15:47:56 +0000 (10:47 -0500)]
Be more optimistic in aspiration window

Be more optimistic wrt search instability, and set the unviolated bound
half window.

STC
LLR: 2.96 (-2.94,2.94) [-1.00,4.00]
Total: 16362 W: 3371 L: 3197 D: 9794

LTC
LLR: 2.94 (-2.94,2.94) [0.00,5.00]
Total: 21666 W: 3780 L: 3569 D: 14317

Bench: 6807896

Resolves #105

9 years agoPrune ttMove like any other
lucasart [Fri, 7 Nov 2014 21:40:24 +0000 (21:40 +0000)]
Prune ttMove like any other

This should reduce search inconsistencies, and doesn't seem to have a measurable ELO Impact:

STC with Hash=16
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 49264 W: 10076 L: 10007 D: 29181

LTC with Hash=64
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 82149 W: 14044 L: 14023 D: 54082

Plus an extra test, to make sure it doesn't regress with strong hash pressure:

STC with Hash=4
LLR: 2.95 (-2.94,2.94) [-4.00,0.00]
Total: 21498 W: 4327 L: 4246 D: 12925

Bench: 7302735

Resolves #100

9 years agoRetire CACHE_LINE_ALIGNMENT
lucasart [Fri, 7 Nov 2014 19:26:23 +0000 (14:26 -0500)]
Retire CACHE_LINE_ALIGNMENT

Speed tests showed no benefit.

No functional change.

Resolves #97

9 years agoApply King Safety later in the endgame
lucasart [Thu, 6 Nov 2014 18:00:07 +0000 (13:00 -0500)]
Apply King Safety later in the endgame

Idea is to apply king safety later in the endgame. Previously, we didn't
apply KS in a RR vs. Q ending for example, which causes poor play.
Now we calculate king attacks when the attacking side has a queen or more.

STC with 8moves_v3
LLR: 3.06 (-2.94,2.94) [0.00,4.00]
Total: 38481 W: 6228 L: 5952 D: 26301

LTC with 2moves_v1
LLR: 2.95 (-2.94,2.94) [0.00,4.00]
Total: 51053 W: 8670 L: 8353 D: 34030

Bench: 7514010

Resolves #98

9 years agoRemoving some superfluous extern declarations
mstembera [Sun, 2 Nov 2014 05:10:31 +0000 (22:10 -0700)]
Removing some superfluous extern declarations

No functional change.

Resolves #93

9 years agoAssume UCI 'nodes' is int64_t instead of int
Marco Costalba [Thu, 30 Oct 2014 11:11:20 +0000 (12:11 +0100)]
Assume UCI 'nodes' is int64_t instead of int

UCI specification is not clear on the size of
integers that are exchanged in the protocol, so
instead of a simple int, assume 'nodes' is a
int64_t because we need a bigger size to store
this value in many real cases, especialy with
very long searches.

No functional change.

Resolves #75

9 years agoRearrange check_time()
Marco Costalba [Sat, 18 Oct 2014 05:44:08 +0000 (07:44 +0200)]
Rearrange check_time()

Remove an ugly workaround for a gcc
warning while there.

No functional change.

9 years agoAdd bonuses for each threat instead of max threat value.
Ajith [Tue, 4 Nov 2014 15:40:37 +0000 (23:40 +0800)]
Add bonuses for each threat instead of max threat value.

Use SPSA tuned values for all threat bonuses

STC
LLR: 2.96 (-2.94,2.94) [-1.50,4.50]
Total: 6074 W: 1284 L: 1160 D: 3630

LTC
LLR: 2.97 (-2.94,2.94) [0.00,6.00]
Total: 13563 W: 2402 L: 2232 D: 8929

Bench: 6981908

Resolves #94

9 years agoOptimize TranspositionTable::store() and TranspositionTable::probe() for speed.
mstembera [Sat, 1 Nov 2014 05:48:19 +0000 (22:48 -0700)]
Optimize TranspositionTable::store() and TranspositionTable::probe() for speed.

No functional change.

Resolves #85

9 years agoDo not assume that enum are signed
lucasart [Mon, 3 Nov 2014 16:35:02 +0000 (00:35 +0800)]
Do not assume that enum are signed

Clang 3.5 issues warning on constructs like: abs(f1 - f2). The thing is that
f1 and f2 are enum types, and the range given (all positive) allows the
compiler to choose an unsigned type (efficiency being one reason to prefer
unsigned arithmetic). If f1 < f2 are unsigned, then f1 - f2 wraps around zero
and the abs() becomes a no-op. It's the reinterpretation of the unsigned
result (large value) as a signed int that happens to give the correct result,
thanks to 2's complement. This is all tricky and dangerous!

In the spirit of the standard, we assume nothing on the signedness of enums,
and simply calculate the rank and file distances as:
- rank_dist(r1, r2) = r1 < r2 ? r2 - r1 : r1 - r2
- file_dist(f1, f2) = f1 < f2 ? f2 - f1 : f1 - f2
this logic can in fact be applied to any enum we may use, so for better
generality and to avoid code duplication, we use a template function diff()
here.

No functional change.

Resolves #95

9 years agoCleanup MAX_PLY
lucasart [Mon, 3 Nov 2014 15:36:24 +0000 (23:36 +0800)]
Cleanup MAX_PLY

This area has become obscure and tricky over the course of incremental
changes that did not respect the original's consistency and clarity. Now,
it's not clear why we use MAX_PLY = 120, or why we use MAX_PLY+6, among
other things.

This patch does the following:

* ID loop: depth ranges from 1 to MAX_PLY-1, and due to TT constraint (depth
must fit into an int8_t), MAX_PLY should be 128.

* stack[]: plies now range from 0 to MAX_PLY-1, hence stack[MAX_PLY+4],
because of the extra 2+2 padding elements (for ss-2 and ss+2). Document this
better, while we're at it.

* Enforce 0 <= ply < MAX_PLY:
  - stop condition is now ss->ply >= MAX_PLY and not ss->ply > MAX_PLY.
  - assert(ss->ply < MAX_PLY), before using ss+1 and ss+2.
  - as a result, we don't need the artificial MAX_PLY+6 range. Instead we
  can use MAX_PLY+4 and it's clear why (for ss-2 and ss+2).

* fix: extract_pv_from_tt() and insert_pv_in_tt() had no reason to use
MAX_PLY_PLUS_6, because the array is indexed by plies, so the range of
available plies applies (0..MAX_PLY before, and now 0..MAX_PLY-1).

Tested with debug compile, using MAX_PLY=16, and running bench at depth 17,
using 1 and 7 threads. No assert() fired. Feel free to submit to more severe
crash-tests, if you can think of any.

No functional change.

9 years agoRestore std::dec after std::hex
Marco Costalba [Sun, 2 Nov 2014 07:03:52 +0000 (08:03 +0100)]
Restore std::dec after std::hex

Code is leaking a std::hex, and causes subsequent
sync_cout output to be in hexadecimal.

Spotted by Lucas

No functional change.

9 years agoRetire ScalePawnSpan[]
Marco Costalba [Sat, 1 Nov 2014 21:18:15 +0000 (22:18 +0100)]
Retire ScalePawnSpan[]

Obscure, undocmented and misnamed array. Replace with
the direct formula: it is much more clear what the
code does.

No functional change.

Resolves #90

9 years agoMerge pull request #89 from official-stockfish/pull_no_pretty
Marco Costalba [Sat, 1 Nov 2014 21:24:33 +0000 (22:24 +0100)]
Merge pull request #89 from official-stockfish/pull_no_pretty

Prefer operator<<() to pretty()

No functional change.

9 years agoRetire PawnsFileSpan
Marco Costalba [Sat, 1 Nov 2014 17:15:07 +0000 (18:15 +0100)]
Retire PawnsFileSpan

It is useless. Tested as no regression:

STC
LLR: 4.06 (-2.94,2.94) [-3.00,1.00]
Total: 140718 W: 28527 L: 28568 D: 83623

LTC
LLR: 2.94 (-2.94,2.94) [-3.00,1.00]
Total: 60034 W: 10359 L: 10303 D: 39372

bench: 6564212

Resolves #88

9 years agoCorrectly describe POPCNT compile
lucasart [Sat, 1 Nov 2014 20:43:57 +0000 (20:43 +0000)]
Correctly describe POPCNT compile

SSE4.2 has nothing to do with POPCNT. We must dispell this myth, because
Stockfish is a reference and many will copy this mistake if they see it in Stockfish:
* SSE is an SIMD instruction set, relative to vectorization (using special 128-bit registers).
* POPCNT/LZCNT work on normal registers (eg. AL, AX, EAX, RAX).

The confusion comes from the fact that, in the Intel product line, it just
so happens that SSE4.2 and POPCNT/LZCNT came out at the same time. But this
is not true for AMD. For example, all AMD Pheniom II have SSE3 but no
POPCNT/LZCNT, and that is why the modern compile uses  -msse3 -popcnt and not -msse4.2.

No functional change.

Resolves #86

9 years agoConsistent use of anonymous namespace
lucasart [Sat, 1 Nov 2014 20:35:10 +0000 (20:35 +0000)]
Consistent use of anonymous namespace

Objects that are only accessible at file-scope should be put in the anonymous namespace.
This is what the  C++ standard recommends, rather than using static, which is really C-style and results in static linkage.

Stockfish already does this throughout the code. So let's weed out the few exceptions,
because... they have no reason to be exceptional.

No functional change.

Resolves #84

9 years agoRemove dead code
lucasart [Sat, 1 Nov 2014 20:16:29 +0000 (20:16 +0000)]
Remove dead code

No functional change.

Closes #87

9 years agoPrefer operator<<() to pretty()
Marco Costalba [Sat, 1 Nov 2014 17:50:27 +0000 (18:50 +0100)]
Prefer operator<<() to pretty()

It is more idiomatic, we didn't used it
in the past because Position::pretty(Move)
had a calling argument, but now we can.

As an added benefit, we avoid a lot of string
copies in the process because now we avoid
std::ostringstream ss.

No functional change.

9 years agoMerge pull request #82 from official-stockfish/clean_up_bishop_code
Marco Costalba [Sat, 1 Nov 2014 17:05:03 +0000 (18:05 +0100)]
Merge pull request #82 from official-stockfish/clean_up_bishop_code

Code style clean-up

No functional change.

9 years agoCode style clean-up
Marco Costalba [Thu, 30 Oct 2014 11:32:43 +0000 (12:32 +0100)]
Code style clean-up

This piece of code needs some love.

No functional change.

9 years agomax_piece_type cleanup, and slight speed increase.
mstembera [Tue, 28 Oct 2014 14:23:01 +0000 (22:23 +0800)]
max_piece_type cleanup, and slight speed increase.

No functional change.

Resolves #81

9 years agoA small clean up of previous patch suggested by Marco
Joona Kiiski [Mon, 27 Oct 2014 20:14:58 +0000 (20:14 +0000)]
A small clean up of previous patch suggested by Marco

No functional change

9 years agoSpeed up max_piece_type()
Joona Kiiski [Mon, 27 Oct 2014 14:05:24 +0000 (14:05 +0000)]
Speed up max_piece_type()

Write code in the way that allows compiler to perform loop unrolling.

My measurement (32 cycles each):

Orig:

Time (Mean: 2466.59375, Trimmed mean: 2464.25, Std: 12.6869487803348)
Nodes (Mean: 4294458, Trimmed mean: 4294458, Std: 0)
Speed (Mean: 1741.09247987678, Trimmed mean: 1742.72879715475, Std: 8.93612608292678)

Time (Mean: 2470.15625, Trimmed mean: 2468.75, Std: 12.7484581610433)
Nodes (Mean: 4294458, Trimmed mean: 4294458, Std: 0)
Speed (Mean: 1738.58176151341, Trimmed mean: 1739.54618465403, Std: 8.95585822316946)

Mod:

Time (Mean: 2449.90625, Trimmed mean: 2445.9375, Std: 12.1000116635508)
Nodes (Mean: 4294458, Trimmed mean: 4294458, Std: 0)
Speed (Mean: 1752.94829372932, Trimmed mean: 1755.75934908231, Std: 8.61478453124504)

Time (Mean: 2442.78125, Trimmed mean: 2441.1875, Std: 8.17839157228837)
Nodes (Mean: 4294458, Trimmed mean: 4294458, Std: 0)
Speed (Mean: 1758.03872783803, Trimmed mean: 1759.16825356261, Std: 5.81131316346191)

No functional change

9 years agoTune PawnsFileSpan
snicolet [Sun, 26 Oct 2014 23:08:56 +0000 (00:08 +0100)]
Tune PawnsFileSpan

Passed the following SPRT tests:

STC:
LLR: 2.96 (-2.94,2.94) [-1.50,4.50]
Total: 24428 W: 5056 L: 4880 D: 14492

LTC:
LLR: 2.96 (-2.94,2.94) [0.00,4.00]
Total: 26590 W: 4715 L: 4472 D: 17403

Bench: 6615949

Resolves #78

9 years agoImprove compatibility with Shredder Classic GUI
Pascal Romaret [Mon, 27 Oct 2014 11:07:35 +0000 (11:07 +0000)]
Improve compatibility with Shredder Classic GUI

This commit fixes two issues:

1) Don't print PVs after the search has been interrupted

    This solves the "mate 0 upperbound" scores that sometimes
    creep up when a multi-PV analysis gets interrupted with
    the `stop` command.

2) Print multipv before score

    Shredder Classic fails to identify the main PV
    (the one with multipv 1) if `score` comes first.
    This leads to an eval graph that doesn't reflect
    the scores actually reported by Stockfish when
    doing a multiPV analysis.

No functional change

Closes #76

9 years agoFix an obscure gcc warning
Marco Costalba [Sun, 26 Oct 2014 07:14:36 +0000 (08:14 +0100)]
Fix an obscure gcc warning

warning: narrowing conversion from ‘int’ to ‘char’ inside { }
is ill-formed in C++11 [-Wnarrowing]

When pedantic meets esoteric!

No functional change.

9 years agoRetire notation.cpp
Marco Costalba [Sun, 26 Oct 2014 06:50:09 +0000 (07:50 +0100)]
Retire notation.cpp

Now we can finally retire notation.cpp
and move UCI helpers under uci.cpp

No functional change.

9 years agoFinal UCI helpers renaming
Marco Costalba [Sun, 26 Oct 2014 06:41:25 +0000 (07:41 +0100)]
Final UCI helpers renaming

To reflect new changes, specifically that
now are all under UCI namespace.

No functional change.

9 years agoRetire notation.h
Marco Costalba [Sun, 26 Oct 2014 06:16:16 +0000 (07:16 +0100)]
Retire notation.h

And move the few remaining content
under UCI namespace where they belong.

No functional change.

9 years agoRename ucioption.h to uci.h
Marco Costalba [Sun, 26 Oct 2014 06:09:19 +0000 (07:09 +0100)]
Rename ucioption.h to uci.h

We are going to add all UCI related
functions here, so first rename it
to a more proper name.

No functional change.

9 years agoRetire to_char() helpers
Marco Costalba [Sun, 26 Oct 2014 05:52:30 +0000 (06:52 +0100)]
Retire to_char() helpers

Remove some useless wrappers and make
the conversion explicit and starightforward.

No functional change.

9 years agoReformat max_threat()
Marco Costalba [Sat, 25 Oct 2014 05:03:42 +0000 (07:03 +0200)]
Reformat max_threat()

Helper function should just know how to find the
biggest piece type in a bitboard. All the threat
logic and data shoud be in evaluate_threats().

This nicely separates the scope of the two functions
in a more consistent way and simplifies the code.

No functional change.

9 years agoCalculate maximum threat for hanging pieces
snicolet [Thu, 23 Oct 2014 17:10:11 +0000 (01:10 +0800)]
Calculate maximum threat for hanging pieces

Use the max_threat() helper function to estimate more precisely the
best hanging piece threat.  Also retunes the Threat array using SPSA.

STC
LLR: 2.95 (-2.94,2.94) [-1.50,4.50]
Total: 7598 W: 1596 L: 1468 D: 4534

LTC
LLR: 2.97 (-2.94,2.94) [0.00,6.00]
Total: 7896 W: 1495 L: 1350 D: 5051

Bench: 6816504

Resolves #73

9 years agoDocument why initing eval tables
Marco Costalba [Mon, 13 Oct 2014 07:23:21 +0000 (09:23 +0200)]
Document why initing eval tables

Instead of hard-code the weights in a big table,
we prefer to calculate them out of few parameters
at startup. This allows to keep low the number of
independent parameters and hence is good for tuning
and for a better insight in the meaning of the numbers.

No functional change.

9 years agoRename Tracing methods
Marco Costalba [Sat, 11 Oct 2014 07:52:16 +0000 (09:52 +0200)]
Rename Tracing methods

Easier to understand and more in line with
standard Trace classes naming like:

http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx

No functional change.

9 years agoAccount for Tempo in do_evaluate()
Marco Costalba [Sat, 11 Oct 2014 07:05:47 +0000 (09:05 +0200)]
Account for Tempo in do_evaluate()

This is more correct because we let evaluate()
to be a pure dispatcher and also now evaluate
and tracing outputs are consistent.

No functional change.

9 years agoFix some warnings with Intel C++ compiler
Marco Costalba [Sun, 5 Oct 2014 08:53:31 +0000 (10:53 +0200)]
Fix some warnings with Intel C++ compiler

No functional change.

9 years ago Further streamline connected pawn evaluation
lucasart [Sun, 12 Oct 2014 19:03:49 +0000 (20:03 +0100)]
 Further streamline connected pawn evaluation

Make even more clear what are the terms that
contribute to evaluate connected pawns, and
completely separate them from the weights
that are now fully looked up in a table.

For future tuning makes sense to init the table with
a formula instead of hard-code it. This allows to
reduce problem space cardinality and makes tuning
easier.

And fix a MSVC warning while there:
warning C4804: '>>' : unsafe use of type 'bool' in operation

No functional change.

9 years agoMerge Connected and Candidate
lucasart [Mon, 6 Oct 2014 11:26:30 +0000 (19:26 +0800)]
Merge Connected and Candidate

These two notions are very correlated. Since connected has the most
generality, it makes sense to generalize it to encompass what is
covered by candidate.

STC:
LLR: 4.03 (-2.94,2.94) [-3.00,1.00]
Total: 11970 W: 2577 L: 2379 D: 7014

LTC:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 13194 W: 2389 L: 2255 D: 8550

bench 7328585

9 years agoRemove the now redundant TT prefetch call from Position::do_move.
joergoster [Mon, 6 Oct 2014 15:59:04 +0000 (23:59 +0800)]
Remove the now redundant TT prefetch call from Position::do_move.

Tested for no regression and passed both
STC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 48250 W: 9757 L: 9686 D: 28807

LTC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 51412 W: 8887 L: 8816 D: 33709

No functional change.

Resolves #66

9 years agoSimplify futility move count array formula
Luca Brivio [Sun, 5 Oct 2014 11:49:18 +0000 (12:49 +0100)]
Simplify futility move count array formula

No functional change

9 years agoReformat and rename hash_after_move()
Marco Costalba [Sat, 4 Oct 2014 04:07:55 +0000 (06:07 +0200)]
Reformat and rename hash_after_move()

Align to standard coding style and properly use
enum types. Rename while there.

No functional change.

9 years agoExtend King Threats to all pieces (other than pawns).
Ajith [Fri, 3 Oct 2014 19:54:12 +0000 (03:54 +0800)]
Extend King Threats to all pieces (other than pawns).

STC
LLR: 2.99 (-2.94,2.94) [-1.50,4.50]
Total: 20559 W: 4261 L: 4095 D: 12203

LTC
LLR: 2.96 (-2.94,2.94) [0.00,4.00]
Total: 75232 W: 13097 L: 12696 D: 49439

Bench: 7543790

Resolves #63

9 years agoSpeculative prefetch
joergoster [Thu, 2 Oct 2014 21:19:14 +0000 (22:19 +0100)]
Speculative prefetch

Idea by Peter Oesterlund.
Implemented and tested by Joerg Oester

STC 3 threads
ELO: 3.19 +-2.1 (95%) LOS: 99.9%
Total: 40000 W: 7576 L: 7209 D: 25215

LTC
LLR: 2.96 (-2.94,2.94) [0.00,6.00]
Total: 22026 W: 3829 L: 3619 D: 14578

STC
LLR: 2.95 (-2.94,2.94) [-1.50,4.50]
Total: 7291 W: 1531 L: 1404 D: 4356

No functional change

Resolves #61

9 years agoConvert TT depth to int8_t
lucasart [Wed, 1 Oct 2014 19:51:32 +0000 (20:51 +0100)]
Convert TT depth to int8_t

Now that half plies have been removed from the engine, we can encode
TT depth into an int8_t.

Range is -128 to +127, so it goes still further than the previous
limit of 121 plies (with ONE_PLY == 2 where depth - DEPTH_NONE was
encoded as an uint8_t).

No functional change.

Resolved #60

9 years agoTrivial code style fixes
Marco Costalba [Tue, 30 Sep 2014 07:05:20 +0000 (09:05 +0200)]
Trivial code style fixes

Mainly to sync mine and official repo.

No functional change.

9 years agoMove ONE_PLY to be 1 instead of 2: search()
Marco Costalba [Mon, 29 Sep 2014 12:08:56 +0000 (14:08 +0200)]
Move ONE_PLY to be 1 instead of 2: search()

Now that half-plies are no more used we can simplify
the code assuming that ONE_PLY is 1 and no more 2.

Verified with a SMP test:
LLR: 2.95 (-2.94,2.94) [-4.50,0.00]
Total: 8926 W: 1712 L: 1607 D: 5607

No functional change.

9 years agoClean up VALUE_KNOWN_WIN conditions
lucasart [Sun, 28 Sep 2014 16:45:49 +0000 (17:45 +0100)]
Clean up VALUE_KNOWN_WIN conditions

A patch (+ some extra changes) passed with:

STC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 14575 W: 3101 L: 2967 D: 8507

LTC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 42579 W: 7580 L: 7496 D: 27503

Bench: 6545733

Resolves #52

9 years agoRemove use of half-ply reductions from LMR, Null-move, IID and
Uri Blass [Sat, 27 Sep 2014 20:33:28 +0000 (04:33 +0800)]
Remove use of half-ply reductions from LMR, Null-move, IID and
Singular extensions.

STC:
ELO: 3.80 +-3.1 (95%) LOS: 99.2%
Total: 19727 W: 4190 L: 3974 D: 11563

LTC:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 7647 W: 1356 L: 1214 D: 5077

Bench: 6545733

Resolves #55

9 years agoCap evaluation based null move extra reduction to three plies
Joona Kiiski [Thu, 25 Sep 2014 19:42:25 +0000 (20:42 +0100)]
Cap evaluation based null move extra reduction to three plies

It's a zero elo patch, and a reasonable safeguard against uncontrolled extreme reductions.

STC:
ELO: -0.08 +-2.0 (95%) LOS: 46.9%
Total: 40000 W: 6728 L: 6737 D: 26535

LTC:
ELO: -0.14 +-1.8 (95%) LOS: 44.0%
Total: 40000 W: 5557 L: 5573 D: 28870

Bench: 7201830

9 years agoChange history reduction in LMR to be a full ply.
Uri Blass [Thu, 25 Sep 2014 18:22:39 +0000 (02:22 +0800)]
Change history reduction in LMR to be a full ply.

STC:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 9829 W: 2142 L: 1998 D: 5689

LTC:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 27162 W: 4802 L: 4692 D: 17668

Bench: 7284120

Resolves #53