~ubuntu-branches/ubuntu/saucy/dds/saucy

« back to all changes in this revision

Viewing changes to .pc/dll.h-__int64/dll.h

  • Committer: Package Import Robot
  • Author(s): Christoph Berg
  • Date: 2011-12-31 18:02:22 UTC
  • mfrom: (11.2.2 sid)
  • Revision ID: package-import@ubuntu.com-20111231180222-ftl7vynb2iftg16m
Tags: 2.1.2+ddd105-1
* New dds upstream version.
* Update watch file to mangle the ddd version to 1.0.5.
* Source format 3.0.
* Update to dh_python2, supporting multiple python versions in parallel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* portability-macros header prefix */
 
2
 
 
3
/* Windows requires a __declspec(dllexport) tag, etc */
 
4
#if defined(_WIN32)
 
5
#    define DLLEXPORT __declspec(dllexport)
 
6
#    define STDCALL __stdcall
 
7
#else
 
8
#    define DLLEXPORT
 
9
#    define STDCALL
 
10
#    define INT8 char
 
11
#endif
 
12
 
 
13
#ifdef __cplusplus
 
14
#    define EXTERN_C extern "C"
 
15
#else
 
16
#    define EXTERN_C
 
17
#endif
 
18
 
 
19
#if defined(_WIN32)
 
20
#    include <windows.h>
 
21
#    include <process.h>
 
22
#endif
 
23
#if defined(_MSC_VER)
 
24
#    include <intrin.h>
 
25
#else
 
26
#    include <omp.h>
 
27
#endif
 
28
 
 
29
/* end of portability-macros section */
 
30
 
 
31
#define DDS_VERSION             20101   /* Version 2.1.1. Allowing for 2 digit
 
32
                                        minor versions */
 
33
 
 
34
#define PBN
 
35
 
 
36
/*#define BENCH*/
 
37
 
 
38
#include <stdio.h>
 
39
/*#define _CRTDBG_MAP_ALLOC */ /* MEMORY LEAK? */
 
40
#include <stdlib.h>
 
41
/*#include <crtdbg.h> */  /* MEMORY LEAK? */
 
42
#include <string.h>
 
43
#include <time.h>
 
44
#include <assert.h>
 
45
#include <math.h>
 
46
 
 
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! */
 
50
 
 
51
#ifdef  TTDEBUG
 
52
#define SEARCHSIZE  20000
 
53
#else
 
54
#define SEARCHSIZE  1
 
55
#endif
 
56
 
 
57
#if defined(INFINITY)
 
58
#    undef INFINITY
 
59
#endif
 
60
#define INFINITY    32000
 
61
 
 
62
#define MAXNOOFTHREADS  16
 
63
 
 
64
#define MAXNODE     1
 
65
#define MINNODE     0
 
66
 
 
67
#define TRUE        1
 
68
#define FALSE       0
 
69
 
 
70
#define MOVESVALID  1
 
71
#define MOVESLOCKED 2
 
72
 
 
73
#define NSIZE   100000
 
74
#define WSIZE   100000
 
75
#define LSIZE   20000
 
76
#define NINIT   250000/*400000*/
 
77
#define WINIT   700000/*1000000*/
 
78
#define LINIT   50000
 
79
 
 
80
#define SIMILARDEALLIMIT        5
 
81
#define SIMILARMAXWINNODES  700000
 
82
 
 
83
#define MAXNOOFBOARDS           20
 
84
 
 
85
#define Max(x, y) (((x) >= (y)) ? (x) : (y))
 
86
#define Min(x, y) (((x) <= (y)) ? (x) : (y))
 
87
 
 
88
/* "hand" is leading hand, "relative" is hand relative leading
 
89
hand.
 
90
The handId macro implementation follows a solution 
 
91
by Thomas Andrews. 
 
92
All hand identities are given as
 
93
0=NORTH, 1=EAST, 2=SOUTH, 3=WEST. */
 
94
 
 
95
#define handId(hand, relative) (hand + relative) & 3
 
96
 
 
97
 
 
98
struct gameInfo  {          /* All info of a particular deal */
 
99
  int declarer;
 
100
  int leadHand;
 
101
  int leadSuit;
 
102
  int leadRank;
 
103
  int first;
 
104
  int noOfCards;
 
105
  unsigned short int suit[4][4];
 
106
    /* 1st index is hand id, 2nd index is suit id */
 
107
};
 
108
 
 
109
 
 
110
struct moveType {
 
111
  unsigned char suit;
 
112
  unsigned char rank;
 
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 */
 
116
};
 
117
 
 
118
struct movePlyType {
 
119
  struct moveType move[14];             
 
120
  int current;
 
121
  int last;
 
122
};
 
123
 
 
124
struct highCardType {
 
125
  int rank;
 
126
  int hand;
 
127
};
 
128
 
 
129
struct futureTricks {
 
130
  int nodes;
 
131
  #ifdef BENCH
 
132
  int totalNodes;
 
133
  #endif
 
134
  int cards;
 
135
  int suit[13];
 
136
  int rank[13];
 
137
  int equals[13];
 
138
  int score[13];
 
139
};
 
