]> git.sesse.net Git - stockfish/log
stockfish
11 years agoFix crash under Chess 960
Marco Costalba [Sun, 16 Sep 2012 12:06:13 +0000 (14:06 +0200)]
Fix crash under Chess 960

We have a crash with this position:

rkqbnnbr/pppppppp/8/8/8/8/PPPPPPPP/RKQBNNBR w HAha -

What happens is that even if we are castling QUEEN_SIDE,
in this case we have kfrom (B8) < kto (C8) so the loop
that checks for attackers runs forever leading to a crash.

The fix is to check for (kto > kfrom) instead of
Side == KING_SIDE, but this is slower in the normal case of
ortodhox chess, so rewrite generate_castle() to handle the
chess960 case as a template parameter and allow the compiler
to optimize out the comparison in case of normal chess.

Reported by Ray Banks.

11 years agoRename class Book to PolyglotBook
Marco Costalba [Sun, 16 Sep 2012 08:30:32 +0000 (10:30 +0200)]
Rename class Book to PolyglotBook

And move struct BookEntry out of the header where it is
not needed.

No functional change.

11 years agoFix KpsK endgame
Marco Costalba [Sun, 16 Sep 2012 06:52:38 +0000 (08:52 +0200)]
Fix KpsK endgame

Broken by commit a44c5cf4f77b05a03 of 3 /12 / 2011 that
was labeled "No functional change" because our 'bench'
test didn't triggered that particular endgame. Indeed
we need to run a specific bench on a set of endgames
position when touching endgame.cpp because normal bench
does not cover endgames properly.

Found by MSVC 2012 code analyzer.

11 years agoRestore development version
Marco Costalba [Sat, 15 Sep 2012 07:34:31 +0000 (09:34 +0200)]
Restore development version

No functional change.

11 years agoStockfish 2.3
Marco Costalba [Sat, 30 Jun 2012 07:00:48 +0000 (08:00 +0100)]
Stockfish 2.3

Stockfish bench signature is: 5416292

11 years agoFix compile with Intel 13.0
Marco Costalba [Sat, 15 Sep 2012 08:50:23 +0000 (10:50 +0200)]
Fix compile with Intel 13.0

It seems Intel is unable to properly workout templates with 'static'
storage specifier.

Workaround using an anonymous namespace instead.

No functional change.

11 years agoDon't exit earlier from aspiration window loop
Marco Costalba [Mon, 10 Sep 2012 16:24:53 +0000 (18:24 +0200)]
Don't exit earlier from aspiration window loop

Currently we exit the loop when

abs(bestValue) >= VALUE_KNOWN_WIN

but there is no logical reason for this. It seems more
natural to re-search again with full open window.

This has practically no impact in most cases, we have a
'no functional change' running 'bench' command.

11 years agoFix MSVC 2012 64bits warnings
Marco Costalba [Fri, 14 Sep 2012 07:42:59 +0000 (09:42 +0200)]
Fix MSVC 2012 64bits warnings

Reported by Rein.

No functional change.

11 years agoSpeed-up generate<LEGAL>
Marco Costalba [Tue, 11 Sep 2012 18:00:58 +0000 (20:00 +0200)]
Speed-up generate<LEGAL>

The trick here is to check for legality only in the
(rare) cases we have pinned pieces or a king move
or an en-passant.

This trick is able to increase the speed of perft
of more then 20%!

No functional change.

11 years agoRemove redundancy in move generation
Marco Costalba [Sun, 9 Sep 2012 12:30:22 +0000 (14:30 +0200)]
Remove redundancy in move generation

Introduce generate_all_moves() and remove a good
bunch of redundant code.

No functional change.

11 years agoSimplify generate_castle()
Marco Costalba [Sun, 9 Sep 2012 08:49:25 +0000 (10:49 +0200)]
Simplify generate_castle()

Skipping the calls to std::min(), std::man() we get
even a nice speed-up on perft.

No functional change.

11 years agoRename *last to *end
Marco Costalba [Sun, 9 Sep 2012 08:17:31 +0000 (10:17 +0200)]
Rename *last to *end

It is a more correct name because it points past the
last move of the list.

