]> git.sesse.net Git - stockfish/log
stockfish
12 years agoMake init_magic() piece agnostic
Marco Costalba [Sun, 15 Jan 2012 07:24:50 +0000 (08:24 +0100)]
Make init_magic() piece agnostic

All the piece dependant data is passed now as
function arguments so that the code is exactly
the same for bishop and rook.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUnify some template specializations
Marco Costalba [Sat, 14 Jan 2012 22:01:09 +0000 (23:01 +0100)]
Unify some template specializations

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire queen_attacks_bb()
Marco Costalba [Sat, 14 Jan 2012 22:00:10 +0000 (23:00 +0100)]
Retire queen_attacks_bb()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse 'adjacent' instead of 'neighboring'
Marco Costalba [Sat, 14 Jan 2012 17:03:57 +0000 (18:03 +0100)]
Use 'adjacent' instead of 'neighboring'

It is more correct and specific. Another naming
improvement while reading Critter sources.

No functional changes.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRestore development version
Marco Costalba [Mon, 2 Jan 2012 17:23:05 +0000 (18:23 +0100)]
Restore development version

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStockfish 2.2.2
Marco Costalba [Thu, 29 Dec 2011 10:09:11 +0000 (11:09 +0100)]
Stockfish 2.2.2

Dedicated to the new Jim's super fast builds ! :-)

stockfish bench signature is: 5447426

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMove struct RootMove to Search namespace
Marco Costalba [Sat, 14 Jan 2012 12:49:25 +0000 (13:49 +0100)]
Move struct RootMove to Search namespace

And directly pass RootMoves instead of SearchMoves
to main thread. A class declaration is better suited
in a header and slims a bit the fatty search.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse a set to store SearchMoves
Marco Costalba [Sat, 14 Jan 2012 10:45:54 +0000 (11:45 +0100)]
Use a set to store SearchMoves

We just need to verify if a legal move is among the
SearchMoves, so we don't need a vector for this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix a gcc 4.7 warning
Marco Costalba [Fri, 13 Jan 2012 06:56:59 +0000 (07:56 +0100)]
Fix a gcc 4.7 warning

New gcc 4.7 complains about casting a volatile pointer
to void* so assign the variables directly.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoEnable easy move detection only for recaptures
Marco Costalba [Thu, 12 Jan 2012 20:26:25 +0000 (21:26 +0100)]
Enable easy move detection only for recaptures

