]> git.sesse.net Git - stockfish/log
stockfish
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>
12 years agoReformat search dispatch code
Marco Costalba [Sat, 19 Nov 2011 12:55:26 +0000 (13:55 +0100)]
Reformat search dispatch code

Reduce indentation level and lines of code and tidy up
some comment.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix regression with printing of debug info
Marco Costalba [Sat, 19 Nov 2011 13:37:26 +0000 (14:37 +0100)]
Fix regression with printing of debug info

Output of debug info each second was disabled
due to recent patches.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't check for early stop when StopOnPonderhit is set
Marco Costalba [Sat, 19 Nov 2011 10:30:32 +0000 (11:30 +0100)]
Don't check for early stop when StopOnPonderhit is set

If we are pondering we will stop the search only when
GUI sends "ponderhit" or "stop" commands or when we reach
maximum depth. In all the other cases we continue to search
so there is no need to verify for available time.

Also better clarify why wait_for_stop_or_ponderhit() before
to exit in some cases.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoEarly stop: retire redundant Rml.size() == 1 case
Marco Costalba [Sat, 19 Nov 2011 10:19:12 +0000 (11:19 +0100)]
Early stop: retire redundant Rml.size() == 1 case

In case there is only 1 legal move we will stop the
search at depth 10 anyway because the exclusion search
probe will fail low.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRewrite early stop logic
Marco Costalba [Sat, 8 Oct 2011 12:01:18 +0000 (13:01 +0100)]
Rewrite early stop logic

In the "easy move" paradigm we verify if the best move has
ever changed over a good number of iterations and if the
biggest part of the searched nodes are consumed on it.
This is a kind of hacky ad indirect heuristic to deduce
if one move is much better than others.

Rewrite the early stop condition to verify directly if one
move is much better than others performing an exclusion
search.

Idea to use exclusion search for time management if form Critter.

