What Is a CTG File? How to Open and Convert ChessBase Opening Books
What is a CTG file
Readers who ask what is a CTG file usually want to know whether it holds games. It does not: a CTG file is an opening book in the format used by ChessBase, and it does not hold games in the sense of a PGN file. It holds a tree of positions with the moves played from each one, so a program can look up the position on the board and play a reply without calculating it. The chessprogramming.org article describes CTG as the ChessBase Opening Tree of Games and says the format is proprietary, with a partial specification that was leaked to allow other programs to read it.
ChessBase and Fritz users meet CTG files as the books that come on the program disc. What is a CTG file in practice? It is the data file of a book, and it normally travels with two companions.
CTG, CTB and CTO: the files of one book
ChessBase documentation says an openings book is made of three files with the same name and different endings. The Fritz 21 handbook gives them as .CTG, .CTB and .CTO. The chessprogramming.org account of the leaked specification explains the roles as far as they are known:
| File | Role |
|---|---|
| CTG | the book data |
| CTO | a lookup table into the CTG file for fast indexed access |
| CTB | a bitmap marking free pages in the CTG file |
| INI | a small text file with auxiliary information, counted by that page as a fourth file |
The Fritz handbook therefore tells the user to copy all three, so the CTG files of one book belong in the same folder with their companions.
How to open a CTG file
A CTG file is opened by loading it as an openings book, not by double-clicking it like a document. In Fritz the Fritz 21 handbook gives two routes: press Ctrl-F12, or choose File, Open, Openings book, go to the folder and click General. Once a book is active, the Notation window of the board offers a Book tab that shows the book. ChessBase’s help also says an engine that uses the book plays its opening moves instantly, and that the book recognises transpositions that were not in the source games.
Books on a program disc are copied as three files. The handbook notes that files taken from a DVD carry the read-only attribute, which has to be cleared in the file properties before the program can use them from the hard disk.
Other programs can read the format too. ChessBase’s help states that CTG books can be read directly by chess programs such as Fritz and Shredder, and chessprogramming.org lists the open-source engines Brutus and Daydreamer among those that support it. Some graphical interfaces use their own book formats instead. Arena, for example, is listed with ABK as its book format, so a CTG book should not be assumed to load there; the program’s own help is the place to check.
Creating a book is also done in ChessBase. In the Database window the user chooses File, New, Database and sets the file type to Books (*.CTG), then copies games into the tree or drags in a whole database. The Game to Book command builds an on-the-fly tree from a selection of games.
How to convert a CTG file
A common target is the Polyglot format, which the chessprogramming.org opening book page calls the most popular book format. Polyglot was developed by Fabien Letouzey and modified by Fonzy Bluemers, and its book format is called bin; each entry takes 16 bytes and covers the hash, move, weight and learning values. The chessprogramming.org CTG article lists a tool named ctgexporter on GitHub for converting CTG to Polyglot and other formats.
The text alternatives are plain: PGN stores opening lines as individual games and EPD stores the final positions of opening lines.
Limits of the format
The leaked specification explains several oddities. A CTG file stores only positions with White to move. Positions with Black to move are converted by flipping colours, including the en passant square and castling rights. If the white king stands on files a to d and neither side can castle, the position is also mirrored horizontally. The file is organised in pages of 4 KiB, with the first page holding header data such as the number of games.
Related reading: the computer chess hub covers engines and books, and the chess history hub puts them in context. A sibling article covers handheld chess computers.
Questions
Is a CTG file the same as a PGN file?
No. A CTG file is a binary tree of positions made by ChessBase. A PGN file is a text list of games.
Why does my opening book not load?
Check that the .ctb and .cto files are beside the .ctg file with the same name, and that the files are not read-only, as the Fritz handbook advises.
Can I edit a CTG file?
Books are created and extended in ChessBase by adding games to the tree by copy and paste or drag and drop, as described in its help.
Can an engine use a CTG file without ChessBase?
Some do. The chessprogramming.org article names the open-source engines Brutus and Daydreamer, and ChessBase says Shredder reads CTG books.