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

2079 commits

Author SHA1 Message Date
Marco Costalba
c6f497f09d Fix small bug in move_attacks_square()
We test if the piece moved in 'to' attacks the square 's' with:

bit_is_set(attacks_from(piece, to), s))

But we should instead consider the new occupancy, changed after
the piece is moved, and so test with:

bit_is_set(attacks_from(piece, to, occ), s))

Otherwise we can miss some cases, for instance a queen in b1 that
moves in c1 is not detected to attack a1 while instead she does.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-30 19:31:50 +01:00
Marco Costalba
29be28e1a2 Inline pinned_pieces() and discovered_check_candidates()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-30 18:48:23 +01:00
Marco Costalba
e7939f450f Code style and 80 chars cols in Position::from_fen()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-30 18:02:18 +01:00
Marco Costalba
81801d395f Sync do_move() and undo_move()
It is not possible to unify due to the fact that the
sequence steps are reversed. What we can do is to try
to sync comments and code as much as we can to easy
reading and documentation.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-30 13:58:44 +01:00
Marco Costalba
bc76c62c63 Explicitly use a dedicated bitboard for occupied squares
Instead of byTypeBB[0]. This better self-documents the code.

No functional and speed change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-30 13:51:20 +01:00
Marco Costalba
fd5d6c5340 Retire do_capture_move()
It is called only in do_move() that now has been fully
expanded. This is the most time consuming function of
all the engine.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-30 10:59:55 +01:00
Marco Costalba
08abe8b4a3 Retire undo_null_move()
Use a templetized do_null_move() to do/undo the null move.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-29 18:01:56 +01:00
Marco Costalba
e896368496 Retire undo_castle_move()
Use a templetized do_castle_move() to do/undo the castling.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-29 17:31:15 +01:00
Marco Costalba
2fe4e10b0b Retire Position::set_castling_rights()
Is called in just one place. And rename set_castle() in the
now free to use and more appropiate set_castle_right().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-29 13:43:44 +01:00
Marco Costalba
f2e78d9f84 Retire PieceValueXXX[] getters
They don't add any value given that the corresponding
table has global visibility anyhow.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-22 16:06:59 +01:00
Marco Costalba
b5bbc1f713 Simplify the promotion case of move_gives_check()
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-22 15:01:21 +01:00
Marco Costalba
23943208ec Remove redundancy in definitions of attack helpers
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-22 14:25:53 +01:00
Marco Costalba
c555e1aa96 Convert PST tables to relative values
This is a prerequisite to allow changing piece values
at runtime, needed for tuning.

Also use scores instead of separated midgame and endgame values.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-22 13:17:24 +01:00
Marco Costalba
36cc214703 Increase Mobility
First tuning with CLOP against a pool of 3 engines. Result
verified with a direct match:

After 8736 games at 10"+0.1
Mod vs Orig 1470 - 1496 - 5770 ELO -1 (+-4.3)

So no change in self match but if CLOP is right it should
be a bit better against an engine pool.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-20 07:06:05 +01:00
Marco Costalba
8f7d36a85d Better document mate and stalemate detection
In particular add that we can have an harmless false positive
in case StopRequest or thread.cutoff_occurred() are set.

Reported by David Lee.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-18 20:01:21 +01:00
Marco Costalba
e7cfe42d3f Use newly added log facility instead of LogFile
As a side effect now log file is open and closed every
time it is used instead of remaining open for the whole
thinking time.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-17 21:07:14 +01:00
Marco Costalba
500fff920b Add basic log facility
Mainly used to log stuff to a file while playing, when
stdout is used for the comunication with the GUI.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-17 21:07:00 +01:00
Marco Costalba
782c3f36cc Fix compile error in debug mode
Build broken by commit 3141490374
where we renamed move_is_ok() in is_ok() and this clashes
with the same named method in Position that overrides the
move's one causing compile errors.

The fix is to rename the method in Position.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-16 23:56:25 +01:00
Marco Costalba
8272dcb6cd Link Time Optimization doesn't needs -static
Justin reports that it breaks the compilation on Fedore 15 and as Tom says:

-static is only needed to work around the gcc on ubuntu 11.10 beta bug.
If -static introduces issues on its own then it is better to remove it.
It will not be needed in most environments.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-09 08:24:56 +01:00
Marco Costalba
fec623d68d Better document how MultiPV search works
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-08 12:11:53 +01:00
Marco Costalba
a3bf09c5c9 Send again all the PV lines in multiPV searching
Partially revert 1036cadcec because UCI protocol
in case of multipv explicitly requires:

for the best move/pv add "multipv 1" in the string when you send the pv.
in k-best mode always send all k variants in k strings together.

Thanks to Justin Blanchard for pointing this out.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-08 10:24:54 +01:00
Marco Costalba
325dedc7da Added gcc -msse3 support
It is enabled when selecting x86-64-modern target, this gives
another nice speed up:

On a Core i5-2500 (3300 Mhz, Sandy Bridge):

64 bit download version: 1597151 n/s

-flto : 1659664 n/s

-flto -msse3: 1732344 n/s

Patch suggested by Tom Vijlbrief.

Also unify flto, popcount and msse3 optimization under "modern"
target, note that this can break the "modern" build on old gcc that
do not support -flto option: in this case update gcc ;-) or default
to the standard build.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-08 08:50:11 +01:00
Tom Vijlbrief
09b5949cd2 Added gcc lto (Link Time Optimization) option
Just by adding the -flto option to CXXFLAGS link command
we can gain a few percent in speed.

On a Core i5-2500 (3300 Mhz, Sandy Bridge):

64 bit download version:

