Moderator: Andres Valverde
Bernd wrote:How do you decide how many plies are stored for each game?
struct {
uint64 hashKey; /* Zorbis hash key for the position */
uint16 score; /* The number of times the position was reached */
}
If I got it right, it does mean to:
- generate all moves
- make/unmake all of them
- for each resulting position lookup its frequency
- chose a move randomly while moves that lead to positions with higher score are more probable..
Doesn't that mean hundreds of seeks in the file?
Yes, assuming that the book holds 1 million positions, about 20 fseek & fread operations per move in the worst case, which would be 600 operations in a position where there are 30 legal moves. That sounds like a lot of work, but it still doesn't take any noticeable time. So there's no need to hold the book in RAM.
I'll post some benchmark results tomorrow (it's midnight in Finland right now) and my source code (in C) for the opening book.
Legal moves: 20, Book moves: 16, time: 37 ms
Legal moves: 28, Book moves: 15, time: 54 ms
Legal moves: 29, Book moves: 3, time: 763 ms
Legal moves: 31, Book moves: 4, time: 58 ms
Legal moves: 37, Book moves: 4, time: 74 ms
Legal moves: 36, Book moves: 3, time: 70 ms
Legal moves: 34, Book moves: 4, time: 99 ms
Legal moves: 37, Book moves: 7, time: 99 ms
Legal moves: 36, Book moves: 0, time: 68 ms
Legal moves: 40, Book moves: 0, time: 77 ms
Legal moves: 44, Book moves: 0, time: 115 ms
Legal moves: 45, Book moves: 0, time: 90 ms
Legal moves: 40, Book moves: 0, time: 79 ms
Legal moves: 43, Book moves: 0, time: 117 ms
Legal moves: 45, Book moves: 0, time: 119 ms
Legal moves: 41, Book moves: 0, time: 77 ms
Legal moves: 39, Book moves: 0, time: 73 ms
Legal moves: 37, Book moves: 0, time: 74 ms
Legal moves: 35, Book moves: 0, time: 70 ms
Legal moves: 38, Book moves: 0, time: 73 ms
Legal moves: 39, Book moves: 0, time: 74 ms
Legal moves: 40, Book moves: 0, time: 74 ms
Legal moves: 47, Book moves: 0, time: 120 ms
Legal moves: 47, Book moves: 0, time: 91 ms
Legal moves: 48, Book moves: 0, time: 121 ms
Legal moves: 42, Book moves: 0, time: 82 ms
Legal moves: 42, Book moves: 0, time: 80 ms
Legal moves: 40, Book moves: 0, time: 78 ms
Legal moves: 5, Book moves: 0, time: 11 ms
Legal moves: 4, Book moves: 0, time: 8 ms
Legal moves: 49, Book moves: 0, time: 95 ms
Legal moves: 29, Book moves: 0, time: 66 ms
Legal moves: 29, Book moves: 0, time: 57 ms
Legal moves: 30, Book moves: 0, time: 59 ms
Legal moves: 30, Book moves: 0, time: 55 ms
Legal moves: 29, Book moves: 0, time: 57 ms
Legal moves: 28, Book moves: 0, time: 55 ms
Legal moves: 29, Book moves: 0, time: 143 ms
Legal moves: 27, Book moves: 0, time: 51 ms
Legal moves: 27, Book moves: 0, time: 52 ms
Legal moves: 24, Book moves: 0, time: 46 ms
Legal moves: 3, Book moves: 0, time: 5 ms
Legal moves: 26, Book moves: 0, time: 50 ms
Legal moves: 27, Book moves: 0, time: 51 ms
Legal moves: 24, Book moves: 0, time: 47 ms
Legal moves: 24, Book moves: 0, time: 48 ms
Legal moves: 20, Book moves: 0, time: 39 ms
Legal moves: 20, Book moves: 0, time: 40 ms
Legal moves: 21, Book moves: 0, time: 43 ms
Legal moves: 22, Book moves: 0, time: 41 ms
Legal moves: 4, Book moves: 0, time: 6 ms
Legal moves: 1, Book moves: 0, time: 2 ms
Legal moves: 5, Book moves: 0, time: 7 ms
Legal moves: 24, Book moves: 0, time: 49 ms
Legal moves: 30, Book moves: 0, time: 60 ms
Legal moves: 33, Book moves: 0, time: 68 ms
Legal moves: 27, Book moves: 0, time: 55 ms
Legal moves: 36, Book moves: 0, time: 77 ms
Legal moves: 6, Book moves: 0, time: 12 ms
Legal moves: 35, Book moves: 0, time: 73 ms
Legal moves: 35, Book moves: 0, time: 71 ms
Legal moves: 18, Book moves: 0, time: 40 ms
Legal moves: 19, Book moves: 0, time: 39 ms
Legal moves: 17, Book moves: 0, time: 35 ms
Legal moves: 19, Book moves: 0, time: 41 ms
Legal moves: 23, Book moves: 0, time: 46 ms
Legal moves: 17, Book moves: 0, time: 35 ms
Legal moves: 19, Book moves: 0, time: 38 ms
Legal moves: 16, Book moves: 0, time: 33 ms
Legal moves: 14, Book moves: 0, time: 29 ms
Legal moves: 22, Book moves: 0, time: 44 ms
average time: 70 ms
e2e4 99 e7e5 99 *
e7e6 15 * *
d2d4 33 d7d5 99 * * *
How many plies are common?
I don't know how many are common, my limit is 45 plies but most lines are shorter (see below).
Should some lines be longer than others?
What can I do with the information about who won the game/is it used? Are moves always chosen by the frequence they are played at a certain position?...
From the starting position you are "in book". That means I try to lookup a book move for each position encountered and will do *no* search.. until a position with no book move is found. Upon then I am out of book and will not try to lookup book moves. Is this o.k. or are there better ways to handle openings...
Volker Annuss wrote:my opening book format is like in this example:
- Code: Select all
e2e4 99 e7e5 99 *
e7e6 15 * *
d2d4 33 d7d5 99 * * *
Every move is followed by a weight. * takes back a move.
In the starting position, there are two alternatives: e2e4 is chosen with a probability of 0.75 /* 99 / (99+33) */ and d2d4 with a probability of 0.25.
After e2e4 the move e7e5 is chosen with a probability of ~0.87 /* 99 / (99+15) */ and e7e6 with a probability of ~0.13 /* 15 / (99+15) */.
In the starting position, the book is read into the same memory that is used for the hash table later in the game. It is not used like the hash table but in a very different way. A hash key, one move and its weight is stored in one hash table slot. When there is more than one book move in a position, there is also more than one element with the same hash key (but different move and weight) in the table. The table is sorted by hash key for a binary search.
Volker Annuss wrote:There are some extensions for Chess960 books but they are still experimental.
Volker Annuss wrote:Advantages:
- fast lookup
- no extra memory required
- human readable book format (In public books I remove blanks from the file to get a better compression for the .zip file.)
Disadvantages:
- no chance to find book moves when out of book and back into book by transposition
- maximum book size depends on Hash size
Should some lines be longer than others?
Normally a position only goes into the book, when it was reached in more than one game. The number of games is a parameter of the book creation. The weight of a game is also a parameter of the book creation, so you can make high quality games more important.
What can I do with the information about who won the game/is it used? Are moves always chosen by the frequence they are played at a certain position?...
When you put much work in selecting your games, there is no need to use the game result. My engine Hermann prefers moves that have a high average score.
Legal moves: 20, Book moves: 12, time: 26 ms
Legal moves: 21, Book moves: 5, time: 28 ms
Legal moves: 23, Book moves: 4, time: 30 ms
Legal moves: 27, Book moves: 4, time: 35 ms
Legal moves: 30, Book moves: 0, time: 39 ms
Legal moves: 34, Book moves: 0, time: 41 ms
Legal moves: 33, Book moves: 0, time: 46 ms
Legal moves: 35, Book moves: 0, time: 45 ms
Legal moves: 38, Book moves: 0, time: 49 ms
Legal moves: 37, Book moves: 0, time: 49 ms
Legal moves: 35, Book moves: 0, time: 46 ms
Legal moves: 37, Book moves: 0, time: 49 ms
Legal moves: 41, Book moves: 0, time: 55 ms
Legal moves: 45, Book moves: 0, time: 55 ms
Legal moves: 7, Book moves: 0, time: 9 ms
Legal moves: 45, Book moves: 0, time: 60 ms
Legal moves: 34, Book moves: 0, time: 43 ms
Legal moves: 44, Book moves: 0, time: 60 ms
Legal moves: 47, Book moves: 0, time: 63 ms
Legal moves: 47, Book moves: 0, time: 61 ms
Legal moves: 47, Book moves: 0, time: 63 ms
Legal moves: 51, Book moves: 0, time: 65 ms
Legal moves: 49, Book moves: 0, time: 68 ms
Legal moves: 47, Book moves: 0, time: 61 ms
Legal moves: 42, Book moves: 0, time: 53 ms
Legal moves: 40, Book moves: 0, time: 52 ms
Legal moves: 3, Book moves: 0, time: 4 ms
Legal moves: 39, Book moves: 0, time: 136 ms
Legal moves: 45, Book moves: 0, time: 92 ms
Average time: 51 ms
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 44 guests