It could lead to terrible mistakes otherwise, as
it happened during a game on playchess when on
this position (after white's f4):

2q4r/4b1k1/p3rpp1/3np2p/PpNpNP1P/1P1P2PQ/2P1R3/4R1K1 b - - 0 1

SF moves immediately e5xf4 instead of the correct f5.
In general during engine matches it is impossible the
opponent leaves a piece hanging or anyhow starts a
clear losing sequence. So avoid to fall in subtle traps.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse operator~ to flip colors and squares
Marco Costalba [Thu, 12 Jan 2012 18:31:18 +0000 (19:31 +0100)]
Use operator~ to flip colors and squares

More natural and nicer. Idea from Critter.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall touches in FEN decoding
Marco Costalba [Thu, 12 Jan 2012 17:12:25 +0000 (18:12 +0100)]
Small touches in FEN decoding

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire is_mate()
Marco Costalba [Tue, 10 Jan 2012 10:57:06 +0000 (11:57 +0100)]
Retire is_mate()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIntroduce piece_moved() to simplify common code
Marco Costalba [Mon, 9 Jan 2012 21:34:00 +0000 (22:34 +0100)]
Introduce piece_moved() to simplify common code

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUnify PseudoAttacks arrays
Marco Costalba [Mon, 9 Jan 2012 08:48:27 +0000 (09:48 +0100)]
Unify PseudoAttacks arrays

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse CheckInfo to generate checks
Marco Costalba [Sun, 8 Jan 2012 14:08:20 +0000 (15:08 +0100)]
Use CheckInfo to generate checks

It should help to avoid recalculating check squares
of sliding attackers for queen when already done for
bishops and rooks. Of course this helps when there are
bishop, rook and queen on the board !

Fixed also a subtle bug (use of same variable b in while
condition and in condition body) introduced recently by
revision d655147e8c that triggers
in case we have at least 2 non-pawn discovered check pieces.
This is very rare that's why didn't show in the node count
verification where we actually have a case of 2 dc pieces
in position 14, but one is a pawn.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdd castling to generation of checking moves
Marco Costalba [Sun, 8 Jan 2012 11:08:16 +0000 (12:08 +0100)]
Add castling to generation of checking moves

During generation of non-captures checks (in qsearch)
we don't consider castling moves that give check,
this patch includes also this rare case. Verified with
perft that all the non-capture checks are now generated.

There should be a very little slowdown due to the extra
work, but actually I failed to measure it. I don't expect
any ELO improvment, there is even no functional change on
the standard depth 12 search, it is just to have a correct
move generator.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoLast touches to movegen.cpp
Marco Costalba [Fri, 6 Jan 2012 11:37:33 +0000 (12:37 +0100)]
Last touches to movegen.cpp

The full movegen patch series shows a speed up of almost
6% (!) on perft, and code is much more readable too.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire the redundant MV_CHECK
Marco Costalba [Thu, 5 Jan 2012 09:50:51 +0000 (10:50 +0100)]
Retire the redundant MV_CHECK

MV_CHECK is an alias of the more appropiate named
MV_NON_CAPTURE_CHECK so use only the latter.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire generate_discovered_checks
Marco Costalba [Thu, 5 Jan 2012 08:27:50 +0000 (09:27 +0100)]
Retire generate_discovered_checks

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRearrange pawn moves generation
Marco Costalba [Wed, 4 Jan 2012 15:40:12 +0000 (16:40 +0100)]
Rearrange pawn moves generation

Functional change due only to rearrangement

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoReshuffle stuff in movegen.cpp
Marco Costalba [Wed, 4 Jan 2012 13:10:53 +0000 (14:10 +0100)]
Reshuffle stuff in movegen.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire OLD_LOCKS option
Marco Costalba [Sat, 7 Jan 2012 10:17:10 +0000 (11:17 +0100)]
Retire OLD_LOCKS option

And make CRITICAL_SECTION locks the only option for Windows.
This guarantees backward compatibility with all the Windows
versions (even XP and older) and an hassle free experience
when compiling for Windows. Tests performed by Ingo and
reported on talkchess confirm there is no speed penalty
against the most modern SRW locks:

http://www.talkchess.com/forum/viewtopic.php?t=41835&start=20

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix compile on HP-UX 11's HP's C++
Marco Costalba [Fri, 6 Jan 2012 23:04:08 +0000 (00:04 +0100)]
Fix compile on HP-UX 11's HP's C++

On that platform non-bracketed casting are not supported.

Reported by Richard Lloyd.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRestore development version
Marco Costalba [Mon, 2 Jan 2012 17:23:05 +0000 (18:23 +0100)]
Restore development version

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStockfish 2.2.1
Marco Costalba [Thu, 29 Dec 2011 10:09:11 +0000 (11:09 +0100)]
Stockfish 2.2.1

Hopefully fixed the "lose on time" issue.

stockfish bench signature is: 5457475

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoExtra time management safety
Marco Costalba [Fri, 6 Jan 2012 09:28:15 +0000 (10:28 +0100)]
Extra time management safety

Further increase safety against time losses. After this
change (tested on LittleBlitzer and cutechess) I had no
more time losses at 2" and 1"+0.02 TC both on Windows
and Linux on more than 10000 games.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoTry hard not to lose on time
Marco Costalba [Mon, 2 Jan 2012 22:40:14 +0000 (23:40 +0100)]
Try hard not to lose on time

We try hard not to lose on time even under extreme
time pressure. We achieve this through 3 different but
coordinated steps:

    1) Increase max frequency of timer events

    2) Quickly return after a stop signal

    3) Take in account timer resolution

With these SF played under LittleBlitzer at 1"+0.02 and 3"+0
without losing on time even one game.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAvoid a race at thread creation
Marco Costalba [Tue, 3 Jan 2012 20:13:29 +0000 (21:13 +0100)]
Avoid a race at thread creation

Before creating main thread we set its do_sleep flag to true,
then thread is created and it will go to sleep in main_loop()
after resetting do_sleep.

But if after the setting of do_sleep and before its resetting
the UI thread calls start_thinking() it will not wait on:

  if (!asyncMode)
      while (!main.do_sleep)
          cond_wait(&sleepCond, &main.sleepLock);

as it should but will immediately return before the main thread has
started the search. This very rare race show itself during bench,
when the first position is erroneusly skipped so that bench node count
results of 5309038 instead of the correct 5457475.