140
 
 
141
struct deal {
 
142
  int trump;
 
143
  int first;
 
144
  int currentTrickSuit[3];
 
145
  int currentTrickRank[3];
 
146
  unsigned int remainCards[4][4];
 
147
};
 
148
 
 
149
 
 
150
struct dealPBN {
 
151
  int trump;
 
152
  int first;
 
153
  int currentTrickSuit[3];
 
154
  int currentTrickRank[3];
 
155
  char remainCards[80];
 
156
};
 
157
 
 
158
 
 
159
struct pos {
 
160
  unsigned short int rankInSuit[4][4];   /* 1st index is hand, 2nd index is
 
161
                                        suit id */
 
162
  int orderSet[4];
 
163
  int winOrderSet[4];
 
164
  int winMask[4];
 
165
  int leastWin[4];
 
166
  unsigned short int removedRanks[4];    /* Ranks removed from board,
 
167
                                        index is suit */
 
168
  unsigned short int winRanks[50][4];  /* Cards that win by rank,
 
169
                                       indices are depth and suit */
 
170
  unsigned char length[4][4];
 
171
  char ubound;
 
172
  char lbound;
 
173
  char bestMoveSuit;
 
174
  char bestMoveRank;
 
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,
 
181
                                    index is suit id. */
 
182
  struct highCardType secondBest[4]; /* Second best rank, index is suit id. */
 
183
};
 
184
 
 
185
struct posSearchType {
 
186
  struct winCardType * posSearchPoint; 
 
187
  __int64 suitLengths;
 
188
  struct posSearchType * left;
 
189
  struct posSearchType * right;
 
190
};
 
191
 
 
192
 
 
193
struct nodeCardsType {
 
194
  char ubound;  /* ubound and
 
195
                        lbound for the N-S side */
 
196
  char lbound;
 
197
  char bestMoveSuit;
 
198
  char bestMoveRank;
 
199
  char leastWin[4];
 
200
};
 
201
 
 
202
struct winCardType {
 
203
  int orderSet;
 
204
  int winMask;
 
205
  struct nodeCardsType * first;
 
206
  struct winCardType * prevWin;
 
207
  struct winCardType * nextWin;
 
208
  struct winCardType * next;
 
209
}; 
 
210
 
 
211
 
 
212
struct evalType {
 
213
  int tricks;
 
214
  unsigned short int winRanks[4];
 
215
};
 
216
 
 
217
struct relRanksType {
 
218
  int aggrRanks[4];
 
219
  int winMask[4];
 
220
  char relRank[15][4];
 
221
};
 
222
 
 
223
struct adaptWinRanksType {
 
224
  unsigned short int winRanks[14];
 
225
};
 
226
 
 
227
 
 
228
struct ttStoreType {
 
229
  struct nodeCardsType * cardsP;
 
230
  char tricksLeft;
 
231
  char target;
 
232
  char ubound;
 
233
  char lbound;
 
234
  unsigned char first;
 
235
  unsigned short int suit[4][4];
 
236
};
 
237
 
 
238
struct card {
 
239
  int suit;
 
240
  int rank;
 
241
};
 
242
 
 
243
struct boards {
 
244
  int noOfBoards;
 
245
  struct deal deals[MAXNOOFBOARDS];
 
246
  int target[MAXNOOFBOARDS];
 
247
  int solutions[MAXNOOFBOARDS];
 
248
  int mode[MAXNOOFBOARDS];
 
249
};
 
250
 
 
251
struct solvedBoards {
 
252
  int noOfBoards;
 
253
  int timeOut;
 
254
  struct futureTricks solvedBoard[MAXNOOFBOARDS];
 
255
};
 
256
 
 
257
struct paramType {
 
258
  int noOfBoards;
 
259
  struct boards *bop;
 
260
  struct solvedBoards *solvedp;
 
261
  int tstart;
 
262
  int timeSupervision;
 
263
  int remainTime;
 
264
};
 
265
 
 
266
struct ddTableDeal {
 
267
  unsigned int cards[4][4];
 
268
};
 
269
 
 
270
struct ddTableDealPBN {
 
271
  char cards[80];
 
272
};
 
273
 
 
274
struct ddTableResults {
 
275
  int resTable[5][4];
 
276
};
 