No functional change.

11 years agoEnable link time optimization only when optimizing
Marco Costalba [Sun, 9 Sep 2012 08:02:11 +0000 (10:02 +0200)]
Enable link time optimization only when optimizing

Because it is quite slow, skip it when 'optimize' flag is 'no'

No functional change.

11 years agoRevert "Simplify Option c'tor"
Marco Costalba [Fri, 7 Sep 2012 13:21:50 +0000 (15:21 +0200)]
Revert "Simplify Option c'tor"

std::to_string() is C++11 material, not c++03.

So revert the patch.

11 years agoSimplify Option c'tor
Marco Costalba [Thu, 6 Sep 2012 16:16:37 +0000 (18:16 +0200)]
Simplify Option c'tor

No functional change.

11 years agoGet rid of struct Time
Marco Costalba [Tue, 4 Sep 2012 07:38:51 +0000 (09:38 +0200)]
Get rid of struct Time

We just need the milliseconds of current system
time for our needs. This allows to simplify the
API.

No functional change.

11 years agoRename current_time() to now()
Marco Costalba [Sun, 2 Sep 2012 14:39:01 +0000 (16:39 +0200)]
Rename current_time() to now()

Follow C++11 naming conventions.

No functional change.

11 years agoGreatly speed up SEE
Marco Costalba [Sat, 1 Sep 2012 22:15:27 +0000 (00:15 +0200)]
Greatly speed up SEE

Simply reshuffling the code inverting the condition in next_attacker()
yields a miraculous speed up of more than 3% under gcc!

On my laptop a bench run goes from 320Knps to 330Knps

No functional change.

11 years agoUnroll least valuable attacker loop in SEE
Marco Costalba [Sat, 1 Sep 2012 09:45:14 +0000 (11:45 +0200)]
Unroll least valuable attacker loop in SEE

This allows to reduce the scanning for new X-ray attacks
according to the capturing piece type.

It seems to be just a very small speed increase in MSVC 64
bit and gcc 32 bit, I guess cache issues value more than some
instruction less to execute (as usual).

No functional change.

11 years agoSlightly simplify SEE
Marco Costalba [Sat, 1 Sep 2012 09:45:14 +0000 (11:45 +0200)]
Slightly simplify SEE

Some renaming and small code reshuffle.

No fuctional change.

11 years agoRetire Time::restart()
Marco Costalba [Fri, 31 Aug 2012 13:19:35 +0000 (15:19 +0200)]
Retire Time::restart()

Simplify API.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoDon't need to memset HashTable
Marco Costalba [Fri, 31 Aug 2012 12:21:16 +0000 (14:21 +0200)]
Don't need to memset HashTable

Default c'tor Entry() already initializes
to zero all its POD members.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoTerminate threads before to exit main()
Marco Costalba [Wed, 29 Aug 2012 14:43:01 +0000 (16:43 +0200)]
Terminate threads before to exit main()

It is very difficult and risky to assure
that a running thread doesn't access a global
variable. This is currently true, but could
change in the future and we don't want to rely
on code that works 'by accident'. The threads
are still running when ThreadPool destructor is
called (after main() returns) and this could
lead to crashes if a thread accesses a global
that has been already freed. The solution is to
use an exit() function and call it while we are
still in main(), ensuring global variables are
still alive at threads termination time.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoConvert to sync_cout and sync_endl
Marco Costalba [Wed, 29 Aug 2012 11:28:59 +0000 (13:28 +0200)]
Convert to sync_cout and sync_endl

Serialize access to std::cout all over the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoIntroduce serialization of accesses to std::cout
Marco Costalba [Wed, 29 Aug 2012 09:25:11 +0000 (11:25 +0200)]
Introduce serialization of accesses to std::cout

When many threds concurrently print you need to serialize
the access to std::cout to avoid output lines are intermixed
with the contents of each thread.

This is not strictly needed at the moment because
only main thread prints out, although some ad-hoc
test could trigger UCI::loop() printing while searching.

Anyhow we want to lift this pretty avoidable constrain
also as a prerequisite for future work.