After 12245 games at 30"+0.1
Mod vs Orig 1776 - 1775 - 8694 ELO +0 (+-3.4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoCLOP: Passed pawns weights tuning
Marco Costalba [Mon, 14 Nov 2011 08:02:01 +0000 (09:02 +0100)]
CLOP: Passed pawns weights tuning

Tuned with CLOP against a pool of 3 engines. Result
verified with a direct match:

After 11720 games at 10"+0.1
Mod vs Orig 1922 - 1832 - 7966 ELO +2 (+-3.6)

So no change in self match but if CLOP is right it should
be a bit better against an engine pool.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRename value in bestValue in id_loop()
Marco Costalba [Sun, 13 Nov 2011 09:54:30 +0000 (10:54 +0100)]
Rename value in bestValue in id_loop()

The value returned by root search it is actually
our best value, so rename the variable to reflect this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRewrite link time optimization in Makefile
Marco Costalba [Sat, 12 Nov 2011 09:10:01 +0000 (10:10 +0100)]
Rewrite link time optimization in Makefile

Instead of binding link time optimization to the choice of
popcount support, do the right thing and add -flto option
when gcc 4.5 or later is detected.

Although it should be supported also under mingw, it happens
that it doesn't, at least on my 4.6.1 due to some known bugs.

Thanks to Mike for helping me with this patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify passed pawns logic
Marco Costalba [Sat, 12 Nov 2011 08:03:18 +0000 (09:03 +0100)]
Simplify passed pawns logic

Remove the bonus for no *friendly* pieces in the pawn's path and
reduce a bit the bonus based on kings proximity.

This patch is part of to the ongoing effort to remove form evaluation
all the terms that do not add value.

After 16284 games:

Mod vs Orig 2728 - 2651 - 10911 ELO +1 (+- 3.1)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix regression: engine hangs while pondering
Marco Costalba [Thu, 10 Nov 2011 08:20:41 +0000 (09:20 +0100)]
Fix regression: engine hangs while pondering

After a "stop" due to a ponder miss Xboard sends
immediately the new position to search, without
waiting for engine to effectively stop the search.

It is not clear if this is a GUI bug (as I suspect)
or allowed behaviour, but because it won't be fixed
anyway workaround this issue making listener thread
to switch to in-sync mode as soon as a "stop" command
is received.

Thanks to Mike Whiteley for reporting this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStop is not an unknown command
Marco Costalba [Thu, 10 Nov 2011 08:10:44 +0000 (09:10 +0100)]
Stop is not an unknown command

If GUI sends stop while we are waiting for
a command do not reply with a silly:

Unknown command: stop

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAnother fix to profile-build on gcc 4.6
Marco Costalba [Wed, 9 Nov 2011 04:03:46 +0000 (05:03 +0100)]
Another fix to profile-build on gcc 4.6

Oliver reports profile builds error with new gcc 4.6, he says:

"We need to add -lgov with profile-generate AND profile-use.
So it has to be added to the second stage of building too.

The problem occurred first with the introduction of gcc4.6 and
I think this is because the previous version did find the gcov
library automatically. gcc4.6 needs more precise options and
does less guesses. I have seen it in debian, Ubuntu and also with
mingw on Windows. And all use gcc4.6."

This patch fixes the issue.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix profile-build
Marco Costalba [Tue, 8 Nov 2011 06:34:44 +0000 (07:34 +0100)]
Fix profile-build

After async I/O patches 'bench' changed behaviour and now waits for
input at the end of the test run. This is due to listener thread stay
blocked on std::getline() even after test run is finished, as soon as
we feed something the thread unblocks and then quickly exits.

This is not a big problem, but has the bad side effect of breaking
profile builds that hang forever at the end of the test run.

The tricky workaround is to create a pipe that connects to stockfish
input and then, when test run is finished, breaking the pipe: this
makes std::getline() immediately return.

So this patch adds a 'sleep 10' piped into 'stockfish bench' test run
command. After 10 seconds sleep ends, the pipe breaks and 'bench'
finishes as usual.

Thanks to Oliver Korff for reporting the issue, and to Mike Whiteley
for having co-authored this solution.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoReformat all_slaves_finished()
Marco Costalba [Sun, 6 Nov 2011 12:37:18 +0000 (13:37 +0100)]
Reformat all_slaves_finished()

Rename and move under ThreadsManager class.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter document and reshuffle stuff in think()
Marco Costalba [Sun, 6 Nov 2011 12:13:54 +0000 (13:13 +0100)]
Better document and reshuffle stuff in think()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter define wait_for_stop_or_ponderhit()
Marco Costalba [Sun, 6 Nov 2011 10:59:07 +0000 (11:59 +0100)]
Better define wait_for_stop_or_ponderhit()

Use do_uci_async_cmd() instead of process input commands
directly and clarify that what we are waiting for is
something that is able to raise StopRequest flag.

Also fix some stale comments in do_uci_async_cmd(). Here
we need to reset Limits.ponder only upon receiving "ponderhit".
In the case of "quit" or "stop" resetting Limits.ponder has no
effect because the search is going to be stopped anyway.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse a timer to avoid polling
Marco Costalba [Sat, 5 Nov 2011 10:19:21 +0000 (11:19 +0100)]
Use a timer to avoid polling

The timer will be fired asynchronously to handle
time management flags, while other threads are
searching.

This implementation uses a thread waiting on a
timed condition variable instead of real timers.
This approach allow to reduce platform dependant
code to a minimum and also is the most portable given
that timers libraries are very different among platforms
and also the best ones are not compatible with olds
Windows.

Also retire the now unused polling code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire now unused input_available()
Marco Costalba [Sat, 5 Nov 2011 07:37:48 +0000 (08:37 +0100)]
Retire now unused input_available()

With our new listener thread we don't need anymore
this ugly and platform dependent code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRewrite how commands from GUI are read
Marco Costalba [Sat, 5 Nov 2011 06:53:19 +0000 (07:53 +0100)]
Rewrite how commands from GUI are read

Instead of polling for input use a dedicated listener
thread to read commands from the GUI independently
from other threads.

To do this properly we have to delegate to the listener
all the reading from the GUI: while searching but also
while waiting for a command, like in std::getline().

So we have two possible behaviours: in-sync mode, in which
the thread mimics std::getline() and the caller blocks until
something is read from GUI, and async mode where the listener
continuously reads and processes GUI commands while other
threads are searching.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFurther touches to magic bitboards code
Marco Costalba [Tue, 1 Nov 2011 08:07:23 +0000 (09:07 +0100)]
Further touches to magic bitboards code

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix compile error in cpu_count()
Marco Costalba [Mon, 31 Oct 2011 19:03:30 +0000 (20:03 +0100)]
Fix compile error in cpu_count()

The std::min() template function requires both arguments
to be of the same type.

But here we have the integer MAX_THREADS compared to a long:

long sysconf(int name);

So cast to integer and fix the compile.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDocument magics bitboards code
Marco Costalba [Mon, 31 Oct 2011 14:37:46 +0000 (15:37 +0100)]
Document magics bitboards code

Add comments and rename stuff to better clarify what the
magic bitboard initialization code does.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMerge pull request #1 from Panthee/master
mcostalba [Mon, 31 Oct 2011 12:32:18 +0000 (05:32 -0700)]
Merge pull request #1 from Panthee/master

Code Cleanup - Replacing macros Min() and Max() with corresponding STL algorithms std::min() and std::max()

12 years agoRetire update_gains()
Alexander Kure [Mon, 31 Oct 2011 07:28:59 +0000 (03:28 -0400)]
Retire update_gains()

12 years agoReplaced macros Min() and Max() with corresponding STL algorithms std::min() and...
Alexander Kure [Mon, 31 Oct 2011 04:38:44 +0000 (00:38 -0400)]
Replaced macros Min() and Max() with corresponding STL algorithms std::min() and std::max()

12 years agoRetire update_gains()
Marco Costalba [Sun, 30 Oct 2011 21:52:59 +0000 (22:52 +0100)]
Retire update_gains()

Called from one place only.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix small bug in move_attacks_square()
Marco Costalba [Sun, 30 Oct 2011 17:59:12 +0000 (18:59 +0100)]
Fix small bug in move_attacks_square()

We test if the piece moved in 'to' attacks the square 's' with:

bit_is_set(attacks_from(piece, to), s))

