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

149 commits

Author SHA1 Message Date
Marco Costalba
145c9d943b Improve TBFile API
Do more work inside TBFile::map() and
simplify the init functions.
2016-04-27 09:01:08 +02:00
Marco Costalba
0fcc2addd1 First attempt at WDLEntry::init()
Still a lot to do...
2016-04-26 20:45:51 +02:00
Marco Costalba
e480cc108a Rearrange DTZ struct
Redefine some fields in a more consistent way.
2016-04-26 18:13:31 +02:00
Marco Costalba
91b9463ec3 Inline a bunch of single-use functions
This is a first step to cleanup that part of
initialization code.

Apparently init functions are harder to read now,
but this is only temporary: this is a prerequisite
for future work.

As a side benefit we can now get rid of the ancillary
struct and define them directly in teh main ones, even
using anonymous structs!
2016-04-26 17:53:19 +02:00
Marco Costalba
d91b6f9a17 Remove pointer usage in init() members
Now that these functions are struct
members, we don't need to use pointers
anymore.
2016-04-26 14:21:02 +02:00
lucasart
a9abb35c9c Constructed objects must be destructible
Pointer members of WDLEntry and DTZEntry must be null, so they can be freed.

Whether unmap() behaves like free() and tolerates a NULL pointer (treated as
no-op) is unclear. Better safe than sorry, so test data before calling unmap().

Simplify hasUniquePieces calculation while at it.

No functional change.
2016-04-26 13:46:14 +02:00
Marco Costalba
578e94629b Add DTZEntry constructor
And sync WDL and DTZ initializations
2016-04-26 12:09:37 +02:00
Marco Costalba
3104915cd1 Add WDLEntry constructor 2016-04-26 09:58:13 +02:00
Marco Costalba
bb9d42f425 Rename structs
Use a more consistent naming convention
2016-04-26 09:27:37 +02:00
Marco Costalba
9e24e68419 Add struct destructors
Avoid explicitly freeing the objects.

Because d'tor involves file unmapping, some
care must be taken to avoid accidentaly destroy
the object (even temporarly), for instance when
reordering the list.

As a side effect, we can now restore the original
main.cpp, fully in sync with master branch.
2016-04-26 09:13:27 +02:00
Marco Costalba
c7c4ab8186 Get rid of DTZEntryList
It is just an intermediate struct, use DTZEntry directly.

This allow us to remove a malloc ad simplify freeing.

Confirmed with Valgrind there are no memory leaks.
2016-04-25 14:43:28 +02:00
Marco Costalba
d3f748c285 Get rid of wild struct aliasing casting
Super big patch that completely rewrite
data layout to avoid casting of pointer
back and forth different structs.

Unfortunatly it is not possible to write
the patch in small steps because all the
data structs where deeply mixed and once
you touch one part you need to chaneg also
the others.

Functionality s unchanged and this is already
a big success, now we have a proper base above
which to di further clean up work.

Verified with Valgrind there are no memory leaks.
2016-04-25 10:43:57 +02:00
Marco Costalba
10b11da913 Restore back DTZ_list size limit
We will remove it when we will have
a better understanding of the code base,
for now just stick to the original
functionality.
2016-04-25 09:01:33 +02:00
Marco Costalba
4119955044 Get rid of get_key()
And also of namespace Zobrist: there is no more need
for TB code to look at Position's internals.
2016-04-24 21:46:06 +02:00
Marco Costalba
fe6ba8d805 Retire load_dtz_table() 2016-04-24 20:49:07 +02:00
Marco Costalba
637f5b5ecb Convert DTZ_table to a std::list
Because it is used as a list, with a LRU
replacement policy and LRU enries order.

Also drop the hardcoded limit on max 64 entries.
2016-04-24 18:50:06 +02:00
Marco Costalba
216e8cc195 Get rid of fixed size array
Use std::deque instead because it preserves references
to its elements when resizing (std::vector does not).

