stockfish
13 years agoDo not use evaluate() for razoring
Marco Costalba [Tue, 23 Sep 2008 11:03:44 +0000 (13:03 +0200)]
Do not use evaluate() for razoring

Because razoring is reached 10% of times and about 50% of time
first two conditions are met we can save 5% of calls to the fairly
costly evaluate().

On the other side statistics have shown 95% of nodes that pass
the first two razoring conditions pass also the evaluate() test.
So the risk of dropping the third condition seems low enough.

Testing seems to validate this.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoinit_eval: small cleanup
Marco Costalba [Mon, 22 Sep 2008 11:22:36 +0000 (13:22 +0200)]
init_eval: small cleanup

Functionality not changed.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFix InitKingDanger initialization
Marco Costalba [Mon, 22 Sep 2008 10:10:09 +0000 (12:10 +0200)]
Fix InitKingDanger initialization

Last line was missing.

Also reformat tables constants to be more readable.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoOptimize pop_1st_bit() take 2
Marco Costalba [Sun, 21 Sep 2008 21:13:03 +0000 (22:13 +0100)]
Optimize pop_1st_bit() take 2

This time we use MSVC intrinsics that are
C wrappers for Intel assembler 'bsf' instruction.

The speed up in node count is around 3%, probably
it does not worth the effort. Anyway this patch
can be useful at least for documentation purposes.

This optimization covers 32 bit systems only.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoChange the name to Glaurung clone
Marco Costalba [Sun, 21 Sep 2008 09:51:38 +0000 (11:51 +0200)]
Change the name to Glaurung clone

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoSwitch to developer version numbering
Marco Costalba [Sun, 21 Sep 2008 08:16:50 +0000 (09:16 +0100)]
Switch to developer version numbering

Also clean up code while there.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoUse optimized pop_1st_bit() only under Windows
Marco Costalba [Sat, 20 Sep 2008 20:19:54 +0000 (22:19 +0200)]
Use optimized pop_1st_bit() only under Windows

Under Linux we have a segfault after a random time,
about a couple of minutes while running the benchmark.

This happens both with gcc and icc, and both with O2
and O3 optimizations.

Disable for Linux until we understand what's the deal.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoAdd new superlinear interpolator
Marco Costalba [Sat, 20 Sep 2008 18:55:52 +0000 (19:55 +0100)]
Add new superlinear interpolator

Faster transition and between phases and
more persistent during mid and ending game.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFinally remove last old C style I/O stuff
Marco Costalba [Fri, 19 Sep 2008 19:36:16 +0000 (20:36 +0100)]
Finally remove last old C style I/O stuff

Now I/O is fully done with C++ iostreams.

The only exception is in non-windows version
of Bioskey() in misc.cpp

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoConvert book.cpp to use C++ I/O
Marco Costalba [Fri, 19 Sep 2008 12:37:28 +0000 (13:37 +0100)]
Convert book.cpp to use C++ I/O

Instead of old C stdio.h

Also small code clean up while there.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFinal touches to pop_1st_bit optimization
Marco Costalba [Fri, 19 Sep 2008 03:33:55 +0000 (05:33 +0200)]
Final touches to pop_1st_bit optimization

This final version is a little bit faster then
previous patch and is a bit cleaned up also.

On 32 bit x86 pop_1st_bit is now more then
two times faster then the original one that
is optimized for 64 bit processors.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoOptimize pop_1st_bit() on 32 bits x86
Marco Costalba [Thu, 18 Sep 2008 14:09:19 +0000 (16:09 +0200)]
Optimize pop_1st_bit() on 32 bits x86

Operations on 64 bits Bitboard types are slow
on x86 compiled with gcc, so optimize this case.

BTW profiling shows that pop_1st_bit() is a
veeery performance critical path!

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoIgnore non keyboard events in Bioskey()
Marco Costalba [Thu, 18 Sep 2008 10:46:48 +0000 (11:46 +0100)]
Ignore non keyboard events in Bioskey()

Filter out mouse and windows type events.

This fix an issue where Glaurung hangs in console mode
under Windows.

To reproduce simply open a console under Windows (cmd.exe),
run "glaurung.exe bench 50 1", this starts benchmarking.
Then hide the windows and show again or clik the mouse
somewhere on the window, this hangs the benchmark
because Boiskey() returns true and poll() calls std::getline()
that hangs waiting for user pressing a return key.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoCleanup poll()
Marco Costalba [Thu, 18 Sep 2008 09:34:19 +0000 (10:34 +0100)]
Cleanup poll()

Reshape this function in preparation
for future work.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoImprove time managment
Marco Costalba [Thu, 18 Sep 2008 09:32:12 +0000 (10:32 +0100)]
Improve time managment