But we should instead consider the new occupancy, changed after
the piece is moved, and so test with:

bit_is_set(attacks_from(piece, to, occ), s))

Otherwise we can miss some cases, for instance a queen in b1 that
moves in c1 is not detected to attack a1 while instead she does.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoInline pinned_pieces() and discovered_check_candidates()
Marco Costalba [Sun, 30 Oct 2011 17:16:28 +0000 (18:16 +0100)]
Inline pinned_pieces() and discovered_check_candidates()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoCode style and 80 chars cols in Position::from_fen()
Marco Costalba [Sun, 30 Oct 2011 14:46:00 +0000 (15:46 +0100)]
Code style and 80 chars cols in Position::from_fen()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSync do_move() and undo_move()
Marco Costalba [Sun, 30 Oct 2011 10:26:06 +0000 (11:26 +0100)]
Sync do_move() and undo_move()

It is not possible to unify due to the fact that the
sequence steps are reversed. What we can do is to try
to sync comments and code as much as we can to easy
reading and documentation.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoExplicitly use a dedicated bitboard for occupied squares
Marco Costalba [Sun, 30 Oct 2011 10:11:45 +0000 (11:11 +0100)]
Explicitly use a dedicated bitboard for occupied squares

Instead of byTypeBB[0]. This better self-documents the code.

No functional and speed change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire do_capture_move()
Marco Costalba [Sun, 30 Oct 2011 09:57:00 +0000 (10:57 +0100)]
Retire do_capture_move()

It is called only in do_move() that now has been fully
expanded. This is the most time consuming function of
all the engine.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire undo_null_move()
Marco Costalba [Sat, 29 Oct 2011 16:49:20 +0000 (17:49 +0100)]
Retire undo_null_move()

Use a templetized do_null_move() to do/undo the null move.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire undo_castle_move()
Marco Costalba [Sat, 29 Oct 2011 15:49:59 +0000 (16:49 +0100)]
Retire undo_castle_move()

Use a templetized do_castle_move() to do/undo the castling.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire Position::set_castling_rights()
Marco Costalba [Sat, 29 Oct 2011 11:23:54 +0000 (12:23 +0100)]
Retire Position::set_castling_rights()

