Author: Dann Corbit
Date: 11:37:58 11/02/00
Go up one level in this thread
On November 02, 2000 at 13:22:08, Wieland Belka wrote: >Hello Crafty friends, > >using opening books it's a great part of Crafty's strong playing, well. > >1. How could I complete Crafty's book with specific opening stuff? From the CRAFTY FAQ: "[1.5] How do I build Crafty's Book? You need an executable version of Crafty and a PGN file to build it's book. Choose between large (unzip large1.zip, large2.zip, large3.zip, large4.zip and append them into one file), medium (unzip medium.zip), or small.zip (unzip small.zip). Large produces a 90Mb-60Mb opening database with 100K GM games; medium produces a 30Mb database, and small will produce a 1Mb database. Note that you will need at least double this space to create the files, since temporary files are written to disk, and then later deleted. Use the following commands to build the book: crafty book create <filename> 60 quit <filename> should be replaced by the PGN filename that is created when you unzip the book file of your choice. Start.zip contains a small file that is used to create books.bin. books.bin is created as follows: crafty books create start.pgn 60 quit This file contains suggested openings that fit Crafty's "open" style of play better. You can edit/modify this at will, and it takes a fraction of a second to re-build after modification, so the big book file can be left alone. Note that the "60" is arbitrary, and is used to cut book lines off at roughly 60 plies. You "can" say 500, so that the entire games will be stored, but you need even more disk space. You can also reduce this number to 30 (15 moves for each side) to conserve disk space as needed, since the book will contain far fewer positions." From the Crafty.doc.ascii file: "6. book -see the explanation near the end of this document for a full explanation of this command and its many options. Note that there are special commands available, *only* on the command line, *not* in the crafty.rc/.craftyrc files, to direct Crafty to specific directories for the book files (bookpath=/a/b/c), the tablebase files (tbpath=/i/j/k) and the log files (logpath=/x/y/z). Note that these commands can *only* be used on the command line, because they must be executed before the engine is initialized. Putting them in the crafty.rc/.craftyrc file will produce error messages without affecting how the files are opened. If you need to specify multiple directories (tbpath only) you may do so by using "tbpath=path1:path2:path3:" etc., or else use the more Unix-like "tbpath=(path1:path2:path3:)" instead. The paths are separated by colon (:) characters and everything is case sensitive as usual. For DOS/Windows users, the separator can be a semicolon (;) or a comma (,) to avoid the drive designation ambiguity." Also: "24. import <filename> [clear] -is used to import any sort of learning data that Crafty supports, which currently includes book learning data, position learning data, and the Chess Analysis Project data. This command reads the appro- priate <filename> and imports that learned data, just as though Crafty had learned it by playing the games. The [clear] option causes all old learned results to be cleared before the import operation; otherwise the imported data is simply added to what is already present." "Opening Book Setup and Usage ---------------------------- Crafty uses two pre-compiled opening books, called "book.bin" and "books.bin". The file book.bin is usually built from a large text file containing PGN games, often taken from collections of grand- master games. Building book.bin is a simple exercise and requires nothing other than the raw input file you are going to use. Generally this will be either medium.pgn or large.pgn-files that can be obtained in zip format from ftp.cis.uab.edu/pub/hyatt/. To create the file book.bin, you start with a PGN compliant collection of games. Supposing this file is called "large.pgn," you would use the following command: book create large.pgn <m> [n] [wpct] The only thing you have to supply is <m>, a number indicat- ing how many moves from each game are to be stored in the book.bin database. I typically use 60, which stores the first 60 moves from each game. Increasing this number slightly increases the probability that Crafty will stay in book longer, but it also increases the probability that it will follow a game too far, so that it begins to reach posi- tions where the move actually played might not be the best move. Increasing this number also increases the size of the database as well. You can decrease the size of the book, and reduce the number of ugly moves in it, by specifying [n], the number of games a move must be played in before it is stored in the book database. This will substantially decrease the size of the book.bin file, eliminating single game moves that often have significant errors or blunders. You can increase the quality of book lines by specifying [wpct]-the "winning percentage." This amount is specified as a percentage of lost games, and is used to discard moves that led to mostly losses. A safe value is 50, which means if a particular opening move didn't win at least 50% as many games as it lost, the move is culled. A value of 100 means that moves are culled if they produced more losses than wins, a very strict criterion. After creating book.bin, you need to create books.bin. This is a small version of book.bin that is intended to give you more control over the moves and openings Crafty will play. This file is usually built from the file start.pgn on the Crafty ftp site, but you can easily modify this file to suit your taste. To build books.bin, you use the following com- mand: books create start.pgn 60 Again, 60 is what I use, but none of my start.pgn lines go anywhere near that many moves. The point of start.pgn is that in you can append a "!" to any move you want; Crafty will play the moves marked with "!" if there are any, ignor- ing the rest of the book moves found in book.bin. If you only want Crafty to play 1. e4 as white, you would just enter the short game: [Crafty only plays 1. e4] 1. e4! and you are finished!. You can enter as many "!" as you want. On the other hand, if a move is appended with a "?" Crafty will never play it. Moves in books.bin that are not flagged with either "!" or "?" don't have any influence on Crafty's choice at all. Here's how the files are used. When searching a position, Crafty first enumerates the set of moves it can find in the book.bin database. It then does the same for the books.bin database, and performs a merge operation to combine the "!" and "?" flags. The purpose of the books.bin file is to give you a small database that you can easily modify, since it takes only a fraction of a second to rebuild. You don't have to rebuild the large book.bin database. One important characteristic of the PGN input is the Result tag must be specified in most of the lines. Crafty counts wins, losses, and draws for each book move, and uses these counts with some of the book selection options given below. How the flags are used. The ! and ? flags should only appear in the small books.bin file, although there is no reason why they cannot appear in the large file as well. For this discussion it doesn't mat- ter since Crafty takes the moves from both files and merges the flags into one entry for each move. If any legal book move has a ! flag, then Crafty will only play moves from the set of moves which have the ! flag. If a move has a ? flag, then that move is immediately removed from the set of possible book moves. If the only legal book move has a ? flag, it will not be played as a book move. Crafty will pre- tend that it found no book moves and will execute a normal tree search. Pretty simple. How to control the frequency of opening move selection. A new feature in version 15.15 and beyond allows you to append a PGN comment to any move in a text file used to cre- ate books.bin, of the form {play nn%}. This will force the move it follows to be played that percentage of the time, regardless of the normal book-ordering values based on fre- quency and so forth. Note that {play 0%} will not prevent a move from being played, as this will look just like a move with no percent specified. To avoid playing a move, use the ? flag. How does Crafty choose book moves? Crafty's book selection algorithm depends on two user- defined values that can be set at any time during a game: book random <n> book width <w> The selection algorithm first finds the set of legal book moves as above. This set will either be all ! moves, or will have no ! moves in it. This set is then sorted based on the setting of book random. Here's the options: book random 0. -is a special case for book selection. Crafty searches the set of book moves using a normal alpha/beta search, but with a shorter than usual time limit. It then plays the move that produces the best search value. This has one serious disadvantage in that there is no ran- domness to this at all. It will always play the same move in the same position, unless the evaluation is modified, or the time per move is changed to let the search find a different move from the book move set. book random 1. -enables a random form of book move selec- tion, but you have a lot of control over how moves are ran- domly chosen. The moves are ordered by four parameters: fre- quency of play, win/lose ratio, static evaluation, and learned results. Normally these are factored into the value used to sort the moves, based on default settings. You can modify these settings with the "bookw option N" command. "option" should be "freq," "ratio," "eval," "learn," or "CAP." N should be any real number between 0 and 1. Crafty finds the minimum and maximum values for each of the four parameters, and then maps these values into the range 0-1000 for each parameter. Each parameter is then multiplied by the corresponding "weight" you have assigned, and the result is used as a value to sort the moves from low to high. Note that the first sort value is always the "play percent" to move them to the top of the list. For moves with equal "play percent" values, the normal sort value is used as the second level sort variable. If no moves have a play percent, then this second-level variable is the only one used, of course. Once Crafty has sorted the moves, it next excludes any book moves that have no wins. This culls the odd lines where a player chose a bad line and lost quickly. With zero wins, it will never be chosen, although Crafty will happily follow it from the other side. :) This is not anywhere near perfect, however, because an opening could have 1 win and 19 losses and that still would stay in the list. If a move has a learned value greater than 100, it is ele- vated in priority to that of a ! move, since it appears to win material instantly. If the learned value is less than -100, it is given a ? since it appears to be a lemon. After these calculations for randomness, the setting for "book width <w>" is used to keep the first <w> moves in the list. The smaller you make <w> the less randomness you get, but the chance of Crafty popping out a really bizarre book move gets smaller as well. After sorting, the final step is to fold in any mandatory "play percent" values. This step finds all the moves in the "playable move set" just computed, which have no percent-to- play value set. It sums the sort values for these moves, then adjusts the sort values for the other moves so that their percentages will be honored. Once this has been done, Crafty uses the "sort value" for each move to compute a total for all moves. It then gener- ates a random number between 1 and this limit, and chooses the move that this probability distribution matches. This will certainly evolve over time as new ideas are developed. I normally use book random 1 and book width 5 for my play on ICC, though for titled players I use book width 3. For com- puters I reduce this to 2, so Crafty plays reasonable open- ings, culling the gambits and things that don't work out. How does book learning work and how can I share learned results? All of Crafty's "learned knowledge" is in the book.bin file. It keeps the learned value and learned count in the book file for speed. You can't modify it, although "show book" will make Crafty display all the book stuff before it makes a move. The book.lrn file is a log of what Crafty has learned, against whom, and what the score was that got its attention in the first place. The values on the end of each book line, inside the {} characters are as follows: {value, depth, rating_difference} Value is the value, in centipawns, of the "key" search that is derived from the first 10 moves out of book; positive values are good, nega- tive values are bad. Depth is the depth the search reached at this "key" position; the deeper the search, the more the value is trusted. Rating_difference is Crafty's rating - opponent's rating; a negative value means pay more attention to the score since the opponent is better than Crafty; a positive value means to take the score with a grain of salt, because the opponent was weaker than Crafty. You can delete this file at any time--it has no effect on learning. As I mentioned, the learning takes place in book.bin. Book.lrn is mainly for you to peek at if you are interested. However, book.lrn is also the "portable learning data file." It can be given to others to import into their Crafty, where it will affect the opening book just like their Crafty had played the openings and got the same scores. There are two ways to use such "lrn" files: 1. import <filename> -will read <filename> and import the knowledge therein into your book.bin. Since I use the same learning code as that used when playing games, this informa- tion also gets appended to *your* book.lrn file as well, so that your book.lrn always reflects everything your program has learned, so long as you don't ever remove the file. It would be a mistake to use this command on your own book.lrn file, because everything would get counted twice, which might not be a good thing. 2. import <filename> clear -will read <filename) and import the knowledge as above, but first clears all learned results from book.bin. You will want to do this if you import my book.lrn after you have contributed to my book.lrn data by sending me yours. I'll take care of eliminating duplicates if you screw up in what you send me, but once you send me something, you run the risk of getting it back later. This is going to be a problem until everyone gets used to sharing something that is rather amorphous as this "learned info" is. Other than that, we are now "open for business." when the urge strikes you, email me your book.lrn file; I'll keep a large master here and update it on occasion. Probably the best thing to do is to send me your book.lrn and at the same instant delete yours. This will capture anything learned after you send me the file, but you'll get your old stuff back with the next version of book.lrn that I distribute. After getting this new book.lrn back, you should: 1. rename your old book.lrn to something else. I'll call it "book.lrn.old" here. 2. copy my blearn.dat to your machine, but do not put it in the directory with your book.bin and books.bin files because it will get confusing very quickly if you do. I'll call blearn.dat new.lrn for this example. 3. import new.lrn clear import book.lrn.old and you are ready to rumble again. The first command clears the learned values, imports my new learn file and updates everything. The second command restores everything you've learned since you sent me the last book.lrn file. After doing this process your book.lrn will have my .lrn stuff, plus your old.lrn stuff, just waiting to be sent to me again... If this is confusing, I can probably add a command to auto- mate this process by renaming book.lrn, etc. I Hope it's not too error prone for the time being anyway. What is this new Position Learning I've heard about? Crafty now has a permanent hash table that is kept from game to game. A position gets into this hash table when a search value is significantly lower than the last search value. The permanent hash table can hold up to 65536 positions. Once it fills up, the positions are replaced on a FIFO basis, always keeping the most recent 64K entries. Each time Crafty starts a search, the positions and scores from this table are stuffed into the normal transposition table, and used during the search just like any other table entry. Here's how it helps: During a game the following moves and scores were found by Crafty (playing white): 1. Ng5 (+.277) h6 2. Nh7 (+.321) Kg8 3. Qh5 (+.133) Qg7 4. Ng5 (-2.122) hxg5 So the knight got trapped at h7, and at move 4 Crafty dis- covered that this loses and learns this position and result. We play the exact same game again, except that one of two things can happen here. It might be that 1. Ng5 is the only square the knight can move to here, which means that this whole line is forced. The first search would find 1. Ng5 (-2.122) if the search can reach 8 plies deep, which happens even in 5 second games. Crafty has learned that Ng5 is bad. It stores this position in the permanent hash file also, and the next time you try this same trap, it will discover 4-5 moves earlier that if the knight goes to g5 it is in trou- ble. Each game will diverge from the first game 3-4 moves earlier. Simple and effective. 2. Ng5 might not be forced, and if not, it knows Ng5 loses a piece for a pawn, so it will promptly play something else, which is exactly what is desired. This hash table is implemented with two files. One file, position.bin, is a binary file that contains the hash table entries. It's maximum size is one megabyte: 16 bytes per hash entry * 65536 entries = exactly one meg, but I have 8 extra bytes for the FIFO queue implementation and to see how many entries are currently in the file if it is not full. The second file is position.lrn, and is, you guessed it, a file that can be shared with others, just like book.lrn. It contains all the information needed to reconstruct the hash table, including positions, scores, and depths,and also includes the PGN tags for who was what color and when the game was played. This data can be imported with the new "import" command (the old book learn <filename> is no longer around), which will import either book.lrn data or position.lrn data, and can tell them apart without your having to do anything. The <clear> option is still there, should you want to use it, which removes the position.lrn and position.bin files before starting the import process for position learning. Learning can be turned off if you like, using the "learn" command. The learn command lets you turn off book learning (as it presently works), position learning, and the next book learning stage, which will add to the book in addition to learning which book lines are good and bad. What is this new "result" learning? Result learning works just like normal book learning, except that if Crafty is checkmated or resigns, it will step back through the book line to find the last point where it had more than one move to choose from. It will flag the move it chose as "never play again". This handles the case where the first ten non-book moves produce reasonable scores, but the position is one that Crafty can't handle very well. If it loses such a game, it will still vary the next time this opening is played, as otherwise it would possibly repeat the same opening, and would certainly repeat the remainder of the game. All three learning modes are turned on by default, although any of them can be disabled with the appropriate "learn" command." >2. Can Crafty profit from any game archives? If yes, on which way? > >Can anybody help? > >Thanks Wieland Suggestion: Read The Fine Manual.
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.