Author: Dann Corbit
Date: 17:36:03 05/07/04
Go up one level in this thread
On May 07, 2004 at 19:51:42, Uri Blass wrote:
>I looked at the code of Crafty to understand what it does when it creates the
>opening book(the function BookUp()).
>
>1)I see that it it is using malloc to allocate memory.
>I have no malloc in movei and I use calloc to allocate hash tables.
>
>I find that Crafty has no calloc but many malloc and my question is if there is
>a reason for that.
To be totally portable, the only thing that calloc() should be used on is an
array of unsigned character (though signed char is probably safe too).
For instance, you have no guarantee that pointers will be NULL or that float or
double will be zero or int values will contain zero.
>2)I understand that crafty first translate pgn to book positions but I do not
>see moves in the following structs
>
>typedef struct {
> BITBOARD position;
> unsigned int status_played;
> float learn;
> int CAP_score;
>} BOOK_POSITION;
>
>typedef struct {
> unsigned char position[8];
> unsigned char status;
> unsigned char percent_play;
>} BB_POSITION;
>
>
>My question is where does Crafty save the moves.
/*
************************************************************
* *
* first cycle through the root move list, make each *
* move, and see if the resulting hash key is in the book *
* database. *
* *
************************************************************
*/
initial_development =
(wtm) ? EvaluateDevelopmentW(tree, 1) : EvaluateDevelopmentB(tree, 1);
total_moves = 0;
nmoves = 0;
for (im = 0; im < n_root_moves; im++) {
common = HashKey & mask_16;
MakeMove(tree, 1, root_moves[im].move, wtm);
if (RepetitionCheckBook(tree, 2)) {
UnmakeMove(tree, 1, root_moves[im].move, wtm);
return (0);
}
temp_hash_key = HashKey ^ wtm_random[wtm];
temp_hash_key = (temp_hash_key & ~mask_16) | common;
for (i = 0; i < cluster; i++) {
if (!(temp_hash_key ^ book_buffer[i].position)) {
book_status[nmoves] = book_buffer[i].status_played >> 24;
bs_played[nmoves] = book_buffer[i].status_played & 077777777;
bs_learn[nmoves] = (int) (book_buffer[i].learn * 100.0);
if (!wtm)
bs_learn[nmoves] *= -1;
bs_CAP[nmoves] = book_buffer[i].CAP_score;
if (puzzling)
bs_played[nmoves] += 1;
tree->current_move[1] = root_moves[im].move;
if (!Captured(root_moves[im].move))
book_development[nmoves] =
((wtm) ? EvaluateDevelopmentW(tree,
2) : EvaluateDevelopmentB(tree, 2)) - initial_development;
else
book_development[nmoves] = 0;
total_moves += bs_played[nmoves];
evaluations[nmoves] = Evaluate(tree, 2, wtm, -999999, 999999);
evaluations[nmoves] -= (wtm) ? Material : -Material;
bs_percent[nmoves] = 0;
for (j = 0; j < smoves; j++) {
if (!(book_buffer[i].position ^ start_moves[j].position)) {
book_status[nmoves] |= start_moves[j].status_played >> 24;
bs_percent[nmoves] = start_moves[j].status_played & 077777777;
break;
}
}
book_moves[nmoves] = root_moves[im].move;
nmoves++;
break;
}
}
UnmakeMove(tree, 1, root_moves[im].move, wtm);
}
if (!nmoves)
return (0);
>I remember that I read that another program (Tao) save only positions in the
>book but it seems to me a bad idea for reasons that Dieter gave because the
>program may go to a book position instead of playing a better move.
>
>book should include positions and moves.
>
>3)If I understand correctly Crafty first remember the book in a big array and
>only later sort the big array by BookSort and later copy it to a file.
That is a "once in a while" operation that only happens when you make a new
book.
>I do not understand what BookUpNextPosition does and what reason there is to
>return the least (lexically) position key.
>
>If I want to put a new position in the book I need to put it in the right place
>and I do not understand how the least hash key can help me.
>
>
>Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.