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

2305 commits

Author SHA1 Message Date
Marco Costalba
41561c9bb8 Use std::vector<Thread*> to store threads
We store pointers instead of Thread objects because
Thread is not copy-constructible nor copy-assignable
and default ones are not suitable. So we cannot store
directly in a std::vector.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 10:23:52 +01:00
Marco Costalba
553655eb07 Refactor Thread class
Associate platform OS thread to the Thread class instead of
creating it from ThreadsManager.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 10:23:51 +01:00
Marco Costalba
f01b53c374 Refactor ThreadsManager::set_size() functionality
Split the data allocation, now done (mostly once)
in read_uci_options(), from the wake up and sleeping
of the slave threads upon entering/exiting the search.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 10:23:49 +01:00
Marco Costalba
8ec421fa14 Revert "Don't sync with C library I/O buffers"
It seems is the cause of strange and rare hangs
reported by some users where Stockfish stops
responding to GUI. It is not clear why but for
the moment revert the patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 10:23:16 +01:00
Marco Costalba
11b0c7b44a Don't ceil cpu_count()
It is already done at calling site where it is
more appropiate.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-25 09:57:33 +01:00
Marco Costalba
f8224fc7d3 Fix a MSVC warning
Not correct warning about use of an uninitialized
variable. The warning is not correct becuase we can
never reach the warned code when in SpNode, anyhow
the fix is simple.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-24 10:14:21 +01:00
Marco Costalba
b356e0fae3 Rename lock.h to platform.h
And move some more platform specific code there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-24 10:05:17 +01:00
Marco Costalba
06f33ff1ee Remove last platform specific code form thread.cpp
A somewhat tricky function pointer cast allows us
to move the platform specifics to lock.h, the cast
is tricky because return type is not the same of the
casted function in Linux (for Windows return type is
a DWORD that is a long) but this should not be a
problem as long as the size is the same;

From: http://stackoverflow.com/questions/188839/function-pointer-cast-to-different-signature