This patch just introduces the support, next one will enable
the serialization.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoCorrectly handle handover of setup states
Marco Costalba [Mon, 27 Aug 2012 12:39:59 +0000 (14:39 +0200)]
Correctly handle handover of setup states

Before the search we setup the starting position doing all the
moves (sent by GUI) from start position to the position just
before to start searching.

To do this we use a set of StateInfo records used by each
do_move() call. These records shall be kept valid during all
the search because repetition draw detection uses them to back
track all the earlier positions keys. The problem is that, while
searching, the GUI could send another 'position' command, this
calls set_position() that clears the states! Of course a crash
follows shortly.

Before searching all the relevant parameters are copied in
start_searching() just for this reason: to fully detach data
accessed during the search from the UCI protocol handling.
So the natural solution would be to copy also the setup states.
Unfortunatly this approach does not work because StateInfo
contains a pointer to the previous record, so naively copying and
then freeing the original memory leads to a crash.

That's why we use two std::auto_ptr (one belonging to UCI and another
to Search) to safely transfer ownership of the StateInfo records to
the search, after we have setup the root position.

As a nice side-effect all the possible memory leaks are magically
sorted out for us by std::auto_ptr semantic.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoUse std::deque to store setup states
Marco Costalba [Sun, 26 Aug 2012 16:07:54 +0000 (18:07 +0200)]
Use std::deque to store setup states

11 years agoDocument PolyGlotRandoms[] offsets
Marco Costalba [Sat, 25 Aug 2012 17:48:08 +0000 (18:48 +0100)]
Document PolyGlotRandoms[] offsets

Should be more clear from where the 'magic' numbers
come from.

Also bit of reformat while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoExplicitly use threads.size()
Marco Costalba [Fri, 24 Aug 2012 11:40:58 +0000 (12:40 +0100)]
Explicitly use threads.size()

Instead of just size(). Although code is longer,
should be more immediate to understand when reading.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoIntroduce struct Mutex and ConditionVariable
Marco Costalba [Fri, 24 Aug 2012 09:59:41 +0000 (10:59 +0100)]
Introduce struct Mutex and ConditionVariable

To mimics C++11 std::mutex and std::condition_variable,
also rename locks and condition variables to be more
uniform across the classes.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoSlightly microptimize SEE
Marco Costalba [Fri, 24 Aug 2012 08:30:50 +0000 (09:30 +0100)]
Slightly microptimize SEE

Reduce of one instruction. It seems a tad faster on
the profiler now. Very slightly but anyhow it is a
code semplification.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoUse size_t as operator[] argument type
Marco Costalba [Wed, 22 Aug 2012 10:44:43 +0000 (11:44 +0100)]
Use size_t as operator[] argument type

This better mimics std::vector::operator[] and
fixes a warning with MSVC 64bit.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoMerge generate_direct_checks() in generate_moves()
Marco Costalba [Wed, 22 Aug 2012 09:13:09 +0000 (10:13 +0100)]
Merge generate_direct_checks() in generate_moves()

Further reduce redundancy in move generation.
Veirifed no speed regression on MSVC, Clang and gcc.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoStreamline generate_moves()
Marco Costalba [Wed, 22 Aug 2012 07:29:49 +0000 (08:29 +0100)]
Streamline generate_moves()

Greatly simplify these very performace critical functions.
Amazingly we don't have any speed regression actually under
MSVC we have the same assembly for generate_moves() !

In generate_direct_checks() 'target' is calculated only
once being a loop invariant.

On Clang there is even a slight speed up.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoReformat piece values arrays
Marco Costalba [Mon, 20 Aug 2012 17:41:28 +0000 (18:41 +0100)]
Reformat piece values arrays

And rename stuff while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoMove zobrist keys out of Position
Marco Costalba [Mon, 20 Aug 2012 17:09:57 +0000 (18:09 +0100)]
Move zobrist keys out of Position

Are used by Position but do not belong to that class,
there is only one instance of them (that's why were
defined as static), so move to a proper namespace instead.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRetire copy c'tor from class Position
Marco Costalba [Mon, 20 Aug 2012 13:44:30 +0000 (14:44 +0100)]
Retire copy c'tor from class Position