Is called in just one place. And rename set_castle() in the
now free to use and more appropiate set_castle_right().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire PieceValueXXX[] getters
Marco Costalba [Sat, 22 Oct 2011 14:52:53 +0000 (15:52 +0100)]
Retire PieceValueXXX[] getters

They don't add any value given that the corresponding
table has global visibility anyhow.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify the promotion case of move_gives_check()
Marco Costalba [Sat, 22 Oct 2011 13:53:35 +0000 (14:53 +0100)]
Simplify the promotion case of move_gives_check()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove redundancy in definitions of attack helpers
Marco Costalba [Sat, 22 Oct 2011 13:21:57 +0000 (14:21 +0100)]
Remove redundancy in definitions of attack helpers

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert PST tables to relative values
Marco Costalba [Fri, 21 Oct 2011 05:45:20 +0000 (06:45 +0100)]
Convert PST tables to relative values

This is a prerequisite to allow changing piece values
at runtime, needed for tuning.

Also use scores instead of separated midgame and endgame values.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIncrease Mobility
Marco Costalba [Thu, 20 Oct 2011 06:06:05 +0000 (07:06 +0100)]
Increase Mobility

First tuning with CLOP against a pool of 3 engines. Result
verified with a direct match:

After 8736 games at 10"+0.1
Mod vs Orig 1470 - 1496 - 5770 ELO -1 (+-4.3)

So no change in self match but if CLOP is right it should
be a bit better against an engine pool.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter document mate and stalemate detection
Marco Costalba [Tue, 18 Oct 2011 10:24:47 +0000 (12:24 +0200)]
Better document mate and stalemate detection

In particular add that we can have an harmless false positive
in case StopRequest or thread.cutoff_occurred() are set.

Reported by David Lee.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse newly added log facility instead of LogFile
Marco Costalba [Mon, 17 Oct 2011 19:41:27 +0000 (20:41 +0100)]
Use newly added log facility instead of LogFile

As a side effect now log file is open and closed every
time it is used instead of remaining open for the whole
thinking time.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdd basic log facility
Marco Costalba [Mon, 17 Oct 2011 16:49:28 +0000 (18:49 +0200)]
Add basic log facility

Mainly used to log stuff to a file while playing, when
stdout is used for the comunication with the GUI.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix compile error in debug mode
Marco Costalba [Sun, 16 Oct 2011 22:56:25 +0000 (23:56 +0100)]
Fix compile error in debug mode

Build broken by commit 3141490374182551ed2
where we renamed move_is_ok() in is_ok() and this clashes
with the same named method in Position that overrides the
move's one causing compile errors.

The fix is to rename the method in Position.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoLink Time Optimization doesn't needs -static
Marco Costalba [Sun, 9 Oct 2011 07:22:13 +0000 (08:22 +0100)]
Link Time Optimization doesn't needs -static

Justin reports that it breaks the compilation on Fedore 15 and as Tom says:

-static is only needed to work around the gcc on ubuntu 11.10 beta bug.
If -static introduces issues on its own then it is better to remove it.
It will not be needed in most environments.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter document how MultiPV search works
Marco Costalba [Sat, 8 Oct 2011 09:51:39 +0000 (10:51 +0100)]
Better document how MultiPV search works

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSend again all the PV lines in multiPV searching
Marco Costalba [Sat, 8 Oct 2011 08:25:38 +0000 (09:25 +0100)]
Send again all the PV lines in multiPV searching

Partially revert 1036cadcecc43737 because UCI protocol
in case of multipv explicitly requires:

for the best move/pv add "multipv 1" in the string when you send the pv.
in k-best mode always send all k variants in k strings together.

Thanks to Justin Blanchard for pointing this out.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdded gcc -msse3 support
Marco Costalba [Sat, 8 Oct 2011 07:17:37 +0000 (08:17 +0100)]
Added gcc -msse3 support

It is enabled when selecting x86-64-modern target, this gives
another nice speed up:

On a Core i5-2500 (3300 Mhz, Sandy Bridge):

64 bit download version: 1597151 n/s

-flto : 1659664 n/s

-flto -msse3: 1732344 n/s

