# Opening book - how to create ?

This topic is 4652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, i am programming an algorithm for a game. I would like to use an opening book or how it is called in usual. In this dictionary i want to save all possible moves the opponent can make. If its my turn i want to read this opening book and choose the way which leads to best result. My problem is that i don't know how to implement this dictionary? How do i have to store the possible positions of the current game? I suspect in a file? But how ? It would be very useful if anybode could give me some advice how to work further.... Thanks a lot

##### Share on other sites
Look into a technique called "hashing". It shouldn't be hard to find good info on Google. If you need more details, ask again.

##### Share on other sites
I'm sorry but i cannot find any hints how to start my work for an opening book.
Imagine i have a board game like TicTacToe.
How can i implement an opening book?
Is it really faster using an book at the beginning instead of searching with a solid alpha beta algorithm ?
I have problems to understand how to store my board positions and how to read them in or how to react to an oponnents move with a correct selection within the opening book....

Thanks for any help

##### Share on other sites
I'll explain a simple solution that will get you started. To keep things simple, make two files: book.1 and book.2. In book.1 you'll put games that are well played by player 1. Similarly in book.2 you'll put games that are well played by player 2. Use a simple text format that you can edit by hand, since this makes debugging easy. In the case of tic-tac-toe, you can number all squares from 1 to 9 and store a game like this: 152374968. You don't need to store complete games, just the first few moves.

When it's your program's turn to play, it will pick book.1 or book.2 depending on what side it is playing. Then it will play all the partial games stored in the file on a secondary board. After each move, compare the board with the current board. Whenever you have a match, you store the next move in the file as a candidate. When you are done with the file, you'll have a set of "good" moves. Pick one at random (you can do it proportionally to the number of times it appears in your file, or not, or you can add notes in the file indicating what probabilities you want to use...).

Opening books are a good idea for games like chess, where no reasonable ammount of alpha-beta search is going to produce moves as strong as moves from a good book. It also saves time.

A more sophisticated way of implementing an opening book is to consider it as a mapping from positions to a distribution of probabilities of the next move, and store that in the file using some hashing scheme to make the lookups fast. Some people use binary trees instead. In any case, you will need some form of specialized editor to modify your book. But remember: keep things simple until the simple solution doesn't serve you well anymore.

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633657
• Total Posts
3013203
×