The patch is somewhat tricky, but is simple and it works!

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStreamline generation of MV_NON_EVASION
Marco Costalba [Tue, 3 Jan 2012 14:16:01 +0000 (15:16 +0100)]
Streamline generation of MV_NON_EVASION

Small speed-up of 3% in perft.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix a warning under gcc
Marco Costalba [Tue, 3 Jan 2012 07:56:29 +0000 (08:56 +0100)]
Fix a warning under gcc

Locals left and right shadow two same named
variables in the std::ifstream base class.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRevert cond_signal() fix
Marco Costalba [Mon, 2 Jan 2012 13:37:44 +0000 (14:37 +0100)]
Revert cond_signal() fix

It seems it yields to missing wake-up events with the
result of SF loosing on time as reported by many people.

So revert the patch and use a more robust approach: assume
there can be spurious wake ups events and make the code to
work also in those cases.

While debugging I found that WaitForSingleObject() had wrong
parameter 0 instead of INFINITE yielding to a crash while
exiting under Windows, strangely unnoticed til now.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBig renaming of move's helpers
Marco Costalba [Sun, 1 Jan 2012 15:00:00 +0000 (16:00 +0100)]
Big renaming of move's helpers

The aim is to have shorter names without losing
readibility but, if possible, increasing it.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify Book APIs
Marco Costalba [Sat, 31 Dec 2011 16:52:14 +0000 (17:52 +0100)]
Simplify Book APIs

Retire open(), close() and name() from public visibility
and greately simplify the code. It is amazing how much
can be squeezed out of an already mature code !

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRestore development version
Marco Costalba [Thu, 29 Dec 2011 10:49:49 +0000 (11:49 +0100)]
Restore development version

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStockfish 2.2
Marco Costalba [Thu, 29 Dec 2011 10:09:11 +0000 (11:09 +0100)]
Stockfish 2.2

stockfish bench signature is: 5457475

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix cond_signal() semantics when using OLD_LOCKS
Marco Costalba [Sat, 31 Dec 2011 14:27:14 +0000 (15:27 +0100)]
Fix cond_signal() semantics when using OLD_LOCKS

In Windows when OLD_LOCKS is defined we use SetEvent() to mimic
the semantic of the POSIX pthread_cond_signal().

Unfortunatly there is not a direct mapping because with SetEvent()
the state of an event object remains signaled until it is set
explicitly to the nonsignaled state or until a single waiting thread
has been released. Instead in case of pthread_cond_signal(), if there
are no waiting threads it has no effect. What we may want is something
like PulseEvent() instead of SetEvent(). Unfortunatly it is documented
by Mcrosoft as 'unreliable' due to spurious wakes up that could
filter out the signal resetting. So we opt to reset manually any
pending signaled state before to go to sleep.

This fixes the strange misbehaves during 'stockfish bench'
when using OLD_LOCKS under Windows.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUnify BitCountType selection
Marco Costalba [Sat, 31 Dec 2011 08:46:43 +0000 (09:46 +0100)]
Unify BitCountType selection

Now that HasPopCnt is a compile time constant we can
centralize and unify the BitCountType selection.

Also rename count_1s() in the more standard popcount()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix Windows 64 build
Marco Costalba [Fri, 30 Dec 2011 23:11:49 +0000 (00:11 +0100)]
Fix Windows 64 build

Broken by previous patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoReformat types.h
Marco Costalba [Fri, 30 Dec 2011 16:08:07 +0000 (17:08 +0100)]
Reformat types.h

Retire obsolete code and reshuffle stuff.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify debug functions
Marco Costalba [Fri, 30 Dec 2011 15:14:24 +0000 (16:14 +0100)]
Simplify debug functions

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAssorted cleanups in benchmark.cpp
Marco Costalba [Fri, 30 Dec 2011 13:40:35 +0000 (14:40 +0100)]
Assorted cleanups in benchmark.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire RootMove::nodes
Marco Costalba [Fri, 30 Dec 2011 13:16:15 +0000 (14:16 +0100)]
Retire RootMove::nodes

Was used for time management but is no more used
today.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUpdate copyright year to 2012
Marco Costalba [Fri, 30 Dec 2011 12:24:41 +0000 (13:24 +0100)]
Update copyright year to 2012