Not needed.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoPrefer a reference to a pointer
Marco Costalba [Mon, 20 Aug 2012 06:54:38 +0000 (07:54 +0100)]
Prefer a reference to a pointer

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoUse enums instead of constants for piece values
Marco Costalba [Sun, 19 Aug 2012 23:04:42 +0000 (00:04 +0100)]
Use enums instead of constants for piece values

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoDocument De Bruijn sequences
Marco Costalba [Sun, 19 Aug 2012 13:12:39 +0000 (14:12 +0100)]
Document De Bruijn sequences

Insted of raw magic numbers.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoAvoid wake up master thread when useless
Marco Costalba [Sun, 19 Aug 2012 12:06:26 +0000 (13:06 +0100)]
Avoid wake up master thread when useless

Check we are the last slave of the split point
before to wake up the master. This should avoid
spurious wakes up.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoSimplify idle_loop() signature
Marco Costalba [Sun, 19 Aug 2012 10:20:33 +0000 (11:20 +0100)]
Simplify idle_loop() signature

We can detect the split point master also from within idle_loop,
so we can call the function without parameters and remove an
overloaded member hack in Thread class.

Note that we don't need to take a lock around curSplitPoint
when entering idle_loop() because if we are the master then
curSplitPoint cannot change under our feet (because is_searching
is set and so we cannot be reallocated), if we are a slave
we enter idle_loop() only upon Thread creation and in that case
is always splitPointsCnt == 0. This is true even in the very rare
case that curSplitPoint != NULL, if we have been already allocated
even before entering idle_loop().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoPrefer size_t over int for array sizes
Marco Costalba [Sun, 19 Aug 2012 09:20:15 +0000 (10:20 +0100)]
Prefer size_t over int for array sizes

Align to standard library conventions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoIntroduce namespace Bitbases
Marco Costalba [Sat, 18 Aug 2012 12:04:43 +0000 (13:04 +0100)]
Introduce namespace Bitbases

Let's continue this namespace galore...

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoIntroduce namespace UCI
Marco Costalba [Sat, 18 Aug 2012 10:50:43 +0000 (11:50 +0100)]
Introduce namespace UCI

Ater previous patch it comes naturally to take this
extra step.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRetire struct OptionsMap
Marco Costalba [Sat, 18 Aug 2012 10:23:18 +0000 (11:23 +0100)]
Retire struct OptionsMap

Directly use the underlying std::map instead and avoid
a useless inheritance.

As a nice side-effect Options global object has now a
default c'tor avoiding possible issues with globals
initializations.

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoExplicitly qualify STL functions
Marco Costalba [Sat, 18 Aug 2012 10:00:56 +0000 (11:00 +0100)]
Explicitly qualify STL functions

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRetire MovePickerExt struct
Marco Costalba [Sat, 18 Aug 2012 09:43:13 +0000 (10:43 +0100)]
Retire MovePickerExt struct

Templetize MovePicker::next_move() member function instead. It
is easier and we also avoid the forwarding of MovePicker() c'tor
arguments in the common case.

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoGuard against 'divide by zero' in bench
Marco Costalba [Mon, 30 Jul 2012 07:44:54 +0000 (09:44 +0200)]
Guard against 'divide by zero' in bench

Also remove an useless cast.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoAdded Haiku-specific changes to Makefile
Joseph R. Prostko [Mon, 30 Jul 2012 00:13:27 +0000 (00:13 +0000)]
Added Haiku-specific changes to Makefile

First change: If Haiku is host platform, change
installation prefix to /boot/common/bin

Second change: Only link in pthreads if Haiku isn't
host platform.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix UCI promotion move notation
Marco Costalba [Thu, 26 Jul 2012 17:16:24 +0000 (18:16 +0100)]
Fix UCI promotion move notation

Regression introduced by revision
f0db6a6c0b82a586

Spotted by Joona.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoReadme.txt: more grammar/style fixes
Linus Arver [Thu, 19 Jul 2012 19:09:37 +0000 (12:09 -0700)]
Readme.txt: more grammar/style fixes

