Subversion Repositories Games.Chess Giants

Rev

Rev 108 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 108 Rev 154
Line 35... Line 35...
35
#include <time.h>
35
#include <time.h>
36
#include <stdio.h>
36
#include <stdio.h>
37
#include <assert.h>
37
#include <assert.h>
38
#include <stdlib.h>
38
#include <stdlib.h>
39
#include <string.h>
39
#include <string.h>
40
#if !defined(TYPES_INCLUDED)
-
 
41
#  define TYPES_INCLUDED
40
#pragma once
42
#  if !defined (UNIX)
41
#  if !defined (UNIX)
43
#    define RESTRICT __restrict
42
#    define RESTRICT __restrict
44
#  else
43
#  else
45
#    define RESTRICT
44
#    define RESTRICT
46
#  endif
45
#  endif
Line 67... Line 66...
67
#  endif
66
#  endif
68
#  if !defined(LOGDIR)
67
#  if !defined(LOGDIR)
69
#    define   LOGDIR       "."
68
#    define   LOGDIR       "."
70
#  endif
69
#  endif
71
#  if !defined(TBDIR)
70
#  if !defined(TBDIR)
72
#    define   TBDIR        "./TB"
71
#    define   TBDIR        "./syzygy"
73
#  endif
72
#  endif
74
#  if !defined(RCDIR)
73
#  if !defined(RCDIR)
75
#    define   RCDIR        "."
74
#    define   RCDIR        "."
76
#  endif
75
#  endif
77
#  include "lock.h"
76
#  include "lock.h"
Line 83... Line 82...
83
#  define SORT_BLOCK                         4000000
82
#  define SORT_BLOCK                         4000000
84
#  define LEARN_INTERVAL                          10
83
#  define LEARN_INTERVAL                          10
85
#  define LEARN_COUNTER_BAD                      -80
84
#  define LEARN_COUNTER_BAD                      -80
86
#  define LEARN_COUNTER_GOOD                    +100
85
#  define LEARN_COUNTER_GOOD                    +100
87
#  define MATE                                 32768
86
#  define MATE                                 32768
-
 
87
#  define TBWIN                                31000
88
#  define PAWN_VALUE                             100
88
#  define PAWN_VALUE                             100
89
#  define KNIGHT_VALUE                           305
89
#  define KNIGHT_VALUE                           305
90
#  define BISHOP_VALUE                           305
90
#  define BISHOP_VALUE                           305
91
#  define ROOK_VALUE                             490
91
#  define ROOK_VALUE                             490
92
#  define QUEEN_VALUE                           1000
92
#  define QUEEN_VALUE                           1000
93
#  define KING_VALUE                           40000
93
#  define KING_VALUE                           40000
-
 
