stockfish
12 years agoNull move dynamic reduction based on value
Marco Costalba [Fri, 13 Nov 2009 10:25:34 +0000 (11:25 +0100)]
Null move dynamic reduction based on value

After 994 games at 1+0

Mod vs Orig +244 =521 -229 50.75%  504.5/994 +5 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse a more standard perft UCI interface
Marco Costalba [Fri, 13 Nov 2009 09:27:14 +0000 (10:27 +0100)]
Use a more standard perft UCI interface

Call directly 'perft 6' to search up to depth 6*OnePly
instead of the old 'perft depth 6'.

It is more in line to what other engines do. Also a bit
of cleanup while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter document king safety evaluation
Marco Costalba [Thu, 12 Nov 2009 18:01:44 +0000 (19:01 +0100)]
Better document king safety evaluation

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRearrange table layout in evaluate.cpp
Marco Costalba [Thu, 12 Nov 2009 16:42:43 +0000 (17:42 +0100)]
Rearrange table layout in evaluate.cpp

A bit more cache friendly.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove dcCandidates data member from SplitPoint
Marco Costalba [Thu, 12 Nov 2009 15:55:31 +0000 (16:55 +0100)]
Remove dcCandidates data member from SplitPoint

It is no more used now that we have CheckInfo.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove update_checkers()
Marco Costalba [Wed, 11 Nov 2009 09:41:46 +0000 (10:41 +0100)]
Remove update_checkers()

Now that we have CheckInfo we don't need it anymore.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire evaluate_mobility()
Marco Costalba [Wed, 11 Nov 2009 20:17:38 +0000 (21:17 +0100)]
Retire evaluate_mobility()

Move the code to the caller and also move mob_area
computation out of evaluate_pieces(). It is more clear
the code flow and it is also faster.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall sort_moves() deobfuscation
Marco Costalba [Wed, 11 Nov 2009 19:32:58 +0000 (20:32 +0100)]
Small sort_moves() deobfuscation

Write the for loop in a more idiomatic way, no assembly
change and of course no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't futility-prune ttMove
Marco Costalba [Tue, 10 Nov 2009 17:15:22 +0000 (18:15 +0100)]
Don't futility-prune ttMove

After 933 games
Mod vs Orig +219 =505 -208 +4 ELO

A small increase as expected.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoPropagate "move is check" info to do_move()
Marco Costalba [Tue, 10 Nov 2009 10:05:20 +0000 (11:05 +0100)]
Propagate "move is check" info to do_move()

When false (common case) we avoid to update checkers
bitboard that although not so costly slows down a bit
this very hot and critical path.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall update_checkers() cleanup
Marco Costalba [Tue, 10 Nov 2009 09:05:09 +0000 (10:05 +0100)]
Small update_checkers() cleanup

And is a bit faster too.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall update to pop_1st_bit()
Marco Costalba [Tue, 10 Nov 2009 07:55:52 +0000 (08:55 +0100)]
Small update to pop_1st_bit()

Avoid a 64 bit load using a pointer. It saves a couple of push/pop
instructions so advantage is only theorical, but anyway we use
pop_1st_bit() as a reference implementation for 32 bit systems so
we keep it more for documentation purposes then for other reasons.

Idea of pointer is of Eric Mullins.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall CheckInfo fallout
Marco Costalba [Mon, 9 Nov 2009 20:48:02 +0000 (21:48 +0100)]
Small CheckInfo fallout

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFully convert move_is_check() internally
Marco Costalba [Mon, 9 Nov 2009 20:29:22 +0000 (21:29 +0100)]
Fully convert move_is_check() internally

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert move_is_check() to take a CheckInfo reference
Marco Costalba [Mon, 9 Nov 2009 20:02:07 +0000 (21:02 +0100)]
Convert move_is_check() to take a CheckInfo reference

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse CheckInfo to compute dcCandidates
Marco Costalba [Mon, 9 Nov 2009 19:54:45 +0000 (20:54 +0100)]
Use CheckInfo to compute dcCandidates

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIntroduce CheckInfo struct
Marco Costalba [Mon, 9 Nov 2009 19:49:01 +0000 (20:49 +0100)]
Introduce CheckInfo struct