And refresh Readme.txt while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify printing of engine info
Marco Costalba [Fri, 30 Dec 2011 11:53:51 +0000 (12:53 +0100)]
Simplify printing of engine info

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire run-time detection of hardware POPCNT
Marco Costalba [Fri, 30 Dec 2011 10:30:26 +0000 (11:30 +0100)]
Retire run-time detection of hardware POPCNT

It was meant to build a single binary optimized
for any kind of CPU: with and without hardware POPCNT.

This is a nice idea but in practice was never used, or
people builds binary with popcnt enabled or not, mainly
according to their type of CPU. And it was also never
used in the official Jim's builds where, in case, would
be easier for a number of reasons, do build two different
versions: with and without SEE42 support.

So retire this feature and simplify the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix an off-by-one bug in ucioption.cpp
Marco Costalba [Thu, 29 Dec 2011 17:25:08 +0000 (18:25 +0100)]
Fix an off-by-one bug in ucioption.cpp

Harmless but anyhow wrong.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter use STL algorithms in Endgame functions
Marco Costalba [Thu, 29 Dec 2011 12:18:03 +0000 (13:18 +0100)]
Better use STL algorithms in Endgame functions

This leads to a further and unexpected simplification
of this already very size optimized code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoWait for main thread to finish before to exit
Marco Costalba [Thu, 29 Dec 2011 08:55:09 +0000 (09:55 +0100)]
Wait for main thread to finish before to exit

Currently after a 'quit' command UI thread raises stop
signal, exits from uci_loop() and calls Threads.exit()
while the search threads are still active.

In Threads.exit() main thread is asked to terminate, but
if it is parked in idle_loop() it will exit and free its
resources (in particular the shared Movepicker object) while
sibling slaves are still active and this leads to a crash.

The fix is to let the UI thread always wait for main thread
to finish the search before to return from uci_loop().

Found by Valgrind when running with 8 threads.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse for_each() in Endgames d'tor
Marco Costalba [Wed, 28 Dec 2011 23:13:49 +0000 (00:13 +0100)]
Use for_each() in Endgames d'tor

And fix some comments while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdd user-defined conversions to UCIOption
Marco Costalba [Wed, 28 Dec 2011 17:27:18 +0000 (18:27 +0100)]
Add user-defined conversions to UCIOption

Greatly improves the usage. User defined conversions
are a novelity for SF, another amazing C++ facility
at work !

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix score_to_uci()
Marco Costalba [Wed, 28 Dec 2011 13:18:56 +0000 (14:18 +0100)]
Fix score_to_uci()

The condition for a mate score was wrong:

abs(v) < VALUE_MATE - PLY_MAX * ONE_PLY

instead of

abs(v) < VALUE_MATE_IN_PLY_MAX

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter document how mate scores are stored in TT
Marco Costalba [Wed, 28 Dec 2011 12:22:09 +0000 (13:22 +0100)]
Better document how mate scores are stored in TT

During the search we score a mate as "plies to mate
from the root" to compare in an homogeneous way the
values returned by different sub-trees. However we
store in TT a mate score as "plies to mate from the
current position" the let the TT value remain valid
across the game.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire SquaresByColorBB[] and enum SquareColor
Marco Costalba [Wed, 28 Dec 2011 09:49:55 +0000 (10:49 +0100)]
Retire SquaresByColorBB[] and enum SquareColor

Use same_color_squares() instead.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRename Pieces
Marco Costalba [Tue, 27 Dec 2011 18:26:27 +0000 (19:26 +0100)]
Rename Pieces

Align with PieceType naming convention and
make them more readable.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDocument mate distance pruning
Marco Costalba [Tue, 27 Dec 2011 15:01:33 +0000 (16:01 +0100)]
Document mate distance pruning

It is simple but somewhat tricky code that deserves
a bit of documentation. A bit of renaming while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAssert enhancements in search
Marco Costalba [Tue, 27 Dec 2011 00:00:44 +0000 (01:00 +0100)]
Assert enhancements in search

Add the check that alpha < beta - 1 if and only if PvNode is true.
The current code would not flag PvNode and alpha == beta - 1. In
other words, the || is not an exclusive OR!.

Also sync assert conditions of search() and qsearch()

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoReformat UCI option code
Marco Costalba [Mon, 26 Dec 2011 15:21:13 +0000 (16:21 +0100)]
Reformat UCI option code

Make a better use of C++ operators overloading to
streamline the APIs.

