Tord Romstad wrote:Hello Marco,
I am very happy to see this project, and I wish you good luck with it! This is how free software is meant to be used.
I tried to compile and run your program on my Mac, and it crashed after a few seconds. I was quickly able to identify the bug. Even if it does not crash the program on your computer, it will certainly have a negative impact on the performance, so it should definitely be fixed. The bug is in the TranspositionTable::retrieve function:
Code: Select all
/// TranspositionTable::retrieve looks up the current position in the
/// transposition table. Returns a pointer to the TTEntry or NULL
/// if position is not found.
const TTEntry* TranspositionTable::retrieve(const Position &pos) const {
TTEntry *tte = first_entry(pos);
for (int i = 0; i < 4; i++)
{
tte += i;
if (tte->key() == pos.get_key())
return tte;
}
return NULL;
}
You clearly mean to iterate over the four first transposition table entries beginning with first_entry(pos), but that's not what the above code does: Notice that you add 'i' to 'tte' once in every iteration, which is wrong, and means that you will try to access memory beyond the end of the transposition table in the case that first_entry(pos) happens to point to the last cluster in the table. What you meant to write is probably something like this (untested, but should work):
Code: Select all
const TTEntry* TranspositionTable::retrieve(const Position &pos) const {
TTEntry *first = first_entry(pos), *tte;
for (int i = 0; i < 4; i++)
{
tte = first + i;
if (tte->key() == pos.get_key())
return tte;
}
return NULL;
}
The name "Stockfish" is great!
During my summer holiday this year, I spent a three very interesting days in the stormy and isolated archipelago of Røst in Northern Norway, outside the Lofoten islands. Røst is a very tiny island community, with just about 600 inhabitants (separated from continental Norway by a 4 hour ferry trip, with only one ferry per day), most of whom make their living from stockfish. During the trip, I learnt a lot about the history of the stockfish trade between Norway and Italy. In particular, the story of
Pietro Querini, the Venetian merchant and nobleman who stranded on Røst after a storm in the winter of 1432 (while on his way from Crete to Flandern -- it must have been a terrible storm!) is told by everyone in Røst, and even the local pub is named after him.
According to the local traditions, the export of stockfish to Italy dates back to the 15th century, and started as a direct result of the contacts established by Querini.
Tord
Wow, that's a SUPER BUG!!! how can be I never saw or impacted that, anyhow perhaps a possible correct code could be.
Code: Select all
const TTEntry* TranspositionTable::retrieve(const Position &pos) const {
TTEntry *tte = first_entry(pos);
for (int i = 0; i < 4; i++, tte++)
{
if (tte->key() == pos.get_key())
return tte;
}
return NULL;
}
Under MAC it _should_ crash also for an optimization in pop_first_bit() when compiled for 32 bit cases and 32BIT_ATTACKS is defined.
Yes, I knew the history of the venetian Querini in Lofoten islands, because I live near Venice, more exactly in a region called Vicenza province, the home town of Querini (the main park of the town is named after him), where there is a town called Sandrigo that is twinned with the Lofoten and is the main importer of stockfish. The local cousine is very famous and the stockfish is the king, is cooked in a special way and only there, you cannot find that recipe in any other place of the world!
There is people that makes long trips, also from abroad, just to go there in one of the very few offically approved restaurant of that town to eat this speciality!
Marco