Keeps info used to speed-up move_is_check()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix operator/(Score s, int i)
Marco Costalba [Mon, 9 Nov 2009 08:00:24 +0000 (09:00 +0100)]
Fix operator/(Score s, int i)

And remove some useless declarations

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't copy the key in do_move
Marco Costalba [Sun, 8 Nov 2009 16:56:41 +0000 (17:56 +0100)]
Don't copy the key in do_move

It will be overwritten anyway.

Also other little small touches that seem to increase
speed more then the whole enum Score patch series :-(

Optimization is really a black art.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDefine Score as an enum
Marco Costalba [Sat, 7 Nov 2009 21:21:50 +0000 (22:21 +0100)]
Define Score as an enum

Increases performance because now we use one integer
for both midgame and endgame scores.

Unfortunatly the latest patches seem to have reduced a bit
the speed so at the end we are more or less at the same
performance level of the beginning. But this patch series
introduced also some code cleanup so it is the main reason
we commit anyway.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoChange Score definition to avoid the union
Marco Costalba [Sat, 7 Nov 2009 18:18:44 +0000 (19:18 +0100)]
Change Score definition to avoid the union

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRevert "Do not extend at low depths if not in PV"
Marco Costalba [Sat, 7 Nov 2009 18:47:02 +0000 (19:47 +0100)]
Revert "Do not extend at low depths if not in PV"

On Joona's QUAD:
Orig - Mod: 414 - 373

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRevert "IID in pv also when TT move depth is too small"
Marco Costalba [Sat, 7 Nov 2009 18:45:13 +0000 (19:45 +0100)]
Revert "IID in pv also when TT move depth is too small"

After almost 900 games we are at -2 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoLast conversions to Score in evaluate.cpp
Marco Costalba [Sat, 7 Nov 2009 14:56:56 +0000 (15:56 +0100)]
Last conversions to Score in evaluate.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert ThreatBonus to Score
Marco Costalba [Sat, 7 Nov 2009 14:43:45 +0000 (15:43 +0100)]
Convert ThreatBonus to Score

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert RookOn7thBonus and QueenOn7thBonus to be Score
Marco Costalba [Sat, 7 Nov 2009 14:35:11 +0000 (15:35 +0100)]
Convert RookOn7thBonus and QueenOn7thBonus to be Score

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert mobility bonus tables to Score
Marco Costalba [Sat, 7 Nov 2009 14:02:10 +0000 (15:02 +0100)]
Convert mobility bonus tables to Score

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert apply_weight() to handle Score
Marco Costalba [Sat, 7 Nov 2009 13:32:26 +0000 (14:32 +0100)]
Convert apply_weight() to handle Score

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert MaterialInfo and PawnInfo to use Score
Marco Costalba [Sat, 7 Nov 2009 13:05:55 +0000 (14:05 +0100)]
Convert MaterialInfo and PawnInfo to use Score

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIntroduce PieceSquareTable[16][64]
Marco Costalba [Sat, 7 Nov 2009 12:12:58 +0000 (13:12 +0100)]
Introduce PieceSquareTable[16][64]

Instead of MgPieceSquareTable[16][64] and EgPieceSquareTable[16][64]

This allows to fetch mg and eg values from adjacent words in memory.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoConvert Position to use Score struct
Marco Costalba [Sat, 7 Nov 2009 11:40:48 +0000 (12:40 +0100)]
Convert Position to use Score struct

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIntroduce Score struct
Marco Costalba [Sat, 7 Nov 2009 10:15:55 +0000 (11:15 +0100)]
Introduce Score struct

Save mid and end game scores in an union so to
operate on both values in one instruction.

This patch just introduces the infrastructure and changes
EvalInfo to use a single Score value instead of mgValue
and egValue.

Speed is more or less the same because we still don't use
unified midgame-endgame tables where the single assignment
optimization can prove effective.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix correct name of int64_t type
Marco Costalba [Sat, 7 Nov 2009 09:08:28 +0000 (10:08 +0100)]
Fix correct name of int64_t type

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDo not extend at low depths if not in PV
Marco Costalba [Fri, 6 Nov 2009 15:42:02 +0000 (16:42 +0100)]
Do not extend at low depths if not in PV

Only check extensions are allowed.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoIID in pv also when TT move depth is too small
Marco Costalba [Fri, 6 Nov 2009 15:08:39 +0000 (16:08 +0100)]
IID in pv also when TT move depth is too small

Try an internal iterative deepening not only when we don't
have a TT move but also if search depth is more then 4*OnePly
higher then TT move depth.

On some tests it seems that in around 20% of cases ttMove changes !

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBetter big-endian support wording in Makefile
Marco Costalba [Fri, 6 Nov 2009 16:33:14 +0000 (17:33 +0100)]
Better big-endian support wording in Makefile

Suggested by Joona.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoEnable POPCNT only through Makefile
Marco Costalba [Fri, 6 Nov 2009 16:23:02 +0000 (17:23 +0100)]
Enable POPCNT only through Makefile

Also remove some fallback templates that prevent a
compile error in case the user runs 'make icc-profile-popcnt'
from a non supported machine.

We want to loudly fail in that case instead of silently
fallback in a non-popcount compilation.

Updated documentation too.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdd popcnt-support in Makefile
Joona Kiiski [Fri, 6 Nov 2009 07:59:42 +0000 (09:59 +0200)]
Add popcnt-support in Makefile

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall code-style touches in movegen.cpp
Marco Costalba [Fri, 6 Nov 2009 13:33:34 +0000 (14:33 +0100)]
Small code-style touches in movegen.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix a small warning under icc
Marco Costalba [Fri, 6 Nov 2009 09:39:33 +0000 (10:39 +0100)]
Fix a small warning under icc

Variable 'f' in 'for' loop scope hides same named
one in outer scope.

Of curse no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoBig-endian compatible pop_1st_bit()
Marco Costalba [Thu, 5 Nov 2009 18:29:26 +0000 (19:29 +0100)]
Big-endian compatible pop_1st_bit()

Thanks to Eric Mullins we have now endian friendly
pop_1st_bit() and also is removed the need to use
-fno-strict-aliasing compiler option with GCC.

Speed is almost as fast, very small difference if any in
perft test, so I assume almost no difference in real games.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix a compile error in debug mode
Marco Costalba [Fri, 6 Nov 2009 07:24:06 +0000 (08:24 +0100)]
Fix a compile error in debug mode

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoEnable PH_TT_MOVES during evasion generation
Marco Costalba [Thu, 5 Nov 2009 13:40:51 +0000 (14:40 +0100)]
Enable PH_TT_MOVES during evasion generation

This allow us to avoid the generation of the
evasion moves if we already have a TT move, and
in case we have a cut-off we skip evasion generation
altoghter.

Node count is changed because now we try TT move _before_
to generate evasions. The search on the TT move alters the
piece lists so that when we come back to generate evasions
we build the move list with a diferent order and this alters
the node count.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoExtend move_is_legal() to work also when in check
Marco Costalba [Thu, 5 Nov 2009 11:52:40 +0000 (12:52 +0100)]
Extend move_is_legal() to work also when in check

This patch is a prerequisite to use TT phase
during evasions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMove locals definitions at the function start
Marco Costalba [Thu, 5 Nov 2009 10:11:02 +0000 (11:11 +0100)]
Move locals definitions at the function start

It seems to me function are easier to read now.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRetire MovePicker::discovered_check_candidates()
Marco Costalba [Wed, 4 Nov 2009 13:46:16 +0000 (14:46 +0100)]
Retire MovePicker::discovered_check_candidates()

It is now no more needed to know dc candidates
inside MovePicker, so avoid calculating there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRewrite generate_pawn_moves() and simplify evasions
Marco Costalba [Tue, 3 Nov 2009 11:29:07 +0000 (12:29 +0100)]
Rewrite generate_pawn_moves() and simplify evasions

Big cleanup and semplification of pawns evasions that
now are pseudo-legal as the remaining moves. This
allow us to remove a lot of tricky code.

Verified against perft: no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoGenerate pseudo-legal moves in generate_evasions()
Marco Costalba [Mon, 2 Nov 2009 17:27:26 +0000 (18:27 +0100)]
Generate pseudo-legal moves in generate_evasions()

This allow a big semplification in move generation
that will be committed with the next patch. And makes
handling of evasions similar to the other type of moves.

This patch plus the next seem to improve also on
the performance side because after 640 games to
verify there are no hidden regressions we are at +9 ELO

Verified with perft no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoOptimize generate_evasions()
Marco Costalba [Mon, 2 Nov 2009 15:33:54 +0000 (16:33 +0100)]
Optimize generate_evasions()

Generate captures of checking piece and blocking
evasions in one go.

Also reduce of one indentation level early returning
when we have a double check.

Verified with perft no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSpeed up perft
Marco Costalba [Wed, 4 Nov 2009 10:11:04 +0000 (11:11 +0100)]
Speed up perft

There is no need to do / undo the move at the last ply

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove SEE optimizations
Marco Costalba [Sun, 1 Nov 2009 21:09:53 +0000 (22:09 +0100)]
Remove SEE optimizations

Don't seem to help, perhaps because we
return an approximate SEE score instead of the
real negative score so that we have some bad capture
or evasion sub-optimal ordering that compensates
the speed up.

Anyhow after 999 games at 1+0
Mod vs Orig +240 =514 -245 -2 ELO

So almost no harm to remove and make the code simpler.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoReorder evasions
Marco Costalba [Sat, 31 Oct 2009 09:51:04 +0000 (10:51 +0100)]
Reorder evasions

Always try ttMove as first. Then try good captures ordered
by MVV/LVA, then non-captures if destination square is not
under attack, ordered by history value, and at the end
bad-captures and non-captures with a negative SEE. This
last group is ordered by the SEE score.

After 999 games at 1+0
Mod vs Orig +254 =546 -199 +19 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAnother see() shortcut
Marco Costalba [Sat, 31 Oct 2009 10:16:40 +0000 (11:16 +0100)]
Another see() shortcut

Because we only generate legal moves we can assume
a king cannot be recaptured, so we can safely return
immediately with the captured piece score. If the move
turns out to be illegal it will be pruned anyhow,
independently from SEE value. This gives a good speed up
especially now that we SEE-test all the evasions that
are always legal and very often are king moves.

Another optimization catches almost 15% of cases, unfortunatly
we have already calculated the very expensive attacks, so
benefits are not so big anyway.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoShortcut see_sign() when SEE is known negative
Marco Costalba [Fri, 30 Oct 2009 12:34:45 +0000 (13:34 +0100)]
Shortcut see_sign() when SEE is known negative

This patch cuts 30% of SEE calculations, as a drawback
a returned negative value is no more always correct if
a shortcut is found.

This could impact move order when based on negative see
score as example bad captures and evasions.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove castling moves in check generation
Marco Costalba [Sun, 1 Nov 2009 16:19:04 +0000 (17:19 +0100)]
Remove castling moves in check generation

Check generation is used only in qsearch and
only at Depth(0), castling moves that give check
are very rare overall and even almost not exsistent
at Depth(0).

So retire this almost never used code that adds
a small but consistent slow down in the normal path.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoOptimize check generation
Marco Costalba [Sun, 1 Nov 2009 09:40:14 +0000 (10:40 +0100)]
Optimize check generation

Because discovery checks are very rare it is better to handle
them all in one go and strip from usual check generation
function.

Also rewrite direct checks generation to use piece lists instead
of pop_1st_bit()

On perft test we have a +6% of speed up and is verified we
generate the same moves, although in a different order.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoImplemented perft
Joona Kiiski [Fri, 2 Oct 2009 04:09:24 +0000 (07:09 +0300)]
Implemented perft

Patch from Joona with extension to benchmark and inclusion
of Depth(0) moves generation by me.

Note that to test also qsearch and in particulary checks
generations a change in the end condition is needed.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoEvaluation threat values after 39089 games
Marco Costalba [Tue, 27 Oct 2009 19:48:19 +0000 (20:48 +0100)]
Evaluation threat values after 39089 games

Verified against tuning branch.

After 100 games at 1+0 on Joona QUAD

Mod - Orig: 527.5 - 471.5 (+20 elo)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix build under gcc
Marco Costalba [Sun, 25 Oct 2009 09:22:03 +0000 (10:22 +0100)]
Fix build under gcc

Also some warnings squashed.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdd threat evaluation
Marco Costalba [Sun, 25 Oct 2009 07:16:34 +0000 (08:16 +0100)]
Add threat evaluation

Give a bonus for each kind of attacked piece. Bonus
value is based on the type of attacked piece and the
type of attacking one.

Penalize pieces attacked by enemy pawns, also in
this case penality value depends on the type of
attacked piece.

This patch oboletes as redundant the increased mobility
count of the attcked squares that is then removed.

After 956 games at 1+0
Mod vs Orig  +262 =462 -232 51.57%  493.0/956 +11 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMicro optimize mobility calculation
Marco Costalba [Fri, 23 Oct 2009 10:24:53 +0000 (11:24 +0100)]
Micro optimize mobility calculation

Take out of mobility loop a constant expression.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUnify capture and promotion tests
Marco Costalba [Wed, 21 Oct 2009 10:41:24 +0000 (11:41 +0100)]
Unify capture and promotion tests

Small code cleanup and a bit faster too.

The only functional change is that in extension
in pv node we extend promotions and not only captures
when condition met.

This is practically an undetectable change and has
no impact on strenght.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't prune TT move in qsearch even if SEE < 0
Marco Costalba [Tue, 20 Oct 2009 15:14:57 +0000 (16:14 +0100)]
Don't prune TT move in qsearch even if SEE < 0

Even if SEE is negative there is always a good possibility
that TT move is a cut move anyway. For instance a lot of
BXN exchanges that have negative SEE can very easily be
good exchanges.

A nice side effect is a bit reduced frequency of
see_sign() calls.

After 643 games at 1+0
Mod vs Orig +174 =327 -142 52.49%  337.5/643 +17 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoPick best moves one per cycle instead of sorting
Marco Costalba [Tue, 20 Oct 2009 10:38:20 +0000 (11:38 +0100)]
Pick best moves one per cycle instead of sorting

When the move list is very small, like captures normally
are, it is faster to pick the best move with a linear
scan, one per cycle.

This has the added advantage that the picked capture move is
very possibly a cut-off move, so that other searches are
avoided. For non-captures it is still faster to sort in
advance.

Because scan-and-pick alghortim is not stable, node count
has changed.

After 885 games at 1+0
Mod vs Orig +196 =510 -179 50.96%  451.0/885

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAvoid a needless locking in sp_search()
Marco Costalba [Mon, 19 Oct 2009 06:44:06 +0000 (07:44 +0100)]
Avoid a needless locking in sp_search()

Only in less then 2% of cases we have a new sp->bestValue,
so check before to lock and save a costly locking
most of the times.

Patch suggested by Joona.

No functional search.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSimilarize pruning code in search() and sp_search()
Joona Kiiski [Sat, 17 Oct 2009 05:42:42 +0000 (08:42 +0300)]
Similarize pruning code in search() and sp_search()

Use futility pruning also in split points.
Do not use history pruning in split points when
getting mated.

After 1000 games on Joona QUAD
Orig - Mod: 496 - 504

Added an optimization to avoid a costly lock in the
very common case that sp->futilityValue <= sp->bestValue.
A test on a dual CPU shows only 114 hits on 23196 events,
so avoid a lock in all the other cases.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse an homegrown insertion sort instead of std::sort()
Marco Costalba [Thu, 15 Oct 2009 11:08:39 +0000 (13:08 +0200)]
Use an homegrown insertion sort instead of std::sort()

It is stable and it is also a bit faster then std::sort()
on the tipical small move lists that we need to handle.

Verified to have same functionality of std::stable_sort()

After 999 games at 1+0
Mod vs Orig +240 =534 -225 50.75%  507.0/999  +5 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDo not prune the move if we are still under mate
Marco Costalba [Wed, 14 Oct 2009 08:18:16 +0000 (09:18 +0100)]
Do not prune the move if we are still under mate

If after the first tried 2 + int(depth) moves we still
have no any move that takes us out of a mate then do
not prune the following move, it is more important to
escape mate then speed up search.

This fixes an odd behaviour regarding mates, as example
the following diagram is a mate in 4, not in 3 as bogusly
reported before this patch.

1B2n3/8/2R5/5p2/3kp1n1/4p3/B3K3/8 w - - bm #4;

The performance impact should be minimal, the increment
in searched nodes is less then 0.1 %%

Idea and patch by Joona

After 999 games at 1+0
Mod vs Orig +193 =604 -202  -3 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMinor improvement in eval of unstoppable pawns promoting one ply apart.
Tord Romstad [Thu, 15 Oct 2009 10:39:55 +0000 (12:39 +0200)]
Minor improvement in eval of unstoppable pawns promoting one ply apart.

Marco's new code for evaluating two unstoppable passed pawns where
one pawn promotes a single ply before the other tried to detect
cases where the pawn that promotes first could immediately capture
the pawn that promotes a ply later, but didn't work in cases where
the two pawns are on the same file. An example of this is the
following position:

8/8/3K4/2P5/2p5/3k4/8/8 w - -

With the new code, such positions are handled correctly.

12 years agoFix a crash when reaching PLY_MAX in a check position
Marco Costalba [Mon, 12 Oct 2009 14:19:29 +0000 (15:19 +0100)]
Fix a crash when reaching PLY_MAX in a check position

In this case we call evaluate() being in check and this
is not allowed.

Bug found testing with reduced PLY_MAX value as suggested
by Miguel A. Ballicora on talkchess.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoAdd a new rule on promoting pawns in evaluate_passed_pawns()
Marco Costalba [Mon, 12 Oct 2009 06:38:21 +0000 (08:38 +0200)]
Add a new rule on promoting pawns in evaluate_passed_pawns()

Add a rule about the situation when one side queens exactly
one ply before the other. To avoid difficult (but luckly rare)
cases we only handle the case of free paths to queen for
both sides.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix x-ray attack from behind in evaluate_passed_pawns()
Marco Costalba [Sun, 11 Oct 2009 16:30:35 +0000 (18:30 +0200)]
Fix x-ray attack from behind in evaluate_passed_pawns()

Fix a condition for x-ray attack of a queen or
a rook behind a pawn of us. Previous condition does
not check if the enemy slider behind our pawn is
really attacking the pawn.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall cleanup and in evaluate_passed_pawns()
Marco Costalba [Sun, 11 Oct 2009 09:12:53 +0000 (11:12 +0200)]
Small cleanup and in evaluate_passed_pawns()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRevert "Use std::stable_sort() instead of std::sort()"
Marco Costalba [Sun, 11 Oct 2009 08:35:41 +0000 (10:35 +0200)]
Revert "Use std::stable_sort() instead of std::sort()"

Unfortunatly std::stable_sort() implementation in gcc is
horrendously slow. We have a big performance regression on
Linux systems (-20% !)

So revert the commit and wait to fix the issue in a different
way, perhaps with an our home grown sorting, that should be
comparable in speed with std::sort()

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse std::stable_sort() instead of std::sort()
Marco Costalba [Sat, 10 Oct 2009 14:29:43 +0000 (15:29 +0100)]
Use std::stable_sort() instead of std::sort()

Standard does not mandate std::sort() to be stable, so we
can have, and actually do have different node count on
different platforms.

So use the platform independent std::stable_sort() and gain
same functionality on any platform (Windows, Unix, Mac OS)
and with any compiler (MSVC, gcc or Intel C++).

This sort is teoretically slower, but profiling shows only a very
minimal drop in performance, probably due to the fact that
the set to sort is very small, mainly only captures and with
less frequency non-captures, anyhow we are talking of 30-40 moves
in the worst average case. Sorting alghortims are build to work on
thousands or even milions of elements. With such small sets
performance difference seems not noticable.

After 999 games at 1+0

Mod vs Orig +234 =523 -242 -3 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUnroll color loops in evaluate_passed_pawns()
Marco Costalba [Sat, 10 Oct 2009 09:31:43 +0000 (10:31 +0100)]
Unroll color loops in evaluate_passed_pawns()

Speed increase is on 1.5% on Intel pgo build.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse piece_list to scan the pawns in evaluate_pawns()
Marco Costalba [Sat, 10 Oct 2009 06:52:34 +0000 (08:52 +0200)]
Use piece_list to scan the pawns in evaluate_pawns()

No functional change and small speed increase.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix pieceList initialization in Position::clear()
Marco Costalba [Sat, 10 Oct 2009 08:48:02 +0000 (09:48 +0100)]
Fix pieceList initialization in Position::clear()

We want piece list to be terminated with SQ_NONE.

This happens with all the pieces but the pawns that
being 8 make the inner loop exit just before writing
the SQ_NONE value at the tail of the list.

This bug was hidden because currently we don't use
piece list to scan pawns, but this will change in the
future and in any case an initialization should be done
correctly for the whole array to avoid subtle bugs in
the future.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUnroll color loops in get_pawn_info
Marco Costalba [Fri, 9 Oct 2009 11:30:43 +0000 (12:30 +0100)]
Unroll color loops in get_pawn_info

This allow to resolve a lot of addresses at compile time
instead of an indirect access at runtime.

Speed up on pgo compile is of 1.3%

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall micro-optimization in get_pawn_info()
Marco Costalba [Fri, 9 Oct 2009 10:29:11 +0000 (11:29 +0100)]
Small micro-optimization in get_pawn_info()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRestore pliesFromNull counter
Marco Costalba [Fri, 9 Oct 2009 09:08:42 +0000 (10:08 +0100)]
Restore pliesFromNull counter

It is not equivalent because the check for the
50 moves rule get badly affected.

// Draw by the 50 moves rule?
if (st->rule50 > 100 || (st->rule50 == 100 && !is_check()))
    return true;

So we _really_ need two counters.

Thanks to Joona and Tord to be patience with a silly guy ;-)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix an off-by-one bug in extract_pv()
Marco Costalba [Fri, 9 Oct 2009 09:04:55 +0000 (10:04 +0100)]
Fix an off-by-one bug in extract_pv()