Also sync polyglot.ini file while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRename getters functions removing 'get_' prefix
Marco Costalba [Sun, 25 Dec 2011 10:50:59 +0000 (11:50 +0100)]
Rename getters functions removing 'get_' prefix

Follow the suggested Qt style:

http://doc.qt.nokia.com/qq/qq13-apis.html

It seems to me simpler and easier to read.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRestore std::cout instead of printf()
Marco Costalba [Sun, 25 Dec 2011 08:04:28 +0000 (09:04 +0100)]
Restore std::cout instead of printf()

I am not able to reproduce the speed regression anymore,
and also we were using cout even before speed regression
so probably the reason is not there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoCorrectly define operators in types.h
Marco Costalba [Sat, 24 Dec 2011 08:55:35 +0000 (09:55 +0100)]
Correctly define operators in types.h

Be consistent with the way these operators are defined
in plain C (and in C++).

Spotted by Lucas Braesch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't update killers for evasions
Marco Costalba [Thu, 8 Dec 2011 16:54:37 +0000 (17:54 +0100)]
Don't update killers for evasions

We don't use killers to order evasions, so it
seems natural do not consider an evasion cut-off
move as a possible killer. Test shows almost no
change, as it should be becuase this is a really
tiny change, but neverthless seems the correct
thing to do.

After 11893 games
Mod vs Orig 1773 - 1696 - 8424 ELO +2 (+-3.4)

Idea from Critter.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse ADL to skip std:: qualifier
Marco Costalba [Sun, 18 Dec 2011 19:48:59 +0000 (20:48 +0100)]
Use ADL to skip std:: qualifier

Take advantage of argument-dependent lookup (ADL) to
avoid specifying std:: qualifier in some STL functions.
When a function argument refers to a namespace (in this
case std) then the compiler will search the unqualified
function in that namespace too.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDisable again buffering at startup
Marco Costalba [Sat, 17 Dec 2011 15:56:36 +0000 (16:56 +0100)]
Disable again buffering at startup

Partially revert efd21679980dfd59
Without this patch SF does not send "bestmove" to GUI.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoHeaders cleanup in ucioption.cpp
Marco Costalba [Sat, 17 Dec 2011 14:58:19 +0000 (15:58 +0100)]
Headers cleanup in ucioption.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse printf() instead of std::cout()
Marco Costalba [Sat, 17 Dec 2011 13:53:11 +0000 (14:53 +0100)]
Use printf() instead of std::cout()

Seems sensibly faster: On a

./stockfish bench > /dev/null

We have +2% on mingw and even +5% on MSVC !

Also removed the nice but complex enum set960 machinery,
use directly the underlying move_to_uci() function.

Speed regression reported by Heinz van Saanen.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire update_history() Inline the only caller site
Marco Costalba [Fri, 16 Dec 2011 09:23:25 +0000 (10:23 +0100)]
Retire update_history() Inline the only caller site

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix book move with searchmoves compatibility
Marco Costalba [Thu, 15 Dec 2011 06:25:45 +0000 (07:25 +0100)]
Fix book move with searchmoves compatibility

Do not return the book move if is not among the
RootMoves,in particular if we have been asked to
search on a move subset with "searchmoves" then
return book move only if it is among this subset.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify id_loop() signature
Marco Costalba [Wed, 14 Dec 2011 11:12:28 +0000 (12:12 +0100)]
Simplify id_loop() signature

And related assorted cleanup of this
very important function.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoReformat sending of PV information
Marco Costalba [Wed, 14 Dec 2011 08:21:00 +0000 (09:21 +0100)]
Reformat sending of PV information

Introduce pv_info_to_log() and pv_info_to_uci() and
greatly cleanup this stuff.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFurther simplify aspiration code
Marco Costalba [Wed, 14 Dec 2011 05:18:33 +0000 (06:18 +0100)]
Further simplify aspiration code

Actually after last patch it happens that delta
starts always with the fixed value of 16.

So further remove useless code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify aspiration window calculation
Marco Costalba [Wed, 7 Dec 2011 16:51:02 +0000 (17:51 +0100)]
Simplify aspiration window calculation

It seems that we just need to look at previous score to
compute aspiration window size.

After 5350 games:
Mod vs Orig 800 - 803  - 3647 ELO +0 (+- 5.2)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire RootMoveList
Marco Costalba [Mon, 12 Dec 2011 16:55:20 +0000 (17:55 +0100)]
Retire RootMoveList

