1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00
Commit graph

2605 commits

Author SHA1 Message Date
Marco Costalba
18505f1fc4 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>
2012-06-30 08:00:48 +01:00
Marco Costalba
dc88cd691f Templetize make_move() helpers
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-25 08:09:55 +01:00
Marco Costalba
ebe8009aff Reduce indentation in UCIOption::operator=()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-25 00:14:42 +01:00
Marco Costalba
628808a113 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>
2012-06-24 12:38:29 +01:00
Marco Costalba
dc7fd868f4 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>
2012-06-24 11:07:18 +01:00
Marco Costalba
7b4aa10708 Rename move.cpp to notation.cpp
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-24 09:46:31 +01:00
Marco Costalba
960a689769 Rename ThreadsManager to ThreadPool
It is a more standard naming convention.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-24 09:45:37 +01:00
Marco Costalba
5f5d056c8f Replace make_square() with operator|(File, Rank)
Be fancy :-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-23 09:17:54 +01:00
Marco Costalba
9c7e2c8f9d Coding style in move.cpp
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-23 08:34:07 +01:00
Marco Costalba
4f5680950a 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>
2012-06-22 06:31:18 +01:00
Marco Costalba
9793fa1906 Calculate min distance between king and his pawns
Just added infrastructure.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-17 09:41:18 +01:00
Marco Costalba
0446fc85de Reformat pick_random() in magics calculation
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-06-10 11:46:52 +01:00
Marco Costalba
764d3f44b6 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>
2012-06-02 09:04:11 +01:00
Marco Costalba
0412f4a1ee 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>
2012-05-27 14:13:14 +01:00
Marco Costalba
6828325881 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>
2012-05-27 13:46:55 +01:00
Marco Costalba
61a054b170 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>
2012-05-26 23:17:22 +01:00
Marco Costalba
3361ad4242 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>
2012-05-26 22:43:23 +01:00
Marco Costalba
6c9c6dd989 Fix book file regression
Revision 2aac860db3 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>
2012-05-26 10:14:08 +01:00
Marco Costalba
a358dfe934 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>
2012-05-26 10:03:35 +01:00
Marco Costalba
0ecc920a09 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>
2012-05-19 08:45:16 +01:00
Marco Costalba
f86182e791 Simplify Position::print()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-05-12 12:50:11 +01:00
Marco Costalba
c19a6ef82d 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>
2012-05-12 10:00:26 +01:00
Marco Costalba
ecb84464f9 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>
2012-05-12 09:21:52 +01:00
Balint Pfliegel
1b2af05ea6 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>
2012-05-12 00:04:17 +01:00
Marco Costalba
caef319219 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>
2012-05-11 17:16:51 +01:00
Marco Costalba
2f47844c7c Simplify attacks_bb()
And some formatting while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-05-01 13:16:20 +01:00
Marco Costalba
b9bc6e823f 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>
2012-05-01 12:09:20 +01:00
Marco Costalba
5e90580088 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>
2012-05-01 11:37:12 +01:00
Marco Costalba
ef0496ff40 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>
2012-04-29 23:28:07 +01:00
Marco Costalba
96f4ab48d8 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>
2012-04-29 23:11:23 +01:00
Marco Costalba
39c08c17c5 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>
2012-04-29 18:58:48 +01:00
Andy Duplain
b93693b831 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>
2012-04-29 11:47:02 +01:00
Marco Costalba
cdfe43eb8f Proper indenting of multiple conditions
Triviality due to a boring saturday morning.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-28 11:10:51 +01:00
Marco Costalba
456f37b8ab Rename square_empty() to is_empty()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-28 10:54:33 +01:00
Marco Costalba
e8d89ca5b0 Micro-optimize king evaluation
Reuse already calculated value, instead of calling
king_safety() again.

Patch suggested by Balint Pfliegel.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-28 10:37:55 +01:00
Marco Costalba
2aac860db3 Fix wrong condition in PawnEntry::king_safety()
Since revision 374c9e6b63
we use also castling information to calculate king safety.
So before to reuse the cached king safety score we have to
veify not only king position, but also castling rights are
the same of the pre-calculated ones.

This is a very subtle bug, found only becuase even after
previous patch, consecutives runs of 'bench' _still_ showed
different numbers. Pawn tables are not cleared between 'bench'
runs and in the second run a king safety score, previously
evaluated under some castling rights, was reused by another
position with different castling rights instead of being
recalculated from scratch.