Without -flto: 1597151 n/s
With -flto : 1659664 n/s

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-06 20:10:12 +01:00
Marco Costalba
3141490374 Shrink names of move helpers
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-03 14:18:57 +01:00
Marco Costalba
1a8e3f0b2e Small touches in position.h
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-03 14:18:56 +01:00
Marco Costalba
80dd90f972 Small touches to book.cpp
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-03 14:18:30 +01:00
Marco Costalba
c2c185423b Better naming borrowed from Critter
In line with http://chessprogramming.wikispaces.com conventions.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-02 10:16:59 +01:00
Marco Costalba
25b4d0c127 Revert "Retire Rml full PV search at depth == 1"
Yet another random crash source !

Hopefully this is the last one.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-02 07:40:46 +01:00
Marco Costalba
2225e3bbe7 Rename kingZone[] and reverse the king's color
Seems easier to understand to me. From Critter.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-02 06:54:57 +01:00
Marco Costalba
a90a990118 Document why Book is defined static
This was not clear to someone on talkchess and actually
is not trivial to understand.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-02 06:54:57 +01:00
Marco Costalba
83d8fe2d59 When exiting wake up all threads at once
It seems we have a very rare crash under Linux, once
every 10K games without this patch.

Is faster to wake up all the threads, especially on SMP,
where the threads can then exit in parallel while the main
thread is waiting for the next one to terminate.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-10-02 06:54:43 +01:00
Marco Costalba
63a04134d0 No need to test for MOVE_NONE before move_is_ok()
Function move_is_ok() already catches the move == MOVE_NONE case.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-09-25 16:30:29 +01:00
Marco Costalba
6bc16f3ff1 Update killers after a TT hit
Almost no increase but seems the logic thing to do.

After 16707 games 2771 - 2595 - 11341 ELO +3 (+- 3.2)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-09-24 17:20:35 +01:00
Marco Costalba
10b24af98a Correctly score capture underpromotions
Be sure a queen capture promotion is tried in front of
an underpromotion.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-09-24 17:13:14 +01:00
Marco Costalba
be9aba2fa0 Don't lock before check for termination
Restore old locking scheme changed with
commit 1e92df6b20.

This seems to prevent a very rare crash that occurs
once every 5-10K games.

With this patch we have no crashes after 33K games.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-09-24 17:12:36 +01:00
Marco Costalba
35018fa307 Use the map type template parameter to access map()
It is more natural than using the family subtype and also
use two single maps instead of a std::pair.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-09-11 11:38:23 +01:00
Marco Costalba
b706165527 Lookup square distance instead of calculate on the fly
Microptimization that gives a +0.7% speed increase.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-09-11 10:11:43 +01:00
Marco Costalba
6963c3802d Detect family type of endgame from its enum value
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-22 00:49:47 +01:00
Marco Costalba
3b67636f0e Indulge a bit on the template wizardy
Push the template pedal a bit in our "showoff" endgame code ;-)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-14 13:15:58 +01:00
Marco Costalba
48e39c5c8e Small simplification of endgame functions API
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-14 12:12:14 +01:00
Marco Costalba
13524bea9b Fix use of uninitialized variable
When initializing endgames map we build a faked FEN string
in mat_key() to get the position hash's key.

This fen string lacks full move numbers, so when parsing the
fen in Position::from_fen() we leave startPosPly un-initialized.

Spotted by Valgrind (this is a kind of bug that is almost impossible
for humans to find).

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-12 11:56:11 +01:00
Marco Costalba
500c7f44ab Fix silly icc remark #2259
Another stupid remark to quiet out:

remark #2259: non-pointer conversion from "int" to "UINT16={unsigned short}"
may lose significant bits

In this case icc always converts to an integer the result of a shift operation
if the bit size of the operand is smaller, hence the warning when assignin
back to n.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-12 11:54:54 +01:00
Marco Costalba
d156e7a20b Use a boolean instead as thread's state
Now that we have just two mutually exclusive thread's states
we can repleace them by a simple boolean.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-10 12:26:52 +01:00
Marco Costalba
c386ce0023 Remove Thread::WORKISWAITING
Set the state directly to Thread::SEARCHING

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-10 12:05:33 +01:00
Marco Costalba
b69d9ee3f7 Don't need pthread_detach() after pthread_join()
Spotted by Joona and verified with Valgrind.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-10 08:17:15 +01:00
Marco Costalba
7d5b8fcf77 Change start_routine argument
Directly pass the thread pointer.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-09 14:19:44 +01:00
Marco Costalba
bc6a6e04a0 Retire Rml full PV search at depth == 1
Now that Rml ordering is based on normal MovePicker logic,
apart for the ttMove that is given, we can avoid to score
all the root moves at depth 1. We only need it for easy move
detection logic, but in this case we just need to score the
first two best moves and not all the Rml set.

No regression after 6400 games
Mod vs Orig 1052 1012 4336 ELO +2 (+- 4.9)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-09 09:58:10 +01:00
Marco Costalba
e5ffe9959c Retire ThreadsManager::init_hash_tables()
Allocation of pawn and material hash tables should
be strictly bounded to the change of the number of
activeThreads, so move the code inside set_size().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-08 23:08:34 +01:00
Marco Costalba
86b95f2105 Retire Thread::TERMINATED
Use proper way to detect for thread terimnation instead of
our homegrown flag.

It adds more code than it removes and adds also platform specific
code, neverthless I think is the way to go becuase Thread::TERMINATED
flag is intrinsecly racy given that when we raise it thread is still
_not_ terminated nor it can be, and also we don't want to reinvent
the (broken) wheel of thread termination detection when there is
already available the proper one.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-08 22:10:01 +01:00
Marco Costalba
1e92df6b20 Retire Thread::INITIALIZING
Was used to prevent issues when creating multiple threads
on Windows, but now it seems we can remove it safely.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
2011-08-08 14:12:02 +01:00