Patch suggested by Tom Vijlbrief.

Also unify flto, popcount and msse3 optimization under "modern"
target, note that this can break the "modern" build on old gcc that
do not support -flto option: in this case update gcc ;-) or default
to the standard build.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdded gcc lto (Link Time Optimization) option
Tom Vijlbrief [Thu, 6 Oct 2011 16:25:36 +0000 (18:25 +0200)]
Added gcc lto (Link Time Optimization) option

Just by adding the -flto option to CXXFLAGS link command
we can gain a few percent in speed.

On a Core i5-2500 (3300 Mhz, Sandy Bridge):

64 bit download version:

Without -flto: 1597151 n/s
With -flto : 1659664 n/s

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoShrink names of move helpers
Marco Costalba [Mon, 3 Oct 2011 08:56:49 +0000 (09:56 +0100)]
Shrink names of move helpers

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall touches in position.h
Marco Costalba [Mon, 3 Oct 2011 08:23:04 +0000 (09:23 +0100)]
Small touches in position.h

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall touches to book.cpp
Marco Costalba [Mon, 3 Oct 2011 07:02:46 +0000 (08:02 +0100)]
Small touches to book.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter naming borrowed from Critter
Marco Costalba [Sun, 2 Oct 2011 07:33:40 +0000 (08:33 +0100)]
Better naming borrowed from Critter

In line with http://chessprogramming.wikispaces.com conventions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRevert "Retire Rml full PV search at depth == 1"
Marco Costalba [Sat, 1 Oct 2011 22:39:39 +0000 (23:39 +0100)]
Revert "Retire Rml full PV search at depth == 1"

Yet another random crash source !

Hopefully this is the last one.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRename kingZone[] and reverse the king's color
Marco Costalba [Sat, 1 Oct 2011 09:47:43 +0000 (10:47 +0100)]
Rename kingZone[] and reverse the king's color

Seems easier to understand to me. From Critter.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDocument why Book is defined static
Marco Costalba [Sat, 1 Oct 2011 05:35:24 +0000 (06:35 +0100)]
Document why Book is defined static

This was not clear to someone on talkchess and actually
is not trivial to understand.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoWhen exiting wake up all threads at once
Marco Costalba [Mon, 26 Sep 2011 05:07:11 +0000 (06:07 +0100)]
When exiting wake up all threads at once

It seems we have a very rare crash under Linux, once
every 10K games without this patch.

Is faster to wake up all the threads, especially on SMP,
where the threads can then exit in parallel while the main
thread is waiting for the next one to terminate.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoNo need to test for MOVE_NONE before move_is_ok()
Marco Costalba [Sun, 25 Sep 2011 15:28:38 +0000 (16:28 +0100)]
No need to test for MOVE_NONE before move_is_ok()

Function move_is_ok() already catches the move == MOVE_NONE case.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUpdate killers after a TT hit
Marco Costalba [Sun, 18 Sep 2011 18:50:42 +0000 (19:50 +0100)]
Update killers after a TT hit

Almost no increase but seems the logic thing to do.

After 16707 games 2771 - 2595 - 11341 ELO +3 (+- 3.2)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoCorrectly score capture underpromotions
Marco Costalba [Sat, 17 Sep 2011 15:41:01 +0000 (16:41 +0100)]
Correctly score capture underpromotions

Be sure a queen capture promotion is tried in front of
an underpromotion.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't lock before check for termination
Marco Costalba [Wed, 14 Sep 2011 05:16:46 +0000 (06:16 +0100)]
Don't lock before check for termination

Restore old locking scheme changed with
commit 1e92df6b20aa2240.

This seems to prevent a very rare crash that occurs
once every 5-10K games.

With this patch we have no crashes after 33K games.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse the map type template parameter to access map()
Marco Costalba [Sun, 11 Sep 2011 09:45:59 +0000 (10:45 +0100)]
Use the map type template parameter to access map()

It is more natural than using the family subtype and also
use two single maps instead of a std::pair.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoLookup square distance instead of calculate on the fly
Marco Costalba [Sun, 11 Sep 2011 09:00:52 +0000 (10:00 +0100)]
Lookup square distance instead of calculate on the fly