Bug spotted and tracked down by Balint Pfliegel

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-27 10:59:18 +01:00
Marco Costalba
8b00e50cb7 Clear TT before running 'bench'
Now that we can call bench multiple times
from command prompt we need to ensure searched
nodes remain constant across different runs.

Spotted by Bálint Pfliegel.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-26 19:37:30 +01:00
Marco Costalba
be3b8f3ae9 Retire "Active reparenting"
After 6K games at 60" + 0.1 on QUAD with 4 threads
this implementation fails to show a measurable increase,
result is well within error bar.

Perhaps with 8 or more threads resut is better but we
don't have the hardware to test. So retire for now and
in case re-add in the future if it proves good on big
machines.

The only good news is that we don't have a regression and
implementation is stable and bug-free, so could be reused
somewhere in the future.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-22 17:52:31 +01:00
Marco Costalba
ce159b16b9 Fix endless reaparenting loop
The check for detecting when a split point has all the
slaves still running is done with:

   slavesMask == allSlavesMask

When a thread reparents, slavesMask is increased, then, if
the same thread finishes, because there are no more moves,
slavesMask returns to original value and the above condition
returns to be true. So that the just finished thread immediately
reparents again with the same split point, then starts and
then immediately exits in a tight loop that ends only when a
second slave finishes, so that slavesMask decrements and the
condition becomes false. This gives a spurious and anomaly
high number of faked reparents.

With this patch, that rewrites the logic to avoid this pitfall,
the reparenting success rate drops to a more realistical 5-10%
for 4 threads case.

As a side effect note that now there is no more the limit of
maxThreadsPerSplitPoint when reparenting.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-17 18:51:49 +01:00
Marco Costalba
5392007a24 Improved cutoff check when reparenting
Check for a cutoff occurred also high in
the tree and not only at current split
point.

This avoids some more wasted reparenting.

No functional chnage.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-16 18:28:08 +01:00
Marco Costalba
f59323b56a Use more_than_one() instead of single_bit()
It is more correct given what the function does. In
particular single_bit() returns true also in case of
empty bitboards.

Of course also the usual renaming while there :-)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-14 09:51:59 +01:00
Marco Costalba
25a9b601b2 Reparent to latest
Instead of reparenting to oldest split point, try to reparent
to latest. The nice thing here is that we can use the YBWC
helpful master condition to allow the reparenting of a split
point master as long as is reparented to one of its slaves.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-14 07:20:31 +01:00
Marco Costalba
c645aca199 Don't reparent if a cutoff is pending
And update master->splitPointsCnt under lock
protection. Not stricly necessary because
single_bit() condition takes care of false
positives anyhow, but it is a bit tricky and
moving under lock is the most natural thing
to do to avoid races with "reparenting".

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-12 21:17:52 +01:00
Marco Costalba
44432f67d7 Active Reparenting
In Young Brothers Wait Concept (YBWC) available slaves are
booked by the split point master, then start to search below
the assigned split point and, once finished, return in idle
state waiting to be booked by another master.

This patch introduces "Active Reparenting" so that when a
slave finishes its job on the assigned split point, instead
of passively waiting to be booked, searches a suitable active
split point and reprents itselfs to that split point. Then
immediately starts to search below the split point in exactly
the same way of the others split point's slaves. This reduces
to zero the time waiting in idle loop and should increase
scalability especially whit many (8 or more) cores.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-10 18:22:58 +01:00
Marco Costalba
d66b765eb6 Sync compute_xxx implementations
Also refactored Position::pos_is_ok() while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-09 13:11:38 +01:00
Marco Costalba
e72b93e44f Move Tempo to evaluation
Apart from the semplification it is now more clear that
the actual Tempo added was half of the indicated score.
This is becuase at start compute_psq_score() added half
Tempo unit and in do_move() white/black were respectively
adding/subtracting one Tempo unit.

Now we have directly halved Tempo constant and everything
is more clear.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-09 11:14:00 +01:00
Marco Costalba
68885f78f3 Micro-optimize do_castle_move()
Use the same tables update trick used in do_move().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-09 09:41:41 +01:00
Marco Costalba
4a310baae2 Disable book during analysis
It is still enabled during fixed limit search so to
use it during fixed depth/nodes/time matches.

Bug reported by Daylen.

No functional changes.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-09 08:09:02 +01:00
Marco Costalba
d549497144 Introduce make_castle_right() helper
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-08 17:19:49 +01:00
Marco Costalba
e56342ed00 Shrink castlePath[] and castleRookSquare[] sizes
Shrinking from [16] to [2][2] is able to speedup
perft of start position of almost 5% !

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-04-08 16:55:01 +01:00