1
/* portability-macros header prefix */
3
/* Windows requires a __declspec(dllexport) tag, etc */
5
# define DLLEXPORT __declspec(dllexport)
6
# define STDCALL __stdcall
14
# define EXTERN_C extern "C"
29
/* end of portability-macros section */
31
#define DDS_VERSION 20101 /* Version 2.1.1. Allowing for 2 digit
39
/*#define _CRTDBG_MAP_ALLOC */ /* MEMORY LEAK? */
41
/*#include <crtdbg.h> */ /* MEMORY LEAK? */
47
/*#define STAT*/ /* Define STAT to generate a statistics log, stat.txt */
48
/*#define TTDEBUG*/ /* Define TTDEBUG to generate transposition table debug information.
49
Only for a single thread! */
52
#define SEARCHSIZE 20000
60
#define INFINITY 32000
62
#define MAXNOOFTHREADS 16
76
#define NINIT 250000/*400000*/
77
#define WINIT 700000/*1000000*/
80
#define SIMILARDEALLIMIT 5
81
#define SIMILARMAXWINNODES 700000
83
#define MAXNOOFBOARDS 20
85
#define Max(x, y) (((x) >= (y)) ? (x) : (y))
86
#define Min(x, y) (((x) <= (y)) ? (x) : (y))
88
/* "hand" is leading hand, "relative" is hand relative leading
90
The handId macro implementation follows a solution
92
All hand identities are given as
93
0=NORTH, 1=EAST, 2=SOUTH, 3=WEST. */
95
#define handId(hand, relative) (hand + relative) & 3
98
struct gameInfo { /* All info of a particular deal */
105
unsigned short int suit[4][4];
106
/* 1st index is hand id, 2nd index is suit id */
113
unsigned short int sequence; /* Whether or not this move is
114
the first in a sequence */
115
short int weight; /* Weight used at sorting */
119
struct moveType move[14];
124
struct highCardType {
129
struct futureTricks {
144
int currentTrickSuit[3];
145
int currentTrickRank[3];
146
unsigned int remainCards[4][4];
153
int currentTrickSuit[3];
154
int currentTrickRank[3];
155
char remainCards[80];
160
unsigned short int rankInSuit[4][4]; /* 1st index is hand, 2nd index is
166
unsigned short int removedRanks[4]; /* Ranks removed from board,
168
unsigned short int winRanks[50][4]; /* Cards that win by rank,
169
indices are depth and suit */
170
unsigned char length[4][4];
175
int first[50]; /* Hand that leads the trick for each ply*/
176
int high[50]; /* Hand that is presently winning the trick */
177
struct moveType move[50]; /* Presently winning move */
178
int handRelFirst; /* The current hand, relative first hand */
179
int tricksMAX; /* Aggregated tricks won by MAX */
180
struct highCardType winner[4]; /* Winning rank of the trick,
182
struct highCardType secondBest[4]; /* Second best rank, index is suit id. */
185
struct posSearchType {
186
struct winCardType * posSearchPoint;
188
struct posSearchType * left;
189
struct posSearchType * right;
193
struct nodeCardsType {
194
char ubound; /* ubound and
195
lbound for the N-S side */
205
struct nodeCardsType * first;
206
struct winCardType * prevWin;
207
struct winCardType * nextWin;
208
struct winCardType * next;
214
unsigned short int winRanks[4];
217
struct relRanksType {
223
struct adaptWinRanksType {
224
unsigned short int winRanks[14];
229
struct nodeCardsType * cardsP;
235
unsigned short int suit[4][4];
245
struct deal deals[MAXNOOFBOARDS];
246
int target[MAXNOOFBOARDS];
247
int solutions[MAXNOOFBOARDS];
248
int mode[MAXNOOFBOARDS];
251
struct solvedBoards {
254
struct futureTricks solvedBoard[MAXNOOFBOARDS];
260
struct solvedBoards *solvedp;
267
unsigned int cards[4][4];
270
struct ddTableDealPBN {
274
struct ddTableResults {
278
struct localVarType {
279
int nodeTypeStore[4];
281
unsigned short int lowestWin[50][4];
289
struct pos iniPosition;
290
struct pos lookAheadPos; /* Is initialized for starting
292
struct moveType forbiddenMoves[14];
293
struct moveType initialMoves[4];
295
struct movePlyType movePly[50];
297
struct gameInfo game;
301
unsigned short int diffDeal;
302
unsigned short int aggDeal;
308
struct moveType bestMove[50];
309
struct moveType bestMoveTT[50];
310
struct winCardType temp_win[5];
317
int nodeSetSizeLimit;
320
__int64 maxmem; /* bytes */
334
struct relRanksType * rel;
335
struct adaptWinRanksType * adaptWins;
337
struct posSearchType *rootnp[14][4];
338
struct winCardType **pw;
339
struct nodeCardsType **pn;
340
struct posSearchType **pl;
341
struct nodeCardsType * nodeCards;
342
struct winCardType * winCards;
343
struct posSearchType * posSearch;
344
/*struct ttStoreType * ttStore;
346
unsigned short int iniRemovedRanks[4];
348
int nodeSetSize; /* Index with range 0 to nodeSetSizeLimit */
349
int winSetSize; /* Index with range 0 to winSetSizeLimit */
350
int lenSetSize; /* Index with range 0 to lenSetSizeLimit */
354
extern CRITICAL_SECTION solv_crit;
357
extern int noOfThreads;
358
extern int noOfCores;
359
extern struct localVarType localVar[MAXNOOFTHREADS];
360
extern struct gameInfo game;
362
extern struct gameInfo * gameStore;
363
extern struct pos position, iniPosition, lookAheadPos;
364
extern struct moveType move[13];
365
extern struct movePlyType movePly[50];
366
extern struct searchType searchData;
367
extern struct moveType forbiddenMoves[14]; /* Initial depth moves that will be
368
excluded from the search */
369
extern struct moveType initialMoves[4];
370
extern struct moveType highMove;
371
extern struct winCardType **pw;
372
extern struct nodeCardsType **pn;
373
extern struct posSearchType **pl;
375
extern int * highestRank;
376
extern int * counttable;
377
extern struct adaptWinRanksType * adaptWins;
378
extern unsigned short int bitMapRank[16];
379
extern unsigned short int relRankInSuit[4][4];
381
extern int score1Counts[50], score0Counts[50];
382
extern int c1[50], c2[50], c3[50], c4[50], c5[50], c6[50], c7[50],
384
extern int nodeTypeStore[4]; /* Look-up table for determining if
385
node is MAXNODE or MINNODE */
386
extern int lho[4], rho[4], partner[4];
387
extern int trumpContract;
389
extern int nodes; /* Number of nodes searched */
390
extern int no[50]; /* Number of nodes searched on each
394
extern int treeDepth;
395
extern int tricksTarget; /* No of tricks for MAX in order to
396
meet the game goal, e.g. to make the
398
extern int tricksTargetOpp; /* Target no of tricks for MAX
402
extern int handToPlay;
403
extern int searchTraceFlag;
405
extern int depthCount;
407
extern int nodeSetSizeLimit;
408
extern int winSetSizeLimit;
409
extern int lenSetSizeLimit;
410
extern int estTricks[4];
412
extern int suppressTTlog;
413
extern unsigned char suitChar[4];
414
extern unsigned char rankChar[15];
415
extern unsigned char handChar[4];
416
extern unsigned char cardRank[15], cardSuit[5], cardHand[4];
417
extern unsigned char cardSuitSds[5];
418
extern struct handStateType handState;
419
extern int totalNodes;
420
extern struct futureTricks fut, ft;
421
extern struct futureTricks *futp;
422
extern char stri[128];
424
extern FILE *fp, /**fp2, *fp7, *fp11,*/ *fpx;
425
/* Pointers to logs */
427
extern struct ttStoreType * ttStore;
428
extern int lastTTstore;
429
extern int ttCollect;
430
extern int suppressTTlog;
432
EXTERN_C DLLEXPORT int STDCALL SolveBoard(struct deal dl,
433
int target, int solutions, int mode, struct futureTricks *futp, int threadIndex);
436
EXTERN_C DLLEXPORT int STDCALL SolveBoardPBN(struct dealPBN dlpbn, int target,
437
int solutions, int mode, struct futureTricks *futp, int thrId);
440
EXTERN_C DLLEXPORT int STDCALL CalcDDtable(struct ddTableDeal tableDeal,
441
struct ddTableResults * tablep);
444
EXTERN_C DLLEXPORT int STDCALL CalcDDtablePBN(struct ddTableDealPBN tableDealPBN,
445
struct ddTableResults * tablep);
449
EXTERN_C void InitStart(int gb_ram, int ncores);
450
void InitGame(int gameNo, int moveTreeFlag, int first, int handRelFirst, int thrId);
451
void InitSearch(struct pos * posPoint, int depth,
452
struct moveType startMoves[], int first, int mtd, int thrId);
453
int ABsearch(struct pos * posPoint, int target, int depth, int thrId);
454
void Make(struct pos * posPoint, unsigned short int trickCards[4],
455
int depth, int thrId);
456
int MoveGen(struct pos * posPoint, int depth, int thrId);
457
void InsertSort(int n, int depth, int thrId);
458
void UpdateWinner(struct pos * posPoint, int suit);
459
void UpdateSecondBest(struct pos * posPoint, int suit);
460
int WinningMove(struct moveType * mvp1, struct moveType * mvp2, int thrId);
461
int AdjustMoveList(int thrId);
462
int QuickTricks(struct pos * posPoint, int hand,
463
int depth, int target, int *result, int thrId);
464
int LaterTricksMIN(struct pos *posPoint, int hand, int depth, int target, int thrId);
465
int LaterTricksMAX(struct pos *posPoint, int hand, int depth, int target, int thrId);
466
struct nodeCardsType * CheckSOP(struct pos * posPoint, struct nodeCardsType
467
* nodep, int target, int tricks, int * result, int *value, int thrId);
468
struct nodeCardsType * UpdateSOP(struct pos * posPoint, struct nodeCardsType
470
struct nodeCardsType * FindSOP(struct pos * posPoint,
471
struct winCardType * nodeP, int firstHand,
472
int target, int tricks, int * valp, int thrId);
473
struct nodeCardsType * BuildPath(struct pos * posPoint,
474
struct posSearchType *nodep, int * result, int thrId);
475
void BuildSOP(struct pos * posPoint, int tricks, int firstHand, int target,
476
int depth, int scoreFlag, int score, int thrId);
477
struct posSearchType * SearchLenAndInsert(struct posSearchType
478
* rootp, __int64 key, int insertNode, int *result, int thrId);
479
void Undo(struct pos * posPoint, int depth, int thrId);
480
int CheckDeal(struct moveType * cardp, int thrId);
481
int InvBitMapRank(unsigned short bitMap);
482
int InvWinMask(int mask);
483
void ReceiveTTstore(struct pos *posPoint, struct nodeCardsType * cardsP, int target,
484
int depth, int thrId);
485
int NextMove(struct pos *posPoint, int depth, int thrId);
486
int DumpInput(int errCode, struct deal dl, int target, int solutions, int mode);
487
void Wipe(int thrId);
488
void AddNodeSet(int thrId);
489
void AddLenSet(int thrId);
490
void AddWinSet(int thrId);
492
void PrintDeal(FILE *fp, unsigned short ranks[4][4]);
494
int SolveAllBoards4(struct boards *bop, struct solvedBoards *solvedp,
495
int timeSupervision, int remainTime);