Subversion Repositories Games.Chess Giants

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.     Protector -- a UCI chess engine
  3.  
  4.     Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com)
  5.  
  6.     This program is free software: you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation, either version 3 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. */
  20.  
  21. #ifndef _book_h_
  22. #define _book_h_
  23.  
  24. #include "protector.h"
  25. #include "position.h"
  26. #include <stdio.h>
  27.  
  28. #define BOOKINDEX_SIZE 10007
  29. #define getBookpositionIndex(hashKey) \
  30.         ((hashKey) % BOOKINDEX_SIZE)
  31. #define getBookpositionIndexOffset(hashKey) \
  32.         (getBookpositionIndex(hashKey) * sizeof(BookPosition))
  33.  
  34. typedef struct
  35. {
  36.    UINT64 hashKey;
  37.    UINT32 nextPosition;
  38.    UINT32 firstMove;
  39. }
  40. BookPosition;
  41.  
  42. typedef struct
  43. {
  44.    UINT16 move;
  45.    UINT16 numberOfGames;
  46.    INT16 score;
  47.    UINT16 numberOfPersonalGames;
  48.    INT16 personalScore;
  49.    UINT32 nextAlternative;
  50. }
  51. BookMove;
  52.  
  53. typedef struct
  54. {
  55.    FILE *indexFile, *moveFile;
  56.    bool readonly;
  57.    UINT32 numberOfPositions, numberOfMoves;
  58. }
  59. Book;
  60.  
  61. extern Book globalBook;
  62.  
  63. /**
  64.  * Open the book specified by 'name'.
  65.  *
  66.  * @return 0 if no errors occurred.
  67.  */
  68. int openBook(Book * book, const char *name);
  69.  
  70. /**
  71.  * Create an empty book.
  72.  */
  73. void createEmptyBook(Book * book);
  74.  
  75. /**
  76.  * Close the specified book.
  77.  */
  78. void closeBook(Book * book);
  79.  
  80. /**
  81.  * Get all bookmoves for the position specified by 'hashKey'.
  82.  */
  83. void getBookmoves(const Book * book, const UINT64 hashKey,
  84.                   const Movelist * legalMoves, Movelist * bookMoves);
  85.  
  86. /**
  87.  * Get a move suggestion for the position specified by 'hashKey'.
  88.  *
  89.  * @return an illegal move if the book doesn't contain the position
  90.  */
  91. Move getBookmove(const Book * book, const UINT64 hashKey,
  92.                  const Movelist * legalMoves);
  93.  
  94. /**
  95.  * Add the specified move to the opening book.
  96.  */
  97. void addBookmove(Book * book, const Position * position,
  98.                  const Move move, const GameResult result,
  99.                  const bool personalResult);
  100.  
  101. /**
  102.  * Append the database specified by 'filename' to the book specified by 'book'.
  103.  *
  104.  * @param maximumNumberOfPlies the maximum distance between a book position
  105.  *        and the start position
  106.  */
  107. void appendBookDatabase(Book * book, const char *filename,
  108.                         int maximumNumberOfPlies);
  109.  
  110. /**
  111.  * Initialize this module.
  112.  *
  113.  * @return 0 if no errors occurred.
  114.  */
  115. int initializeModuleBook(void);
  116.  
  117. /**
  118.  * Test this module.
  119.  *
  120.  * @return 0 if all tests succeed.
  121.  */
  122. int testModuleBook(void);
  123.  
  124. #endif
  125.