In case we reach ply == PLY_MAX we exit the function
writing

pv[PLY_MAX] = MOVE_NONE;

And because SearchStack is defined as:

struct SearchStack {
  Move pv[PLY_MAX];
  Move currentMove;
  .....

We end up with the unwanted assignment

SearchStack.currentMove = MOVE_NONE;

Fortunatly this is harmless because currentMove is not used where
extarct_pv() is called. But neverthless this is a bug that
needs to be fixed.

Thanks to Uri Blass for spotting out this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRewrite previous patch using only one counter
Marco Costalba [Fri, 9 Oct 2009 03:35:11 +0000 (04:35 +0100)]
Rewrite previous patch using only one counter

Use only rule50 and retire pliesFromNull.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDo not claim repetition after null move
Marco Costalba [Wed, 7 Oct 2009 08:03:17 +0000 (09:03 +0100)]
Do not claim repetition after null move

Null moves can artificially create a repetition
draw where instead there is no one.

So use a second counter to reset history after
a null move.

Idea from Joona.

After 999 games at 1+0

Mod vs Orig +238 =553 -208 51.50%  514.5/999  +10 ELO

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRestore development version
Marco Costalba [Wed, 7 Oct 2009 08:21:50 +0000 (09:21 +0100)]
Restore development version

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStockfish 1.5.1
Marco Costalba [Wed, 7 Oct 2009 08:18:45 +0000 (09:18 +0100)]
Stockfish 1.5.1

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix the polling frequency when pondering
Marco Costalba [Thu, 8 Oct 2009 08:09:19 +0000 (09:09 +0100)]
Fix the polling frequency when pondering

When pondering InfiniteSearch == false but myTime == 0 so that
NodesBetweenPolls = 1000 instead of the standard.

The patch fixes the bug and is more robust because checks
directly myTime for a non-zero value, without relying on
an indirect test (InfiniteSearch in this case).

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoUse slightly lower polling frequency in the last few seconds.
Tord Romstad [Thu, 8 Oct 2009 06:55:25 +0000 (08:55 +0200)]
Use slightly lower polling frequency in the last few seconds.

Instead of checking the time every 100 nodes in the last second,
and every 1000 nodes in the last five seconds, Stockfish now checks
every 1000 nodes in the last second and every 5000 nodes in the last
five seconds.  This was tested in 1036 games at a time control of
40 moves/10 seconds, and no losses on time occured.

Also fixed a bug pointed out by Marco:  In infinite mode, myTime
is actually 0, but of course we still don't want to check the time
more frequently than the standard once per 30000 nodes in this
case.

12 years agoMinor change to time management code, to make sure we don't lose on
Tord Romstad [Wed, 7 Oct 2009 16:27:00 +0000 (18:27 +0200)]
Minor change to time management code, to make sure we don't lose on
time at the last move before the time control when there is very
little time left.

12 years agoDisplay fail high/fail low in search log file.
Tord Romstad [Tue, 6 Oct 2009 10:51:15 +0000 (12:51 +0200)]
Display fail high/fail low in search log file.

12 years agoFix bogus comment in extract_pv()
Marco Costalba [Tue, 6 Oct 2009 10:15:05 +0000 (11:15 +0100)]
Fix bogus comment in extract_pv()

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFix use of an initialized SearchStack
Marco Costalba [Tue, 6 Oct 2009 08:10:42 +0000 (10:10 +0200)]
Fix use of an initialized SearchStack

In RootMoveList c'tor we allocate a search stack and then
call directly qsearch.

There is called init_node() that clears all the fields of the search
stack array that refers to current ply but not the the killer moves.

The killer moves cleared correspond to ply+2.

In id_loop() this is not a problem because killer moves of
corresponding ply are cleared anyway few instructions later,
but in RootMoveList c'tor we leave them uninitialized.

This patch fixes this very old bug. It comes direclty
from Glaurung age.

Bug spotted by Valgrind.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoRemove a redundant assignment in PawnInfo c'tor
Marco Costalba [Tue, 6 Oct 2009 08:18:15 +0000 (09:18 +0100)]
Remove a redundant assignment in PawnInfo c'tor

We don't need to set key to 0 because clear() already
takes care of that.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall code reformat in TranspositionTable::extract_pv()
Marco Costalba [Mon, 5 Oct 2009 11:00:35 +0000 (12:00 +0100)]
Small code reformat in TranspositionTable::extract_pv()

In particular don't use an array of StateInfo, this
avoids a possible overflow and is in any case redundant.

Also pass as argument the pv[] array size to avoid a second
possible overflow on this one.

Fix suggested by Joona.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoFixed an embarassing Chess960 bug found by Alexander Schmidt.
Tord Romstad [Mon, 5 Oct 2009 14:46:18 +0000 (16:46 +0200)]
Fixed an embarassing Chess960 bug found by Alexander Schmidt.

It turned out that we used do_move_bb to update the king and rook
bitboards when making and unmaking castling moves, which obviously
doesn't work in Chess960, where the source and destination squares
for the king or rook could be identical.

No functional change in normal chess.

12 years agoRestore development version
Marco Costalba [Mon, 5 Oct 2009 06:15:13 +0000 (07:15 +0100)]
Restore development version

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoStockfish 1.5
Marco Costalba [Sun, 4 Oct 2009 06:01:24 +0000 (07:01 +0100)]
Stockfish 1.5

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoSmall touches to increased mobility patch
Marco Costalba [Sat, 3 Oct 2009 11:25:51 +0000 (13:25 +0200)]
Small touches to increased mobility patch

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoMove a comment where it belongs in SEE
Marco Costalba [Fri, 2 Oct 2009 07:33:26 +0000 (08:33 +0100)]
Move a comment where it belongs in SEE

No functional change of course.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
12 years agoDon't increase mobility if attacked piece is defended by a pawn
Marco Costalba [Wed, 30 Sep 2009 15:04:51 +0000 (16:04 +0100)]
Don't increase mobility if attacked piece is defended by a pawn

If an enemy piece is defended by a pawn don't give the
extra mobility bonus in case we attack it.

Joona says that "Paralyzing pawn" is usually worth of nothing.

On Joona QUAD after 964 games:
Orig - Patch_2: 191 - 218 - 555 (+ 10 elo)

On my PC after 999 games at 1+0:
Mod vs Orig +227 =550 -222 50.25%  502.0/999  +2 ELO

In both cases we tested against the original version (without
increased mobility), not against the previous patch that instead
seems to fail on Joona QUAD:
Orig vs. Prev.Patch: 237 - 217 - 627 (-6 elo)

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