Diretcly use the underlying std::vector<Move> and the
STL algorithms. Also a bit of cleanup while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix another crash triggered by previous patch
Marco Costalba [Sun, 11 Dec 2011 10:42:16 +0000 (11:42 +0100)]
Fix another crash triggered by previous patch

It is ok to redirect st pointer to startState, but the latter
should be updated with the content pointed by the st of the
original position. The bug is hidden when startState and *st
are the same as is the case of searching from start position,
but as soon as moves are made (as is the case when splitting)
the bug leads to a crash.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix a crash when quitting while searching
Marco Costalba [Sun, 11 Dec 2011 09:07:16 +0000 (10:07 +0100)]
Fix a crash when quitting while searching

The Position object used by UI thread is a local variable in
uci_loop(), so after receiving "quit" command the function
returns and the position is freed from the stack.

This should not be a problem becuase in start_thinking() we copy
the position to RootPosition that is the one used by main search
thread. Unfortunatly we blindly copy also StateInfo pointer that
still points to the startState struct inside UI position. So the
pointer becomes stale as soon as UI thread leaves uci_loop() and
because this happens while main search thread is still recovering
after the 'stop' signal we have a crash.

The fix is to update the pointer to the correct startState after
the copy.

Found with Valgrind.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoPrune silly comments in search()
Marco Costalba [Sat, 10 Dec 2011 18:14:13 +0000 (19:14 +0100)]
Prune silly comments in search()

Comments should be informative but not pedantic / obvious.
The only exception is the function description where we
indulge a bit on the "chatty" side, but has always been like
this since Glaurung times, so we continue with this tradition.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAllow to prune also first move
Marco Costalba [Thu, 8 Dec 2011 18:25:52 +0000 (19:25 +0100)]
Allow to prune also first move

Tested togheter with previous patch; shows no regression and
is a semplification.

After 5817 games:
Mod vs Orig 939 - 892 - 3986 ELO +2 (+- 5.1)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't update bestValue when pruning
Marco Costalba [Thu, 8 Dec 2011 18:12:17 +0000 (19:12 +0100)]
Don't update bestValue when pruning

Simply return a fail-low score

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix description of endgame scaling functions
Marco Costalba [Sat, 10 Dec 2011 09:14:25 +0000 (10:14 +0100)]
Fix description of endgame scaling functions

Triggered by a comment of Eelco on talkchess. Also
a bit of cleanup while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix compile for 64 bits
Marco Costalba [Thu, 8 Dec 2011 12:55:27 +0000 (13:55 +0100)]
Fix compile for 64 bits

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSet captureThreshold according to static evaluation
Marco Costalba [Thu, 8 Dec 2011 12:48:18 +0000 (13:48 +0100)]
Set captureThreshold according to static evaluation

Consider negative captures as good if
still enough to reach beta.

After 7502 games:
Mod vs Orig 1225 - 1158 - 5119 ELO +3 (+- 4.5)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove some (int) casts
Marco Costalba [Wed, 7 Dec 2011 07:21:25 +0000 (08:21 +0100)]
Remove some (int) casts

A cast rarely is the right solution. In this case was enough
to redifine 3 variables with type size_t instead of int

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire all extensions (but checks) for non-PV nodes
Marco Costalba [Wed, 7 Dec 2011 06:45:44 +0000 (07:45 +0100)]
Retire all extensions (but checks) for non-PV nodes

It seems we don't have any added value. Note that the
moves that were used to be extended are still flagged
as dangerous so to avoid at least pruning them.

After 9555 games
Mod vs Orig 1562 - 1540 - 6453 ELO +0 (+- 4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoPrefer empty() to size()
Marco Costalba [Tue, 6 Dec 2011 13:18:04 +0000 (14:18 +0100)]
Prefer empty() to size()

As Heinz says:

"Function empty() should have a constant run-time even
 on lousy compilers and you spare the not.

The change is even measurable: + 100-150 nodes/sec. Wow:-)"

Patch from Heinz van Saanen

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse operator() instead of apply() in endgames
Marco Costalba [Mon, 5 Dec 2011 19:58:23 +0000 (20:58 +0100)]
Use operator() instead of apply() in endgames