If we need some more and we are in time
advantage take it.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoPass also opponent time to think()
Marco Costalba [Thu, 18 Sep 2008 09:31:01 +0000 (10:31 +0100)]
Pass also opponent time to think()

This patch modifies think() signature to accept
also opponent time. This is needed for future
changes to time managment.

Still no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoDisable a stupid and noisy MSVC warning
Marco Costalba [Thu, 18 Sep 2008 09:29:26 +0000 (10:29 +0100)]
Disable a stupid and noisy MSVC warning

Remove the crap from compiler messages.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoTeach Benchmark to read positions from a file
Marco Costalba [Thu, 18 Sep 2008 08:55:35 +0000 (09:55 +0100)]
Teach Benchmark to read positions from a file

This comes handy to test the engine on different
sets of positions, not only the 15 default ones.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoReformat benchmark interface
Marco Costalba [Thu, 18 Sep 2008 08:54:44 +0000 (09:54 +0100)]
Reformat benchmark interface

Prepare to following patches, still no functional
change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFix another conversion warning: Bitboard->int
Marco Costalba [Thu, 18 Sep 2008 08:53:53 +0000 (09:53 +0100)]
Fix another conversion warning: Bitboard->int

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoDocument where we want a uint16_t instead of a uint64_t
Marco Costalba [Thu, 18 Sep 2008 08:53:14 +0000 (09:53 +0100)]
Document where we want a uint16_t instead of a uint64_t

This patch removes some conversion warnings and
better describe where we are going to expect a
small integer.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoUse size_t instead of int
Marco Costalba [Thu, 18 Sep 2008 08:52:09 +0000 (09:52 +0100)]
Use size_t instead of int

Remove some warning.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoMovePicker: simplify move swapping
Marco Costalba [Thu, 18 Sep 2008 08:51:24 +0000 (09:51 +0100)]
MovePicker: simplify move swapping

We don't need a full swap here because once found
and returned the best move will not be used again.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoPrefer strncpy() to strcpy()
Marco Costalba [Thu, 18 Sep 2008 08:49:54 +0000 (09:49 +0100)]
Prefer strncpy() to strcpy()

This removes a warning under MSVC++

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFix: "Ponder" option has type bool not int
Marco Costalba [Thu, 18 Sep 2008 08:48:56 +0000 (09:48 +0100)]
Fix: "Ponder" option has type bool not int

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoSpace inflate sp_search_pv
Marco Costalba [Tue, 9 Sep 2008 09:37:27 +0000 (11:37 +0200)]
Space inflate sp_search_pv

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoSpace inflate sp_search
Marco Costalba [Tue, 9 Sep 2008 09:15:58 +0000 (11:15 +0200)]
Space inflate sp_search

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoUse TT in qsearch
Marco Costalba [Tue, 9 Sep 2008 05:37:46 +0000 (07:37 +0200)]
Use TT in qsearch

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agosearch: fix a bug and clear history update
Marco Costalba [Sun, 7 Sep 2008 07:38:19 +0000 (09:38 +0200)]
search: fix a bug and clear history update

When a move produces a beta-cut off is marked as
success in history and all the remaining ones are
marked as failures.

The loop across the searched moves, that is used
to register failures, does not skip the good one,
that is then registered as a failure too.

The patch fixes the bug and cleanup the code.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoSpace inflate qsearch
Marco Costalba [Sun, 7 Sep 2008 06:31:30 +0000 (08:31 +0200)]
Space inflate qsearch

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoSpace inflate search()
Marco Costalba [Sat, 6 Sep 2008 16:25:58 +0000 (18:25 +0200)]
Space inflate search()

Same as previous patch but for search() function.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agosearch_pv: spaces inflate
Marco Costalba [Sat, 6 Sep 2008 15:12:39 +0000 (17:12 +0200)]
search_pv: spaces inflate

It seems easier to understand, at least to me.

Hopefully no functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoSplit transposition table lookup in a separate function
Marco Costalba [Sat, 6 Sep 2008 13:53:43 +0000 (15:53 +0200)]
Split transposition table lookup in a separate function

This slims down the code and is a prerequisite for
future patches.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoTranspositionTable: add first_entry() helper
Marco Costalba [Sat, 6 Sep 2008 10:30:07 +0000 (12:30 +0200)]
TranspositionTable: add first_entry() helper

An inline function to retrieve the first TT entry
given a position.

Plus usual whitespace noise.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoAdd simple debug hit rate counter
Marco Costalba [Sat, 6 Sep 2008 10:22:10 +0000 (12:22 +0200)]
Add simple debug hit rate counter