11 years agoReadme.txt: grammar/stylistic fixes
Linus Arver [Wed, 18 Jul 2012 23:46:51 +0000 (16:46 -0700)]
Readme.txt: grammar/stylistic fixes

11 years agoFix regression in move_to_san()
Marco Costalba [Sun, 15 Jul 2012 08:03:38 +0000 (09:03 +0100)]
Fix regression in move_to_san()

Broken since commit 628808a11382a3ac

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoIntroduce notation.h
Marco Costalba [Sun, 15 Jul 2012 07:14:25 +0000 (08:14 +0100)]
Introduce notation.h

And group there all the formatting functions but
uci_pv() that requires access to search.cpp variables.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRewrite pv_info_xxx() signatures
Marco Costalba [Sat, 14 Jul 2012 12:19:16 +0000 (13:19 +0100)]
Rewrite pv_info_xxx() signatures

Use the helpers to format the PV info but without
writing to output stream (file or cout). Message
formatting and sending are two logically different
task.

Incidentaly reintroduce the pretty_pv() name,
from Glaurung memories :-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoInclude castle moves in 'dangerous' flag
Marco Costalba [Sat, 14 Jul 2012 11:29:11 +0000 (12:29 +0100)]
Include castle moves in 'dangerous' flag

Simplifies the code and seems more natural.

We have a very small fucntional change becuase now
at PV nodes castles are extended one ply anyhow.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoMerge exclusion search conditions
Marco Costalba [Sat, 14 Jul 2012 11:18:14 +0000 (12:18 +0100)]
Merge exclusion search conditions

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRemove redundant condition in is_dangerous()
Marco Costalba [Fri, 13 Jul 2012 08:54:24 +0000 (10:54 +0200)]
Remove redundant condition in is_dangerous()

A pawn on 7th is always passed so retire
this redundant condition.

No funtional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoSilence a MSVC warning in class Tie
Marco Costalba [Sun, 8 Jul 2012 09:22:42 +0000 (10:22 +0100)]
Silence a MSVC warning in class Tie

With warning level 4 MSVC complains that a default
assignment operator could not be generated due to
member 'file' is a reference (warning C4512).

Use a pointer instead of a reference and move
struct Tie outisde class Logger while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRename first_1 / last_1 in lsb / msb
Marco Costalba [Sun, 8 Jul 2012 07:30:37 +0000 (08:30 +0100)]
Rename first_1 / last_1 in lsb / msb

It seems more accurate: lsb is clear while 'first
bit' depends from where you look at the bitboard.

And fix compile in case of 64 bits platforms that
do not use BSFQ intrinsics.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoUse last_1() to compute new TT size
Marco Costalba [Sat, 7 Jul 2012 18:30:27 +0000 (19:30 +0100)]
Use last_1() to compute new TT size

Transposition table consists of a power of 2
number of TTCluster entries.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRevert to -O3 with Clang
Marco Costalba [Sat, 7 Jul 2012 18:00:05 +0000 (19:00 +0100)]
Revert to -O3 with Clang

Instead of -O4 option that does not work with both mingw and
Linux gcc (tested with Clang 3.1).

As reported by Reed Kotler:
Turns out that -O4 is not a valid option for clang unless you have
the proper gold linker and plugins built. That's because -O4 enables
LTO, which writes out bitcode files during the compile, and then loads
those and optimizes them during the link phase.

It requires a linker that supports LLVM's LTO. There is a plugin for
Gold available as part of LLVM.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix signedness warning in time_to_msec()
Marco Costalba [Sat, 7 Jul 2012 15:28:39 +0000 (16:28 +0100)]
Fix signedness warning in time_to_msec()

We have a signed integer here so let the return type
take in account that.

Found by Clang with -Weverything option.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoMore idiomatic signature for operator=()
Marco Costalba [Thu, 5 Jul 2012 10:52:11 +0000 (11:52 +0100)]
More idiomatic signature for operator=()

Return a reference instead of void so to enable
chained assignments like

"p = q = Position(...);"

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoStreamline null search reduction formula
Marco Costalba [Thu, 5 Jul 2012 10:48:17 +0000 (11:48 +0100)]
Streamline null search reduction formula