It is more idiomatic for a functor (a function object) as are
the endgames.

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix disambiguation bug in move_to_san()
Marco Costalba [Sun, 4 Dec 2011 11:24:15 +0000 (12:24 +0100)]
Fix disambiguation bug in move_to_san()

A pinned piece cannot move and so does not play any role
in SAN disambiguation.

Reported by Steven Edwards.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMove SearchStack under Search namespace
Marco Costalba [Sun, 4 Dec 2011 10:46:31 +0000 (11:46 +0100)]
Move SearchStack under Search namespace

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire move.h
Marco Costalba [Sun, 4 Dec 2011 09:53:40 +0000 (10:53 +0100)]
Retire move.h

Also some assorted comments fixes and other trivia.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoPrefer 0 to EmptyBoardBB
Marco Costalba [Sat, 3 Dec 2011 10:56:11 +0000 (11:56 +0100)]
Prefer 0 to EmptyBoardBB

Easier and even faster or at least easier to optimize.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire neighboring_files_bb() overload
Marco Costalba [Sat, 3 Dec 2011 10:43:07 +0000 (11:43 +0100)]
Retire neighboring_files_bb() overload

Rarely used and we prefer to not hide the complexity.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't disable IO buffering at startup
Marco Costalba [Sat, 3 Dec 2011 09:54:44 +0000 (10:54 +0100)]
Don't disable IO buffering at startup

It was never clear to me why we needed this trick, and now
that we rely only on C++ std::getline() and std::cout for
input / output it is even more a mistery what this code does.

So disable it and wait to see if someone screams ;-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoTidy up comments in uci.cpp
Marco Costalba [Sat, 3 Dec 2011 09:41:50 +0000 (10:41 +0100)]
Tidy up comments in uci.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoTidy up comments in thread.cpp
Marco Costalba [Mon, 28 Nov 2011 14:54:40 +0000 (15:54 +0100)]
Tidy up comments in thread.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoInclude <cstring> in search.h
Marco Costalba [Mon, 28 Nov 2011 06:30:31 +0000 (07:30 +0100)]
Include <cstring> in search.h

Now we use memset() directly there.

Spotted by Justin Blanchard.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoLittle reformat of elapsed_search_time()
Marco Costalba [Sun, 27 Nov 2011 21:36:13 +0000 (22:36 +0100)]
Little reformat of elapsed_search_time()

Change name and argument type.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDetach search arguments from UI thread
Marco Costalba [Sun, 27 Nov 2011 16:07:17 +0000 (17:07 +0100)]
Detach search arguments from UI thread

Detach from the UI thread the input arguments used by
the search threads so that the UI thread is able to receive
and process any command sent by the GUI while other threads
keep searching.

With this patch there is no more need to block the UI
thread after a "stop", so it is a more reliable and
robust solution than the previous patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAfter a "stop" do not read new input until search finishes
Marco Costalba [Sun, 27 Nov 2011 11:16:23 +0000 (12:16 +0100)]
After a "stop" do not read new input until search finishes

Unfortunatly xboard sends immediately the new position to
search after sending "stop" when we have a ponder miss.

Becuase main thread position is not copied but is referenced
directly from root position and the latter is modified by
the "position.." UCI command we end up with the working position
that changes under our feet while the search is still recovering
after the "stop" and this causes a crash.

This happens only with the (broken) xboard, native UCI does not
have this problem.

Reported by otello1984

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix a race in pondering mode
Marco Costalba [Sat, 26 Nov 2011 15:29:54 +0000 (16:29 +0100)]
Fix a race in pondering mode

Fixes an hang when playing with ponder ON. Perhaps there is still
a very small race but now it seems engine does not hang anymore.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIntroduce Search namespace
Marco Costalba [Sat, 26 Nov 2011 11:07:35 +0000 (12:07 +0100)]
Introduce Search namespace

Move global search-related variables under "Search" namespace.

As a side effect we can move uci_async_command() and
wait_for_stop_or_ponderhit() away from search.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRewrite async I/O
Marco Costalba [Wed, 23 Nov 2011 19:07:29 +0000 (20:07 +0100)]
Rewrite async I/O

Use the starting thread to wait for GUI input and instead use
the other threads to search. The consequence is that now think()
is alwasy started on a differnt thread than the caller that
returns immediately waiting for input. This reformat greatly
simplifies the code and is more in line with the common way
to implement this feature.

As a side effect now we don't need anymore Makefile tricks
with sleep() to allow profile builds.

No functional change.

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