DTZ_table is still an array because it seems its size
is fixed and does not depend on TB exsisting files.
2016-04-24 14:33:41 +02:00
Marco Costalba
1a8e0416bb Document encode_piece
Retire Flipdiag[] while there
2016-04-24 14:07:13 +02:00
Marco Costalba
39e4398133 Retire probe_dtz() from Tablebases
It is not needed in SF.
2016-04-24 12:40:29 +02:00
Marco Costalba
7aeef7285f Sync with master 2016-04-24 11:55:44 +02:00
Marco Costalba
9bf2a9f842 Add a FIXME on the odd probe_ab()
Given a position probe_ab() does a kind of qsearch,
but instead of evaluating the position at the begin,
through a table look up, it performs a depth-first
search and only at the end checks for current position
score.
2016-04-24 11:47:59 +02:00
lucasart
d434fc465b Use Square instead of int
No functional change.
2016-04-24 07:41:21 +02:00
lucasart
3771db79eb Use File instead of int
No functional change.
2016-04-24 07:41:21 +02:00
lucasart
eb484823d7 Document enc_type
No functional change.
2016-04-24 07:41:21 +02:00
Marco Costalba
63b39c5bff Use SF Position to calculate material key
Don't reinvent the wheel.

Also clarify that init_tb it is used to
populate TBHash: rename it in proper way.
2016-04-23 23:05:22 +02:00
Marco Costalba
024fec7a2b Drop another couple of define
And simplify file name extarction function
2016-04-23 13:14:24 +02:00
Marco Costalba
a14fa77ede Free Tablebases before to exit
Fix valgrind errors.
2016-04-23 12:20:07 +02:00
Marco Costalba
7bc5946fc9 Clean up decompress_pairs
Also replace platform specific byte swap with
a software version. Amazingly it seems it is
even faster now!

Also removing the templatized form does not slow down.
2016-04-23 11:52:51 +02:00
Marco Costalba
5414eaba35 Introduce WDLScore
Start to add some type safety above naked int

Improve code self-documenting readibility as well.
2016-04-22 09:23:36 +02:00
lucasart
b82f6dabcc Assorted cleanup
No functional change.
2016-04-22 10:20:37 +08:00
Marco Costalba
c6e96881ca Cleanup probe_wdl_table()
Memory barrier is totally unused inside a locked scope.
2016-04-21 22:23:34 +02:00
Marco Costalba
8db35c8a5f Rework hash table access 2016-04-21 22:01:11 +02:00
Marco Costalba
b4985de966 Assorted formatting 2016-04-21 22:01:10 +02:00
lucasart
f4c930e038 Additional work in init_tb()
* document 0x38

* remove useless enc_type

For whatever reason (?), syzygy tables have the information to play a stupid
chess variant that (apparently) can result in having only 1 King on the board
instead of 2. Obviously, we do not care about this "game" which is neither
Chess, nor Chess960, so get rid of that useless code.

No functional change.
2016-04-21 22:00:39 +02:00
Marco Costalba
6b5a350bc3 Merge cpp files
* Properly include tbcore.cpp

* Merge *cpp files

* Additional reshuffle and consolidation

* Cosmetic touch

- run: astyle -A3 -s4 -f -xn -xc -xl *.cpp *.h. Mainly this breaks blocks (if,
  do, while, for etc.)

- remove static_cast<>: inconsistently used, and ugly. Prefer C-style cast.
  Eventually, the code will be rewritten so that less casting is needed...