Although a (little) functional change, we have no ELO change
but formula it is now more clear.

After 13019 games at 30"+0.05
Mod vs Orig 2075 - 2088 - 8856 ELO 0 (+- 3.4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoClear transposition table on "ucinewgame"
Marco Costalba [Sat, 30 Jun 2012 07:00:48 +0000 (08:00 +0100)]
Clear transposition table on "ucinewgame"

It seems the standard behaviour as implemented
in most engines although UCI protocol does not
specify what to do upon "ucinewgame" command.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoTempletize make_move() helpers
Marco Costalba [Mon, 25 Jun 2012 06:57:28 +0000 (07:57 +0100)]
Templetize make_move() helpers

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoReduce indentation in UCIOption::operator=()
Marco Costalba [Sun, 24 Jun 2012 23:14:42 +0000 (00:14 +0100)]
Reduce indentation in UCIOption::operator=()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoMicro-optimize move_to_san()
Marco Costalba [Sun, 24 Jun 2012 11:08:07 +0000 (12:08 +0100)]
Micro-optimize move_to_san()

Calculate the attacks only for the piece to disambiguate,
not for all.

Also some reformatting while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoUse type_of() to categorize the moves
Marco Costalba [Sun, 24 Jun 2012 09:08:16 +0000 (10:08 +0100)]
Use type_of() to categorize the moves

Needed to rename old MoveType (used in move generation)
to GenType.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRename move.cpp to notation.cpp
Marco Costalba [Sun, 24 Jun 2012 08:46:08 +0000 (09:46 +0100)]
Rename move.cpp  to notation.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRename ThreadsManager to ThreadPool
Marco Costalba [Sun, 24 Jun 2012 08:30:40 +0000 (09:30 +0100)]
Rename ThreadsManager to ThreadPool

It is a more standard naming convention.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoReplace make_square() with operator|(File, Rank)
Marco Costalba [Sat, 23 Jun 2012 07:49:33 +0000 (08:49 +0100)]
Replace make_square() with operator|(File, Rank)

Be fancy :-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoCoding style in move.cpp
Marco Costalba [Sat, 23 Jun 2012 06:51:02 +0000 (07:51 +0100)]
Coding style in move.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoAdd min pawn-king distance to endgame evaluation
Marco Costalba [Sun, 17 Jun 2012 08:18:18 +0000 (09:18 +0100)]
Add min pawn-king distance to endgame evaluation

At endgame time push the king near his pawns (actually
one of them).

Original idea is from Critter (although slightly different),
implementation is mine and is completely different from the
original, in particular it is different the algorithm to
compute the minimum distance from pawns.

After 19895 games at 15"+0.05
Mod vs Orig 3638 - 3248 - 13009 ELO +7

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoCalculate min distance between king and his pawns
Marco Costalba [Sun, 17 Jun 2012 08:03:05 +0000 (09:03 +0100)]
Calculate min distance between king and his pawns

Just added infrastructure.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoReformat pick_random() in magics calculation
Marco Costalba [Sun, 10 Jun 2012 10:11:28 +0000 (11:11 +0100)]
Reformat pick_random() in magics calculation

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix a compile error in opposite_colors()
Marco Costalba [Sat, 2 Jun 2012 07:51:58 +0000 (08:51 +0100)]
Fix a compile error in opposite_colors()

Error is due to ambiguous overloading of operator^
because we have both the built-in operator^(int, int)
and the user defined operator^(Bitboard, Square).

This error does not trigger when using Makefile becuase,
due to luck, the user defined operator^(Bitboard, Square)
happens to be always defined _after_ opposite_colors() so
that compiler does not claim. But in case of Microsoft MSVC
we don't have a Makefile and the order of files compilation
is chosen by the compiler (in an unpredictable way). So it
could still happen that error is not detected (as in my case),
but in another case the order of compilation of the files could
be so that at some point both operator^ were defined before
opposite_colors() and this triggers the error.

The fix is much simpler than the explanation :-)

Reported by Quocvuong82.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix an issue when adding a book during the game
Marco Costalba [Sun, 27 May 2012 13:13:14 +0000 (14:13 +0100)]
Fix an issue when adding a book during the game

