Sign in to follow this  

Opening book - how to create ?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this