Subversion Repositories Games.Chess Giants

Rev

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

  1. /*
  2.   Copyright (c) 2011-2013 Ronald de Man
  3. */
  4.  
  5. #ifndef RTB_CORE_HPP_
  6. #define RTB_CORE_HPP_
  7.  
  8. #ifndef _WIN32
  9. #define SEP_CHAR ':'
  10. #define FD int
  11. #define FD_ERR -1
  12. #else
  13. #include <windows.h>
  14. #define SEP_CHAR ';'
  15. #define FD HANDLE
  16. #define FD_ERR INVALID_HANDLE_VALUE
  17. #endif
  18.  
  19. #include <stdint.h>
  20.  
  21. #define WDLSUFFIX ".rtbw"
  22. #define DTZSUFFIX ".rtbz"
  23. #define TBPIECES 6
  24.  
  25. #define WDL_MAGIC 0x5d23e871
  26. #define DTZ_MAGIC 0xa50c66d7
  27.  
  28. #define TBHASHBITS 11
  29.  
  30. using ubyte = unsigned char;
  31. using ushort = unsigned short;
  32.  
  33. struct TBHashEntry;
  34.  
  35. using base_t = uint64_t;
  36.  
  37. struct PairsData {
  38.     char *indextable;
  39.     ushort *sizetable;
  40.     ubyte *data;
  41.     ushort *offset;
  42.     ubyte *symlen;
  43.     ubyte *sympat;
  44.     int blocksize;
  45.     int idxbits;
  46.     int min_len;
  47.     base_t base[1]; // C++ complains about base[]...
  48. };
  49.  
  50. struct TBEntry {
  51.     char *data;
  52.     uint64_t key;
  53.     uint64_t mapping;
  54.     std::atomic<ubyte> ready;
  55.     ubyte num;
  56.     ubyte symmetric;
  57.     ubyte has_pawns;
  58. }
  59. #ifndef _MSC_VER
  60. __attribute__((__may_alias__)) // Pierre-Marie Baty -- this is not supported by MSVC
  61. #endif // !_MSC_VER
  62. ;
  63.  
  64. struct TBEntry_piece {
  65.     char *data;
  66.     uint64_t key;
  67.     uint64_t mapping;
  68.     std::atomic<ubyte> ready;
  69.     ubyte num;
  70.     ubyte symmetric;
  71.     ubyte has_pawns;
  72.     ubyte enc_type;
  73.     struct PairsData *precomp[2];
  74.     int factor[2][TBPIECES];
  75.     ubyte pieces[2][TBPIECES];
  76.     ubyte norm[2][TBPIECES];
  77. };
  78.  
  79. struct TBEntry_pawn {
  80.     char *data;
  81.     uint64_t key;
  82.     uint64_t mapping;
  83.     std::atomic<ubyte> ready;
  84.     ubyte num;
  85.     ubyte symmetric;
  86.     ubyte has_pawns;
  87.     ubyte pawns[2];
  88.     struct {
  89.         struct PairsData *precomp[2];
  90.         int factor[2][TBPIECES];
  91.         ubyte pieces[2][TBPIECES];
  92.         ubyte norm[2][TBPIECES];
  93.     } file[4];
  94. };
  95.  
  96. struct DTZEntry_piece {
  97.     char *data;
  98.     uint64_t key;
  99.     uint64_t mapping;
  100.     std::atomic<ubyte> ready;
  101.     ubyte num;
  102.     ubyte symmetric;
  103.     ubyte has_pawns;
  104.     ubyte enc_type;
  105.     struct PairsData *precomp;
  106.     int factor[TBPIECES];
  107.     ubyte pieces[TBPIECES];
  108.     ubyte norm[TBPIECES];
  109.     ubyte flags; // accurate, mapped, side
  110.     ushort map_idx[4];
  111.     ubyte *map;
  112. };
  113.  
  114. struct DTZEntry_pawn {
  115.     char *data;
  116.     uint64_t key;
  117.     uint64_t mapping;
  118.     std::atomic<ubyte> ready;
  119.     ubyte num;
  120.     ubyte symmetric;
  121.     ubyte has_pawns;
  122.     ubyte pawns[2];
  123.     struct {
  124.         struct PairsData *precomp;
  125.         int factor[TBPIECES];
  126.         ubyte pieces[TBPIECES];
  127.         ubyte norm[TBPIECES];
  128.     } file[4];
  129.     ubyte flags[4];
  130.     ushort map_idx[4][4];
  131.     ubyte *map;
  132. };
  133.  
  134. struct TBHashEntry {
  135.     uint64_t key;
  136.     struct TBEntry *ptr;
  137. };
  138.  
  139. struct DTZTableEntry {
  140.     uint64_t key1;
  141.     uint64_t key2;
  142.     std::atomic<TBEntry*> entry;
  143. };
  144.  
  145. #endif
  146.