Currently when we fail to open a book file, for instance
if it doesn't exsist, we leave Book::open() with ifstream
failbit set. If then the book file is added, we correctly
open it at next attempt, but failbit is still set so that
after opening we exit because ifstream::good() returns false.

The fix is to reset failbit upon exiting.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRetire PieceOffset[] in book.cpp
Marco Costalba [Sun, 27 May 2012 12:43:15 +0000 (13:43 +0100)]
Retire PieceOffset[] in book.cpp

And calculate piece offset on the fly. Also
improve comments.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix a possible 'Division by zero'
Marco Costalba [Sat, 26 May 2012 22:14:37 +0000 (23:14 +0100)]
Fix a possible 'Division by zero'

In case a book entry has 'count' field set to 0
we crash. Spotted by Clang's static analyzer.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRename psq_score in ReducedStateInfo
Marco Costalba [Sat, 26 May 2012 21:43:23 +0000 (22:43 +0100)]
Rename psq_score in ReducedStateInfo

So to be fully in sync with StateInfo, and move struct
to position.h, just below StateInfo.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix book file regression
Marco Costalba [Sat, 26 May 2012 09:11:59 +0000 (10:11 +0100)]
Fix book file regression

Revision 2aac860db3d04881103a3b0d0 of 27 / 4 / 2012
changed can_castle() signatures from bool to int and
this broke the code that calculates polyglot hash key
in book.cpp

Instead of directly fixing the code we prefer to change
castling rights definitions to align to the polyglot ones
(as we did in previous patch). After this step we can simply
take internal castle rights as they are and use them
directly to calculate polyglot book hash key, as we do
in this patch that fixes the regression.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRedefine enum CastleRight
Marco Costalba [Sat, 26 May 2012 08:51:16 +0000 (09:51 +0100)]
Redefine enum CastleRight

To be aligned with PolyGlot book castle right definitions.

This will be used by next patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoAdd a known draw case in kpk bitbase generation
Marco Costalba [Sat, 19 May 2012 07:38:23 +0000 (08:38 +0100)]
Add a known draw case in kpk bitbase generation

Early classify as known draws the positions
where white king is trapped on the rook file.

Suggested by Dan Honeycutt.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoSimplify Position::print()
Marco Costalba [Sat, 12 May 2012 10:35:40 +0000 (11:35 +0100)]
Simplify Position::print()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRevert "Don't split if reduced below min_split_depth"
Marco Costalba [Sat, 12 May 2012 08:57:24 +0000 (09:57 +0100)]
Revert "Don't split if reduced below min_split_depth"

After extensive testing (I was off line this week and let
the test go on) it seems this change is useless:

After 33968 games on a QUAD (4 threads) at 15"+0.05
Mod vs Orig 5425 - 5550 - 22993 ELO -1 (+-2.1)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoImprove previous patch
Marco Costalba [Sat, 12 May 2012 08:21:52 +0000 (09:21 +0100)]
Improve previous patch

Only in case of promotion we care about an upper case
promotion piece char, so std::transform() is overkill
for the task.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoJunior promotion patch
Balint Pfliegel [Fri, 11 May 2012 23:01:33 +0000 (00:01 +0100)]
Junior promotion patch

Assumption: Junior sends promotions according to the side to move (ucase/lcase).
Fact: Stockfish generally handles promotion lcase.
Patch: Handling position fen input moves always with lcase promotions.

Ported back by Portfish. No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoFix compilation with Android NDK
Marco Costalba [Wed, 9 May 2012 07:33:25 +0000 (09:33 +0200)]
Fix compilation with Android NDK

It seems ADL lookup is broken with the STLPort library. Peter says:

The compiler is gcc 4.4.3, but I don't know how many patches they
have applied to it. I think gcc has had support for Koenig lookup
a long time. I think the problem is the type of the vector iterator.
For example, line 272 in search.cpp:

 if (bookMove && count(RootMoves.begin(), RootMoves.end(), bookMove))

gives the error:

jni/stockfish/search.cpp:272: error: 'count' was not declared in this scope