277
 
 
278
struct localVarType {
 
279
  int nodeTypeStore[4];
 
280
  int trump;
 
281
  unsigned short int lowestWin[50][4];
 
282
  int nodes;
 
283
  int trickNodes;
 
284
  int no[50];
 
285
  int iniDepth;
 
286
  int handToPlay;
 
287
  int payOff;
 
288
  int val;
 
289
  struct pos iniPosition;
 
290
  struct pos lookAheadPos; /* Is initialized for starting
 
291
                                                        alpha-beta search */
 
292
  struct moveType forbiddenMoves[14];
 
293
  struct moveType initialMoves[4];
 
294
  struct moveType cd;
 
295
  struct movePlyType movePly[50];
 
296
  int tricksTarget;
 
297
  struct gameInfo game;
 
298
  int newDeal;
 
299
  int newTrump;
 
300
  int similarDeal;
 
301
  unsigned short int diffDeal;
 
302
  unsigned short int aggDeal;
 
303
  int estTricks[4];
 
304
  FILE *fp2;
 
305
  FILE *fp7;
 
306
  FILE *fp11;
 
307
  /*FILE *fdp */
 
308
  struct moveType bestMove[50];
 
309
  struct moveType bestMoveTT[50];
 
310
  struct winCardType temp_win[5];
 
311
  /*int hiwinSetSize;
 
312
  int hinodeSetSize;
 
313
  int hilenSetSize;
 
314
  int MaxnodeSetSize;
 
315
  int MaxwinSetSize;
 
316
  int MaxlenSetSize;*/
 
317
  int nodeSetSizeLimit;
 
318
  int winSetSizeLimit;
 
319
  int lenSetSizeLimit;
 
320
  __int64 maxmem;               /* bytes */
 
321
  __int64 allocmem;
 
322
  __int64 summem;
 
323
  int wmem;
 
324
  int nmem; 
 
325
  int lmem;
 
326
  int maxIndex;
 
327
  int wcount;
 
328
  int ncount;
 
329
  int lcount;
 
330
  int clearTTflag;
 
331
  int windex;
 
332
  /*int ttCollect;
 
333
  int suppressTTlog;*/
 
334
  struct relRanksType * rel;
 
335
  struct adaptWinRanksType * adaptWins;
 
336
  __int64 suitLengths;
 
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;
 
345
  int lastTTstore;*/
 
346
  unsigned short int iniRemovedRanks[4];
 
347
 
 
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 */
 
351
};
 
352
 
 
353
#if defined(_WIN32)
 
354
extern CRITICAL_SECTION solv_crit;
 
355
#endif
 
356
 
 
357
extern int noOfThreads;
 
358
extern int noOfCores;
 
359
extern struct localVarType localVar[MAXNOOFTHREADS];
 
360
extern struct gameInfo game;
 
361
extern int newDeal;
 
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;
 
374
 
 
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];
 
380
extern int sum;
 
381
extern int score1Counts[50], score0Counts[50];
 
382
extern int c1[50], c2[50], c3[50], c4[50], c5[50], c6[50], c7[50],
 
383
  c8[50], c9[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;
 
388
extern int trump;
 
389
extern int nodes;                       /* Number of nodes searched */
 
390
extern int no[50];                      /* Number of nodes searched on each
 
391
                                        depth level */
 
392
extern int payOff;
 
393
extern int iniDepth;
 
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
 
397
                                        contract */
 
398
extern int tricksTargetOpp;             /* Target no of tricks for MAX
 
399
                                        opponent */
 
400
extern int targetNS;
 
401
extern int targetEW;
 
402
extern int handToPlay;
 
403
extern int searchTraceFlag;
 
404
extern int countMax;
 
405
extern int depthCount;
 
406
extern int highHand;
 
407
extern int nodeSetSizeLimit;
 
408
extern int winSetSizeLimit;
 
409
extern int lenSetSizeLimit;
 
410
extern int estTricks[4];
 
411
extern int recInd; 
 
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];
 
423
 
 
424
extern FILE *fp, /**fp2, *fp7, *fp11,*/ *fpx;
 
425
  /* Pointers to logs */
 
426
 
 
427
extern struct ttStoreType * ttStore;
 
428
extern int lastTTstore;
 
429
extern int ttCollect;
 
430
extern int suppressTTlog;
 
431
 
 
432
EXTERN_C DLLEXPORT int STDCALL SolveBoard(struct deal dl, 
 
433
  int target, int solutions, int mode, struct futureTricks *futp, int threadIndex);
 
434
 
 
435
#ifdef PBN
 
436
EXTERN_C DLLEXPORT int STDCALL SolveBoardPBN(struct dealPBN dlpbn, int target, 
 
437
    int solutions, int mode, struct futureTricks *futp, int thrId);
 
438
#endif
 
439
 
 
440
EXTERN_C DLLEXPORT int STDCALL CalcDDtable(struct ddTableDeal tableDeal, 
 
441
  struct ddTableResults * tablep);
 
442
 
 
443
#ifdef PBN
 
444
EXTERN_C DLLEXPORT int STDCALL CalcDDtablePBN(struct ddTableDealPBN tableDealPBN, 
 
445
  struct ddTableResults * tablep);
 
446
#endif
 
447
 
 
448
 
 
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
 
469
  * nodep);  
 
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);
 
491
 
 
492
void PrintDeal(FILE *fp, unsigned short ranks[4][4]);
 
493
 
 
494
int SolveAllBoards4(struct boards *bop, struct solvedBoards *solvedp, 
 
495
  int timeSupervision, int remainTime);
 
496
 
 
497
 
 
498
 
 
499