"OpenSSL was only casting functions pointers to
other function types taking and returning the same
number of values of the same exact sizes, and this
(assuming you're not dealing with floating-point)
happens to be safe across all the platforms and
calling conventions I know of. However, anything
else is potentially unsafe."

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-23 19:28:20 +01:00
Marco Costalba
c47a74ec62 Merge two loops in ThreadsManager::init()
In analogy with ThreadsManager::exit()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-22 22:40:04 +01:00
Marco Costalba
e26d13bb31 Use a local copy of tte->value()
This should avoid some aliasing issues
with TT table access.

After 3913 games at 10"+0.05
Mod vs Orig 662 - 651 - 2600  ELO +0 (+- 6.4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-22 19:32:30 +01:00
Gary Linscott
f41a21fefd Penalty for undefended rook as well 2012-03-22 07:33:47 -04:00
mcostalba
d4c9abb967 Merge pull request #8 from glinscott/master
Optimize undefended minor check. Little editing by
me, no change even at assembly level.

No regression after 8K games at fast TC on a 64bit CPU.
2012-03-22 07:49:11 +01:00
Gary Linscott
d1e18fc7dd Optimize undefended minor check. 2012-03-21 08:19:21 -04:00
Gary Linscott
3c6a4bfbed Penalize undefended minors
Even if not under attack. This seems to be good
especially on openings.

After 12112 games at 10"+0.05
Mod vs Orig 2175 - 1997 - 7940 ELO +5 (+- 3.7)

[Patch series from Gary, little edited by me]

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-21 08:00:57 +01:00
Marco Costalba
3b7dbc4f6d Fix Logger under MSVC iostream libraries
We need splitted Tie classes because MSVC stream library
takes a lock on buffer both on reading and on writing and
this causes an hang because, while searching, the I/O
thread is locked on getline() and when main thread is
trying to std::cout() something it blocks on the same
lock waiting for I/O thread getting some input and
releasing the lock.

The solution is to use separated streambuf objects for
cin and cout.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-20 21:46:08 +01:00
Marco Costalba
17d1940278 Remove cruft from Logger class
A big code simplification and cruft removing, make
Logger class a singleton and fully self conteined.
Also add direction indicators (">>" and "<<") to
better differentiate input and output lines in the
log file.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-20 19:24:52 +01:00
Marco Costalba
258da28e79 Better on_change() argument name
Using "o" as a parameter with the on_xxx(const UICOption& o)
functions is a bit dangerous because of confusion with "0".

Suggested by Rein Halbersma.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-20 07:09:58 +01:00
Marco Costalba
df80232495 Add also logging of std::cin
Some trial was needed to find the correct recipe but now
we log both stdin and stdout to file "io_log.txt".

Link http://spec.winprog.org/streams/ was very useful
to understand the details of iostreams implementation.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-19 21:59:25 +01:00
Marco Costalba
eb28a683bd Add (smart) logging facility
By means of "Use Debug Log" UCI option it is possible to toggle
the logging of std::cout to file "out.txt" while preserving
the usual output to stdout. There is zero overhead when logging
is disabled and we achieved this without changing a single line
of exsisting code, in particular we still use std::cout as usual.

The idea and part of the code comes from this article:
http://groups.google.com/group/comp.lang.c++/msg/1d941c0f26ea0d81

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-18 23:10:24 +01:00
Marco Costalba
2dfc94e0b6 Show startup messages immediately
In particular before initialization. So that SF
seems more snappy at startup.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-18 23:10:18 +01:00
Marco Costalba
7bc3688714 Revert to byTypeBB[0] storing occupied squares
As it was in Glaurung times. Also rearranged order
so that byTypeBB[0] is accessed before byTypeBB[x]
to be more cache friendly. It seems there is even
a small speedup.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-18 12:02:23 +01:00
Marco Costalba
fc3ea7365a Rename occupied_squares() to pieces()
Also some microoptimizations, were there from ages
but hidden: the renaming suddendly made them visible!

This is a good example of how better naming lets you write
better code. Naming is really a kind of black art!

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-18 11:18:38 +01:00
Marco Costalba
55376219b7 UCI buttons don't need a value
Take advantage of this to further simplify the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-17 21:44:50 +01:00
Marco Costalba
9b26356347 Don't use "OwnBook" by default
Stick to UCI protocol that says:

* by default all the opening book handling is done by the GUI,
  but there is an option for the engine to use its own book
  ("OwnBook" option, see below)

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-17 13:16:51 +01:00
Marco Costalba
7c8a8e038f Retire "ucinewgame" UCI option
UCI protocol it is not clear about what the engine
should be supposed to do when "ucinewgame" is
received. Stockfish simply sets the position to
start FEN, but it is redundant becuase the GUI always
resends the position after "ucinewgame" command, so
it seems we can safely ignore that command.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-17 11:24:19 +01:00
Marco Costalba
ee838f56f7 Fix UCI 'button' options
When a button fires UCIOption::operator=() is called and from
there the on_change() function. Now it happens that in case of
a button the on_change() function resets option's value to
"false" triggering again UCIOption::operator=() that calls again
on_change() and so on in an endless loop that is experienced
by the user as an application hang.

Rework the button logic to fix the issue and also be more clear
about how button works.

Reported by several people working with Scid and tracked down
to the "Clear Hash" UCI button by Steven Atkinson.

Bug recently introduced by 2ef5b4066e.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-17 10:35:01 +01:00
Marco Costalba
9934b8ec31 Don't sync with C library I/O buffers
Now we are forced to just use C++ iostream becuase
buffers are independent and using C library functions
like printf() or scanf() could yield to issues.

Speed up of about 1%.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-12 19:34:19 +01:00
Marco Costalba
3dccdf5b83 Fix time_to_msec() precision
Result of t.time * 1000 should be a 64 bit value, not an int.

Bug reported by several users.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-10 19:38:56 +01:00
Marco Costalba
4220f191d8 Introduce Eval namespace
Wrap evaluation related stuff and reshuffle
a bit the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-07 07:39:01 +01:00
Marco Costalba
843a5961e1 Double pinner bonus
Fine tune newly introduced pinner bonus score:

After 34696 games at 2"+0.05
Mod vs Orig 7474 - 7087 - 20135 ELO +3 (+- 2.4)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-07 07:31:43 +01:00
Marco Costalba
d8e56cbe54 Convert init of eval to async option
So to be done only once at startup and in the (unlikely)
cases that a relevant UCI parameter is changed, instead
of doing it at the beginning of each search.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-06 19:21:00 +01:00
Marco Costalba
2ef5b4066e Async UCI options actions
Introduce 'on change' actions that are triggered as soon as
an UCI option is changed by the GUI. This allows to set hash
size before to start the game, helpful especially on very fast
TC and big TT size.

As a side effect remove the 'button' type option, that now
is managed as a 'check' type.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-05 19:20:07 +01:00
Marco Costalba
482b5b7ece Use new Time class in timed_wait()
And simplify the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-05 19:18:46 +01:00
Marco Costalba
19540c9ee8 Introduce single_bit() helper
Self-documenting code instead of a tricky
bitwise tweak, not known by everybody.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-04 23:37:44 +01:00
Marco Costalba
cf0561d31a Introduce pinning bonus
Add a bonus if a slider is pinning an enemy piece.
Idea from Critter.

After 27443 games at 2"+0.05
Mod vs Orig 5900 - 5518 - 16025 ELO +4 (+- 2.7)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-04 23:01:31 +01:00
Marco Costalba
161c6b025e Rewrite time measurement code
Introduce and use a new Time class designed after
QTime, from Qt framework. Should be a more clear and
self documented code.

As an added benefit we now use 64 bits internally to get
millisecs from system time. This avoids to wrap around
to 0 every 2^32 milliseconds, which is 49.71 days.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-03-03 18:01:39 +01:00
Marco Costalba
b966adf103 Halve rook on open file bonus for endgame
After 42206 fast games TC 2"+0.05
Mod vs Orig 12871 - 16849 - 12486 ELO +3 (+- 2.6)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-29 06:20:48 +01:00
Marco Costalba
c2a68708ef Fix a shift overflow warning
Visual Studio 11 is worried that shift result could
overflow an integer, this is impossible becuase max
value of the shift is 4, but compiler cannot know it.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-27 20:32:41 +01:00
Marco Costalba
34178205fc Micro-optmize castling moves
Pre compute castle path so to quickly test
for impeded rule.

This speeds up perft on starting position
of more than 2%.

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-27 19:44:04 +01:00
Marco Costalba
5bb766e826 Rename promotion_piece_type() to promotion_type()
Shorter and equally clear to understand.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-26 18:39:53 +01:00
Marco Costalba
96eefc4af6 Introduce another two (bitboard,square) operators
And simplify the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-26 18:39:40 +01:00
Marco Costalba
8751b18cf0 Fix MSVC warning on streampos to size_t conversion
Fix this warning with MSVC 64 bits:

warning C4244: '=' : conversion from 'std::streampos' to 'size_t',
possible loss of data

Point is that std::streampos could be negative, while size_t
is always non-negative.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-26 12:05:37 +01:00
Marco Costalba
2608b9249d Retire ss->bestMove
And introduce SPlitPoint bestMove to pass back the
best move after a split point.

This allow to define as const the search stack passed
to split.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-21 20:31:22 +01:00
Marco Costalba
43f84efa15 Don't update bestValue in check_is_dangerous()
It is a prerequisite for next patch and simplifies
the function. testing at ultra fast TC shows no
regression.

After 24302 games at 2"+0.05
Mod vs Orig 5122 - 5038 - 13872 ELO +1 (+- 2.9)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-21 20:29:05 +01:00
Marco Costalba
ea5616785e Fix a wrong check in pos_is_ok()
Bug introduced by revision a44c5cf4f7
of 3/12/2011.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-20 19:34:43 +01:00
Marco Costalba
6a48325c49 Further simplify castling rights
Reverse the meaning of castleRightsMask[sq] so that now
is stored the castling right that will be removed in
case a move starts from or arrives to sq square. This
allows to simplify the code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-20 19:20:13 +01:00
Marco Costalba
50edb7cd73 Spread usage of pos.piece_moved()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-19 12:20:29 +01:00
Marco Costalba
4aadd1e401 Retire empty_squares()
Use ~pos.occupied_squares() instead and avoid to
hide the ~ computation.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-19 11:50:50 +01:00
Marco Costalba
ec5b9994b5 Index en-passant zobrist keys by file
Instead of by square. This is a more conventional
approach, as reported also in:

http://chessprogramming.wikispaces.com/Zobrist+Hashing

We shrink zobEp[] from 64 to 8 keys at the cost of an extra
'and 7' at runtime to get the file out of the ep square.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-19 11:31:36 +01:00
Marco Costalba
3441e0075d Move some stuff out of lock protection in split()
We shouldn't need lock protection to increment
splitPointsCnt and set curSplitPoint of masterThread.

Anyhow because this code is very tricky and prone to
races bound the change in a single patch.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2012-02-19 10:32:38 +01:00