Add a very simple debug framework to
measure the hit rate of a given condition.

Simply insert macro

dbg_hit_on(x);

Anywhere you want to compute hit rate of condition x
and then call, as example in poll(), function
dbg_print_hit_rate() to print current results.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoTranspositionTable: micro optimize first cycle
Marco Costalba [Sat, 6 Sep 2008 10:21:08 +0000 (12:21 +0200)]
TranspositionTable: micro optimize first cycle

In the common case (>95%) tte == replace so skip
additional comparisons in this case.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoTranspositionTable: early skip on an empty TT entry
Marco Costalba [Sat, 6 Sep 2008 10:20:28 +0000 (12:20 +0200)]
TranspositionTable: early skip on an empty TT entry

Instead of going for the whole 4 cycle loop early
skip if TT entry is empty.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoTranspositionTable: spaces inflate
Marco Costalba [Sat, 6 Sep 2008 10:19:29 +0000 (12:19 +0200)]
TranspositionTable: spaces inflate

No functional change, just a tidy up in
preparation for next patches.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoRootMoveList: inline trivial accessors
Marco Costalba [Sat, 6 Sep 2008 04:37:00 +0000 (06:37 +0200)]
RootMoveList: inline trivial accessors

Although not performance critical, trivial
accessors can be inlined without any harm.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoRootMoveList sorting: be compatible with std::sort
Marco Costalba [Fri, 5 Sep 2008 07:04:45 +0000 (09:04 +0200)]
RootMoveList sorting: be compatible with std::sort

sort() and sort_multipv() are almost the same, so
use only one implementation.

Also introduce the natural RootMove::operator<() to
compare the moves instead of compare_root_moves(),
this will allow to use std::sort instead of our
home grown bubble-sort.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoscan_for_easy_move: we don't need a loop here
Marco Costalba [Wed, 3 Sep 2008 21:33:49 +0000 (23:33 +0200)]
scan_for_easy_move: we don't need a loop here

Moves are already sorted, so just consider the best
and the second one.

Some trailing whitespace remove noise crept in due
to my editor removes it before to save.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoBetter document RootMoveList c'tor
Marco Costalba [Wed, 3 Sep 2008 21:29:04 +0000 (23:29 +0200)]
Better document RootMoveList c'tor

Also some code tidy-up.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFix a couple of bugs (fallout from previous patches)
Marco Costalba [Mon, 1 Sep 2008 20:05:23 +0000 (22:05 +0200)]
Fix a couple of bugs (fallout from previous patches)

After testing and comparing output with standard Glaurung
a couple of issues arised.

A default value was wrong and init_uci_options() missed a couple
of stringify() calls. Also storing bool values as "false" and "true"
needs some care.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoucioptions: Fix stringification of a bool
Marco Costalba [Mon, 1 Sep 2008 14:58:02 +0000 (16:58 +0200)]
ucioptions: Fix stringification of a bool

We want stringify a bool as "true" and "false",
not "1" and "0".

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoPreserve options order when printed
Marco Costalba [Mon, 1 Sep 2008 14:03:01 +0000 (16:03 +0200)]
Preserve options order when printed

Use a vector instead of a map so that options
are printed according to their original order.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoRewrite ucioptions.cpp to use C++
Marco Costalba [Mon, 1 Sep 2008 12:05:02 +0000 (14:05 +0200)]
Rewrite ucioptions.cpp to use C++

Instead of old-style C string functions use standard
library to greatly streamline the implementation.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoFinally remove UCIInputParser class altogether
Marco Costalba [Mon, 1 Sep 2008 06:16:17 +0000 (08:16 +0200)]
Finally remove UCIInputParser class altogether

Class UCIInputParser is now a typedef of a std::istringstream,
this greatly simplifies the code, especially the many conversions
from string to integer are now handled automatically by the
stream instead of relying on a chunk of C-style atoi() calls.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoUse a string stream in UCIInputParser
Marco Costalba [Mon, 1 Sep 2008 06:06:34 +0000 (08:06 +0200)]
Use a string stream in UCIInputParser

Use a std::istringstream instead of an home
grown string tokenizer code.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoAvoid casts to handle isspace() arguments
Marco Costalba [Mon, 1 Sep 2008 06:03:21 +0000 (08:03 +0200)]
Avoid casts to handle isspace() arguments

Use proper standard conversion to deal
with negative values of a char.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
13 years agoInitial import of Glaurung 2.1
Marco Costalba [Mon, 1 Sep 2008 05:59:13 +0000 (07:59 +0200)]
Initial import of Glaurung 2.1