Microptimization that gives a +0.7% speed increase.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDetect family type of endgame from its enum value
Marco Costalba [Sun, 21 Aug 2011 19:11:37 +0000 (20:11 +0100)]
Detect family type of endgame from its enum value

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIndulge a bit on the template wizardy
Marco Costalba [Sun, 14 Aug 2011 11:36:34 +0000 (12:36 +0100)]
Indulge a bit on the template wizardy

Push the template pedal a bit in our "showoff" endgame code ;-)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall simplification of endgame functions API
Marco Costalba [Sun, 14 Aug 2011 10:52:27 +0000 (11:52 +0100)]
Small simplification of endgame functions API

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix use of uninitialized variable
Marco Costalba [Fri, 12 Aug 2011 09:42:08 +0000 (11:42 +0200)]
Fix use of uninitialized variable

When initializing endgames map we build a faked FEN string
in mat_key() to get the position hash's key.

This fen string lacks full move numbers, so when parsing the
fen in Position::from_fen() we leave startPosPly un-initialized.

Spotted by Valgrind (this is a kind of bug that is almost impossible
for humans to find).

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix silly icc remark #2259
Marco Costalba [Fri, 12 Aug 2011 08:53:32 +0000 (10:53 +0200)]
Fix silly icc remark #2259

Another stupid remark to quiet out:

remark #2259: non-pointer conversion from "int" to "UINT16={unsigned short}"
may lose significant bits

In this case icc always converts to an integer the result of a shift operation
if the bit size of the operand is smaller, hence the warning when assignin
back to n.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse a boolean instead as thread's state
Marco Costalba [Wed, 10 Aug 2011 11:12:10 +0000 (12:12 +0100)]
Use a boolean instead as thread's state

Now that we have just two mutually exclusive thread's states
we can repleace them by a simple boolean.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove Thread::WORKISWAITING
Marco Costalba [Wed, 10 Aug 2011 11:05:33 +0000 (12:05 +0100)]
Remove Thread::WORKISWAITING

Set the state directly to Thread::SEARCHING

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't need pthread_detach() after pthread_join()
Marco Costalba [Tue, 9 Aug 2011 20:08:55 +0000 (21:08 +0100)]
Don't need pthread_detach() after pthread_join()

Spotted by Joona and verified with Valgrind.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoChange start_routine argument
Marco Costalba [Tue, 9 Aug 2011 13:19:44 +0000 (14:19 +0100)]
Change start_routine argument

Directly pass the thread pointer.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire Rml full PV search at depth == 1
Marco Costalba [Thu, 4 Aug 2011 13:14:56 +0000 (14:14 +0100)]
Retire Rml full PV search at depth == 1

Now that Rml ordering is based on normal MovePicker logic,
apart for the ttMove that is given, we can avoid to score
all the root moves at depth 1. We only need it for easy move
detection logic, but in this case we just need to score the
first two best moves and not all the Rml set.

No regression after 6400 games
Mod vs Orig 1052 1012 4336 ELO +2 (+- 4.9)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire ThreadsManager::init_hash_tables()
Marco Costalba [Mon, 8 Aug 2011 22:07:09 +0000 (23:07 +0100)]
Retire ThreadsManager::init_hash_tables()

Allocation of pawn and material hash tables should
be strictly bounded to the change of the number of
activeThreads, so move the code inside set_size().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire Thread::TERMINATED
Marco Costalba [Mon, 8 Aug 2011 20:25:37 +0000 (21:25 +0100)]
Retire Thread::TERMINATED

Use proper way to detect for thread terimnation instead of
our homegrown flag.

It adds more code than it removes and adds also platform specific
code, neverthless I think is the way to go becuase Thread::TERMINATED
flag is intrinsecly racy given that when we raise it thread is still
_not_ terminated nor it can be, and also we don't want to reinvent
the (broken) wheel of thread termination detection when there is
already available the proper one.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire Thread::INITIALIZING
Marco Costalba [Mon, 8 Aug 2011 12:41:58 +0000 (13:41 +0100)]
Retire Thread::INITIALIZING