No functional change.
2016-04-21 06:40:27 +02:00
Marco Costalba
8a3569f667 Platform agnostic file functions (#643)
Platform agnostic file functions

Reduce the platform specific code to bare minimum
and localize all in a single place.
2016-04-20 15:12:32 +02:00
Marco Costalba
be45c212cd Avoid encode/decode madness in init_tb (#641)
* Avoid encode/decode madness in init_tb

We encode pieces in a string passed to init_tb() that
just decodes the exactly same string to get the pieces back!

Sanitize this madness.

No functional change.

* Further cleanup init_tb

* Avoid useless intermediate conversions of TB paths

In many cases original information is converted to
an intermediate form to be then further used later.

In many cases this intermediate form is useless and
the original information can be used directly instead.

This patch removes a typical case.

Also simplified open_tb() signature.

* Address some Lucas review comments
2016-04-19 15:19:42 +02:00
lucasart
8609c4ece4 use std::sort() (#640)
No functional change.
2016-04-18 15:13:03 +02:00
lucasart
a037e20f28 Syzygy pull (#639)
* factorize repetitive code in calc_key() and calc_key_from_pcs()

and do some cleanup while at it.

* sync with master

No functional change.
2016-04-18 14:08:23 +02:00
Marco Costalba
7eaea3848c StateInfo is usually allocated on the stack by search()
And passed in do_move(), this ensures maximum efficiency and
speed and at the same time unlimited move numbers.

The draw back is that to handle Position init we need to
reserve a StateInfo inside Position itself and use at
init time and when copying from another Position.

After lazy SMP we don't need anymore this gimmick and we can
get rid of this special case and always pass an external
StateInfo to Position object.

Also rewritten and simplified Position constructors.

Verified it does not regress with a 3 threads SMP test:
ELO: -0.00 +-12.7 (95%) LOS: 50.0%
Total: 1000 W: 173 L: 173 D: 654

No functional change.
2016-04-17 08:29:33 +02:00
lucasart
9173d29c41 syzygy clean-up + unit test 2016-04-16 22:59:39 +01:00
mstembera
8fb45caade Simplify popcnt
Also a speedup(about 1%) on 64-bit w/o hardware popcnt

Retire Max15 and Full template parameters
(Contributed by Marco Costalba)

Now that we have just SW and HW versions, use
template default parameter to get rid of explicit
template parameters.

Retire bitcount.h and move the only defined
function to bitboard.h

No functional change

Resolves #620
2016-04-08 18:52:15 +01:00
mstembera
46b5a5f0db Fix syzygy en passant issue
v = value without ep capture being considered
v1 = value of the ep capture

The correct logic is:
if without e.p. capture we are losing, and the value of e.p is either draw, or win or "loss, but 50 move rule saves us", then we should use the value of ep capture.

Credit and thanks to syzygy1 and lantonov !

No functional change (except with syzygy bases)

Resolves #415
Resolves #394
2015-09-06 22:19:33 +01:00
lucasart
dc13004283 Compute checkers from scratch
This micro-optimization only complicates the code and provides no benefit.
Removing it is even a speedup on my machine (i7-3770k, linux, gcc 4.9.1):

stat        test     master    diff
mean   2,403,118  2,390,904  12,214
stdev     12,043     10,620   3,677

speedup       0.51%
P(speedup>0) 100.0%

No functional change.
2015-02-15 12:11:05 +01:00
Marco Costalba
712bbb052e Fix compile error with MSVC 2013
Without this std::min chokes with windows 'min' macro.

No functional change.
2015-01-18 15:14:05 +01:00
Gary Linscott
7b4828b68c Only use _ReadWriteBarrier on MSVC
It was causing compile errors when cross-compiling using mingw.

No functional change.
2014-12-11 14:56:24 -05:00
Gary Linscott
afafdf7b73 MSVC compiling fixes
No functional change.

Resolves #150
2014-12-11 13:03:44 -05:00
Marco Costalba
ba1464751d Explicitly pass RootMoves to TB probes
Currently Search::RootMoves is accessed and even
modified by TB probing functions in a hidden
and sneaky way.

This is bad practice and makes the code tricky.
Instead explicily pass the vector as function
argument so to clarify that the vector is modified
inside the functions.

No functional change.
2014-12-06 15:08:21 +00:00
Ronald de Man
7caa6cd338 Syzygy tablebases
Adds support for Syzygy tablebases to Stockfish.  See
the Readme for information on using the tablebases.

Tablebase support can be enabled/disabled at the Makefile
level as well, by setting syzygy=yes or syzygy=no.

Big/little endian are both supported.

No functional change (if Tablebases are not used).

Resolves #6
2014-11-26 07:49:58 +08:00