94
#  define FOREVER                                  1
94
#  if !defined(CLOCKS_PER_SEC)
95
#  if !defined(CLOCKS_PER_SEC)
95
#    define CLOCKS_PER_SEC 1000000
96
#    define CLOCKS_PER_SEC 1000000
96
#  endif
97
#  endif
97
typedef enum {
98
typedef enum {
98
  A1, B1, C1, D1, E1, F1, G1, H1,
99
  A1, B1, C1, D1, E1, F1, G1, H1,
Line 122... Line 123...
122
  int8_t castle[2];
123
  int8_t castle[2];
123
  uint8_t enpassant_target;
124
  uint8_t enpassant_target;
124
  uint8_t reversible;
125
  uint8_t reversible;
125
} SEARCH_POSITION;
126
} SEARCH_POSITION;
126
typedef struct {
127
typedef struct {
127
  int move1;
128
  uint32_t move1;
128
  int move2;
129
  uint32_t move2;
129
} KILLER;
130
} KILLER;
130
typedef struct {
131
typedef struct {
131
  uint64_t pieces[7];
132
  uint64_t pieces[7];
132
} BB_PIECES;
133
} BB_PIECES;
133
typedef struct {
134
typedef struct {
Line 223... Line 224...
223
typedef struct tree {
224
typedef struct tree {
224
/* commonly used variables */
225
/* commonly used variables */
225
  SEARCH_POSITION status[MAXPLY + 3];
226
  SEARCH_POSITION status[MAXPLY + 3];
226
  NEXT_MOVE next_status[MAXPLY];
227
  NEXT_MOVE next_status[MAXPLY];
227
  KILLER killers[MAXPLY];
228
  KILLER killers[MAXPLY];
-
 
229
  KILLER counter_move[4096];
-
 
230
  KILLER move_pair[4096];
228
  POSITION position;
231
  POSITION position;
229
  uint64_t save_hash_key[MAXPLY + 3];
232
  uint64_t save_hash_key[MAXPLY + 3];
230
  uint64_t save_pawn_hash_key[MAXPLY + 3];
233
  uint64_t save_pawn_hash_key[MAXPLY + 3];
231
  uint64_t rep_list[256];
234
  uint64_t rep_list[256];
232
  int curmv[MAXPLY];
235
  int curmv[MAXPLY];
Line 316... Line 319...
316
#  define EVALUATION                  16
319
#  define EVALUATION                  16
317
#  define ILLEGAL                      0
320
#  define ILLEGAL                      0
318
#  define LEGAL                        1
321
#  define LEGAL                        1
319
#  define IN_WINDOW                    2
322
#  define IN_WINDOW                    2
320
#  define FAIL_HIGH                    3
323
#  define FAIL_HIGH                    3
321
#if /*defined(UNIX) &&*/ !defined(INLINEASM) // Pierre-Marie Baty -- we also use them on Windows...
-
 
322
int CDECL PopCnt(uint64_t);
324
#define PopCnt(v) __builtin_popcountll(v)
323
int CDECL MSB(uint64_t);
325
#define LSB(v)    __builtin_ctzll(v)
324
int CDECL LSB(uint64_t);
326
#define MSB(v)    (63 - __builtin_clzll(v))
325
#endif
-
 
326
void AlignedMalloc(void **, int, size_t);
327
void AlignedMalloc(void **, uint64_t, size_t);
327
void AlignedRemalloc(void **, int, size_t);
328
void AlignedRemalloc(void **, uint64_t, size_t);
328
void Analyze(void);
329
void Analyze(void);
329
void Annotate(void);
330
void Annotate(void);
330
void AnnotateHeaderHTML(char *, FILE *);
331
void AnnotateHeaderHTML(char *, FILE *);
331
void AnnotateFooterHTML(FILE *);
332
void AnnotateFooterHTML(FILE *);
332
void AnnotatePositionHTML(TREE *RESTRICT, int, FILE *);
333
void AnnotatePositionHTML(TREE *RESTRICT, int, FILE *);
Line 339... Line 340...
339
uint64_t Attacked(TREE *RESTRICT, int, uint64_t);
340
uint64_t Attacked(TREE *RESTRICT, int, uint64_t);
340
uint64_t AttacksFrom(TREE *RESTRICT, int, int);
341
uint64_t AttacksFrom(TREE *RESTRICT, int, int);
341
uint64_t AttacksTo(TREE *RESTRICT, int);
342
uint64_t AttacksTo(TREE *RESTRICT, int);
342
void AutoTune(int, char **);
343
void AutoTune(int, char **);
343
int Bench(int, int);
344
int Bench(int, int);
344
int Bench_PGO(int, int);
-
 
345
int Book(TREE *RESTRICT, int);
345
int Book(TREE *RESTRICT, int);
346
void BookClusterIn(FILE *, int, BOOK_POSITION *);
346
void BookClusterIn(FILE *, int, BOOK_POSITION *);
347
void BookClusterOut(FILE *, int, BOOK_POSITION *);
347
void BookClusterOut(FILE *, int, BOOK_POSITION *);
348
int BookIn32(unsigned char *);
348
int BookIn32(unsigned char *);
349
float BookIn32f(unsigned char *);
349
float BookIn32f(unsigned char *);
Line 380... Line 380...
380
char *DisplayTime(unsigned);
380
char *DisplayTime(unsigned);
381
char *Display2Times(unsigned);
381
char *Display2Times(unsigned);
382
char *DisplayTimeKibitz(unsigned);
382
char *DisplayTimeKibitz(unsigned);
383
void DisplayChessMove(char *, int);
383
void DisplayChessMove(char *, int);
384
int Drawn(TREE *RESTRICT, int);
384
int Drawn(TREE *RESTRICT, int);
-
 
385
int  DTZtoWDL(int, int);
385
void Edit(void);
386
void Edit(void);
386
#  if !defined(NOEGTB)
-
 
387
int EGTBProbe(TREE *RESTRICT, int, int, int *);
-
 
388
void EGTBPV(TREE *RESTRICT, int);
-
 
389
#  endif
-
 
390
int Evaluate(TREE *RESTRICT, int, int, int, int);
387
int Evaluate(TREE *RESTRICT, int, int, int, int);
391
void EvaluateBishops(TREE *RESTRICT, int);
388
void EvaluateBishops(TREE *RESTRICT, int);
392
void EvaluateCastling(TREE *RESTRICT, int, int);
389
void EvaluateCastling(TREE *RESTRICT, int, int);
393
int EvaluateDraws(TREE *RESTRICT, int, int, int);
390
int EvaluateDraws(TREE *RESTRICT, int, int, int);
394
int EvaluateHasOpposition(int, int, int);
391
int EvaluateHasOpposition(int, int, int);
Line 425... Line 422...
425
uint64_t InitializeMagicBishop(int, uint64_t);
422
uint64_t InitializeMagicBishop(int, uint64_t);
426
uint64_t InitializeMagicRook(int, uint64_t);
423
uint64_t InitializeMagicRook(int, uint64_t);
427
uint64_t InitializeMagicOccupied(int *, int, uint64_t);
424
uint64_t InitializeMagicOccupied(int *, int, uint64_t);
428
void InitializeMasks(void);
425
void InitializeMasks(void);
429
void InitializePawnMasks(void);
426
void InitializePawnMasks(void);
-
 
427
void InitializeLMP(void);
430
void InitializeReductions(void);
428
void InitializeLMR(void);
431
void InitializeSMP(void);
429
void InitializeSMP(void);
432
int IInitializeTb(char *);
430
int IInitializeTb(char *);
433
int InputMove(TREE *RESTRICT, int, int, int, int, char *);
431
int InputMove(TREE *RESTRICT, int, int, int, int, char *);
434
int InputMoveICS(TREE *RESTRICT, int, int, int, int, char *);
432
int InputMoveICS(TREE *RESTRICT, int, int, int, int, char *);
435
uint64_t InterposeSquares(int, int, int);
433
uint64_t InterposeSquares(int, int, int);
Line 444... Line 442...
444
void LearnBook(void);
442
void LearnBook(void);
445
int LearnFunction(int, int, int, int);
443
int LearnFunction(int, int, int, int);
446
void LearnValue(int, int);
444
void LearnValue(int, int);
447
void MakeMove(TREE *RESTRICT, int, int, int);
445
void MakeMove(TREE *RESTRICT, int, int, int);
448
void MakeMoveRoot(TREE *RESTRICT, int, int);
446
void MakeMoveRoot(TREE *RESTRICT, int, int);
-
 
447
int Mated(TREE *RESTRICT, int, int);
449
void NewGame(int);
448
int RootMoveEGTB(int);
450
int NextMove(TREE *RESTRICT, int, int, int, int);
449
int NextMove(TREE *RESTRICT, int, int, int, int);
451
int NextRootMove(TREE *RESTRICT, TREE *RESTRICT, int);
450
int NextRootMove(TREE *RESTRICT, TREE *RESTRICT, int);
452
int NextRootMoveParallel(void);
451
int NextRootMoveParallel(void);
453
void NextSort(TREE *RESTRICT, int);
452
void NextSort(TREE *RESTRICT, int);
454
int Option(TREE *RESTRICT);
453
int Option(TREE *RESTRICT);
Line 459... Line 458...
459
int ParseTime(char *);
458
int ParseTime(char *);
460
void Pass(void);
459
void Pass(void);
461
int PinnedOnKing(TREE *RESTRICT, int, int);
460
int PinnedOnKing(TREE *RESTRICT, int, int);
462
int Ponder(int);
461
int Ponder(int);
463
void Print(int, char *, ...);
462
void Print(int, char *, ...);
-
 
463
int ProbeDTZ(TREE * RESTRICT tree, int ply, int wtm);
464
int HashProbe(TREE *RESTRICT, int, int, int, int, int, int*);
464
int HashProbe(TREE *RESTRICT, int, int, int, int, int, int*);
465
void HashStore(TREE *RESTRICT, int, int, int, int, int, int);
465
void HashStore(TREE *RESTRICT, int, int, int, int, int, int);
466
void HashStorePV(TREE *RESTRICT, int, int);
466
void HashStorePV(TREE *RESTRICT, int, int);
467
int Quiesce(TREE *RESTRICT, int, int, int, int, int);
467
int Quiesce(TREE *RESTRICT, int, int, int, int, int);
468
int QuiesceEvasions(TREE *RESTRICT, int, int, int, int);
468
int QuiesceEvasions(TREE *RESTRICT, int, int, int, int);
Line 487... Line 487...
487
int SearchNull(TREE * RESTRICT, int, int, int, int);
487
int SearchNull(TREE * RESTRICT, int, int, int, int);
488
void Trace(TREE *RESTRICT, int, int, int, int, int, const char *, int, int, int);
488
void Trace(TREE *RESTRICT, int, int, int, int, int, const char *, int, int, int);
489
void SetBoard(TREE *, int, char **, int);
489
void SetBoard(TREE *, int, char **, int);
490
void SetChessBitBoards(TREE *);
490
void SetChessBitBoards(TREE *);
491
void SharedFree(void *address);
491
void SharedFree(void *address);
492
void SortRootMoves(void);
492
void SortRootMoves(TREE *RESTRICT, int);
493
int Split(TREE *RESTRICT);
493
int Split(TREE *RESTRICT);
494
int StrCnt(char *, char);
494
int StrCnt(char *, char);
495
int SEE(TREE *RESTRICT, int, int);
495
int SEE(TREE *RESTRICT, int, int);
496
int SEEO(TREE *RESTRICT, int, int);
496
int SEEO(TREE *RESTRICT, int, int);
497
void Test(char *, FILE *, int, int);
497
void Test(char *, FILE *, int, int);
Line 559... Line 559...
559
#  define BishopMobility(square, occ) *(magic_bishop_mobility_indices[square]+((((occ)&magic_bishop_mask[square])*magic_bishop[square])>>magic_bishop_shift[square]))
559
#  define BishopMobility(square, occ) *(magic_bishop_mobility_indices[square]+((((occ)&magic_bishop_mask[square])*magic_bishop[square])>>magic_bishop_shift[square]))
560
#  define KingAttacks(square) king_attacks[square]
560
#  define KingAttacks(square) king_attacks[square]
561
#  define KnightAttacks(square) knight_attacks[square]
561
#  define KnightAttacks(square) knight_attacks[square]
562
#  define PawnAttacks(side, square)   pawn_attacks[side][square]
562
#  define PawnAttacks(side, square)   pawn_attacks[side][square]
563
#  define Reversible(p)               (tree->status[p].reversible)
563
#  define Reversible(p)               (tree->status[p].reversible)
-
 
564
#  define ReversibleMove(m)           (!CaptureOrPromote(m) && Piece(m) != pawn)
564
#  define RookAttacks(square, occ) *(magic_rook_indices[square]+((((occ)&magic_rook_mask[square])*magic_rook[square])>>magic_rook_shift[square]))
565
#  define RookAttacks(square, occ) *(magic_rook_indices[square]+((((occ)&magic_rook_mask[square])*magic_rook[square])>>magic_rook_shift[square]))
565
#  define RookMobility(square, occ) *(magic_rook_mobility_indices[square]+((((occ)&magic_rook_mask[square])*magic_rook[square])>>magic_rook_shift[square]))
566
#  define RookMobility(square, occ) *(magic_rook_mobility_indices[square]+((((occ)&magic_rook_mask[square])*magic_rook[square])>>magic_rook_shift[square]))
566
#  define QueenAttacks(square, occ)   (BishopAttacks(square, occ)|RookAttacks(square, occ))
567
#  define QueenAttacks(square, occ)   (BishopAttacks(square, occ)|RookAttacks(square, occ))
567
#  define Rank(x)        ((x)>>3)
568
#  define Rank(x)        ((x)>>3)
568
#  define File(x)        ((x)&7)
569
#  define File(x)        ((x)&7)
Line 611... Line 612...
611
#  define PieceValues(c, p)      (piece_values[c][p])
612
#  define PieceValues(c, p)      (piece_values[c][p])
612
#  define TotalAllPieces         (tree->position.total_all_pieces)
613
#  define TotalAllPieces         (tree->position.total_all_pieces)
613
#  define Material               (tree->position.material_evaluation)
614
#  define Material               (tree->position.material_evaluation)
614
#  define MaterialSTM(side)      ((side) ? Material : -Material)
615
#  define MaterialSTM(side)      ((side) ? Material : -Material)
615
#  define MateScore(s)           (Abs(s) > 32000)
616
#  define MateScore(s)           (Abs(s) > 32000)
-
 
617
#  define EGTBScore(s)           (Abs(s) > 30000 && Abs(s) < 32000)
616
#  define Castle(ply, c)         (tree->status[ply].castle[c])
618
#  define Castle(ply, c)         (tree->status[ply].castle[c])
617
#  define HashKey                (tree->position.hash_key)
619
#  define HashKey                (tree->position.hash_key)
618
#  define PawnHashKey            (tree->position.pawn_hash_key)
620
#  define PawnHashKey            (tree->position.pawn_hash_key)
619
#  define EnPassant(ply)         (tree->status[ply].enpassant_target)
621
#  define EnPassant(ply)         (tree->status[ply].enpassant_target)
620
#  define EnPassantTarget(ply)   (EnPassant(ply) ? SetMask(EnPassant(ply)) : 0)
622
#  define EnPassantTarget(ply)   (EnPassant(ply) ? SetMask(EnPassant(ply)) : 0)
Line 643... Line 645...
643
        tree->pv[ply-1].pathh=ph;                                             \
645
        tree->pv[ply-1].pathh=ph;                                             \
644
        tree->pv[ply-1].pathd=iteration;} while(0)
646
        tree->pv[ply-1].pathd=iteration;} while(0)
645
#  if defined(INLINEASM)
647
#  if defined(INLINEASM)
646
#    include "inline.h"
648
#    include "inline.h"
647
#  endif
649
#  endif
648
#endif
-
 
649
/* *INDENT-ON* */
650
/* *INDENT-ON* */