Was used to prevent issues when creating multiple threads
on Windows, but now it seems we can remove it safely.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMove idle_loop() under Thread
Marco Costalba [Mon, 8 Aug 2011 11:03:16 +0000 (12:03 +0100)]
Move idle_loop() under Thread

This greatly removes clutter from the difficult idle_loop() function

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoTidy up comments in thread.cpp
Marco Costalba [Mon, 8 Aug 2011 09:53:52 +0000 (10:53 +0100)]
Tidy up comments in thread.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire broken SendSearchedNodes
Marco Costalba [Mon, 8 Aug 2011 09:08:41 +0000 (10:08 +0100)]
Retire broken SendSearchedNodes

Now that we can split at root it happens that SendSearchedNodes
works only once at the end of the iteration, but this is useless
becuase speed info is sent anyhow toghter with the pv line.

So retire for now, waiting to find something SMP compatible.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSync search() and qsearch() alpha update
Marco Costalba [Sun, 7 Aug 2011 09:29:47 +0000 (10:29 +0100)]
Sync search() and qsearch() alpha update

Change qsearch() to reflect alpha update logic
of search().

To be consistent changed also moves loop condition and
futility pruning condition.

No regression after 5072 games at TC 10"+0.1

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire Thread::BOOKED
Marco Costalba [Sun, 7 Aug 2011 18:56:53 +0000 (19:56 +0100)]
Retire Thread::BOOKED

Start a slave as soon as is allocated.

No functional change with faked split.

Regression tested the full split() series and after
2000 games no regression and no crash.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix obey the "maxThreadsPerSplitPoint" setting
Marco Costalba [Sun, 7 Aug 2011 14:15:19 +0000 (15:15 +0100)]
Fix obey the "maxThreadsPerSplitPoint" setting

Spotted by Joona.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDo not modify alpha in split()
Marco Costalba [Sun, 7 Aug 2011 08:24:40 +0000 (09:24 +0100)]
Do not modify alpha in split()

When calling split or we immediately return because unable to
find available slaves, or we start searching on _all_ the moves
of the node or until a cut-off occurs, so that when returning
from split we immediately leave the moves loop.

Because of this we don't need to change alpha inside split() and
we can use a signature similar to search() so to better clarify
that split() is actually a search on the remaining node's moves.

No functional change with faked split.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoInitialize a new split point out of lock
Marco Costalba [Sat, 6 Aug 2011 18:11:35 +0000 (19:11 +0100)]
Initialize a new split point out of lock

Allocate and initialize a new split point
out of lock becuase modified data is local to
master thread only.

Also better document why we need a lock at
the end of split().

No functional change with faked split.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUpdate comment on why we call root search with ss+1
Marco Costalba [Sat, 6 Aug 2011 10:19:13 +0000 (11:19 +0100)]
Update comment on why we call root search with ss+1

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix an assert when stopping the search
Marco Costalba [Sat, 6 Aug 2011 09:56:06 +0000 (10:56 +0100)]
Fix an assert when stopping the search

When StopRequest is raised we cannot immediately exit the
move loop but first we need to update bestValue so to avoid
assert:

assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSplit at root!
Joona Kiiski [Sat, 6 Aug 2011 08:43:46 +0000 (09:43 +0100)]
Split at root!

Another great success by Joona !

After 5876 games at 10"+0.1
Mod vs Orig: 1073 - 849 - 3954 ELO +13 (+- 5.2)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoPreparations for splitting at root
Joona Kiiski [Sat, 6 Aug 2011 08:15:46 +0000 (09:15 +0100)]
Preparations for splitting at root

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimplify MovePickerExt<>
Marco Costalba [Fri, 5 Aug 2011 06:23:54 +0000 (07:23 +0100)]
Simplify MovePickerExt<>

Now that we don't special case the root moves anymore
we don't need to pass NodeType anymore as template parameter,
a simple bool to detect a SpNode will be enough.

Spotted by Joona.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix silly bug in uci loop
Marco Costalba [Fri, 5 Aug 2011 06:15:45 +0000 (07:15 +0100)]
Fix silly bug in uci loop

After issuing "go"-command, at the end of the search
SF shows: "Unknown command: ...".

Spotted by Joona.

No functional change.

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