Here RootMoves is:

 std::vector<RootMove> RootMoves;

If std::vector<T>::iterator is implemented as T*, then Koenig lookup
would fail because RootMove* is not in namespace std.

I compile with the stlport implementation of STL, which in its vector
class has:

 typedef value_type* iterator;

I'm not sure if this is allowed by the C++ standard. I did not find
anything that says the iterator type must belong to namespace std.
The consensus in this thread

http://compgroups.net/comp.lang.c++.moderated/argument-dependent-lookup/433395

is that the stlport iterator type is allowed.

Report and patch by Peter Osterlund.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoSimplify attacks_bb()
Marco Costalba [Tue, 1 May 2012 11:17:08 +0000 (12:17 +0100)]
Simplify attacks_bb()

And some formatting while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoChange pos.pieces() argument order
Marco Costalba [Tue, 1 May 2012 11:01:38 +0000 (12:01 +0100)]
Change pos.pieces() argument order

Let first argument to be the 'color'. This allows to align
pos.pieces() signatures with piece_list(), piece_count() and
all the other functions where 'color' argument is passed as
first one.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoConvert constants to decimal representation
Marco Costalba [Tue, 1 May 2012 10:33:38 +0000 (11:33 +0100)]
Convert constants to decimal representation

Hex representation doesn't add any value in those cases.
Preserve hex representation where more self-documenting
for instance for binary masks values.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoDon't split if reduced depth is below min_split_depth
Marco Costalba [Sun, 22 Apr 2012 11:59:35 +0000 (12:59 +0100)]
Don't split if reduced depth is below min_split_depth

It seems to increase SMP performances. To note that
this patch goes in the opposite direction of "Active
reparenting" where we try to reparent an idle slave
as soon as possible. Instead here we prefer to keep
it idle instead of splitting on a shallow / near the
leaves node.

After 11550 games on a QUAD (4 threads) at 15"+0.05
Mod vs Orig 1972 - 1752 - 7826 ELO +6 (+-3.6)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoIncrease optimization level of Clang
Marco Costalba [Sun, 29 Apr 2012 22:11:23 +0000 (23:11 +0100)]
Increase optimization level of Clang

Set optimization level to 4 and get a 2.564% faster binary:

Stockfish (Clang, Level 4) bench:
$ make build ARCH=osx-x86-64 COMP=clang
(Clang does not support PGO)
Average of 4 trials:
Total time (ms): 5137.5
Nodes searched: 5631135
Nodes/second: 1096084.5

Stockfish (Clang, Level 3) bench:
$ make build ARCH=osx-x86-64 COMP=clang
(Clang does not support PGO)
Average of 4 trials:
Total time (ms): 5269.25
Nodes searched: 5631135
Nodes/second: 1068679.25

Stockfish (GCC, PGO) bench:
$ make profile-build ARCH=osx-x86-64
Average of 4 trials:
Total time (ms): 5286
Nodes searched: 5631135
Nodes/second: 1065292.25

Suggestion and performance tests by Daylen Yang.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRemove unreachable extension condition
Marco Costalba [Sun, 29 Apr 2012 17:58:48 +0000 (18:58 +0100)]
Remove unreachable extension condition

A PvNode that givesCheck has been already granted
an extension of ONE_PLY in previous condition.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoAdd support for Mac clang compiler
Andy Duplain [Sun, 29 Apr 2012 09:14:50 +0000 (10:14 +0100)]
Add support for Mac clang compiler

Makefile modified to support the clang compiler under Mac.
This was tested using clang 4 under Mountain Lion, but should
also work fine under Lion and possibly under Snow Leopard.

It requires the 'Xcode 4.x Command Line Tools' to be installed.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoProper indenting of multiple conditions
Marco Costalba [Sat, 28 Apr 2012 10:08:10 +0000 (11:08 +0100)]
Proper indenting of multiple conditions

Triviality due to a boring saturday morning.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
11 years agoRename square_empty() to is_empty()
Marco Costalba [Sat, 28 Apr 2012 09:49:52 +0000 (10:49 +0100)]
Rename square_empty() to is_empty()

No functional change.

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