File: dll.h

package info (click to toggle)
dds 2.9.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 56,572 kB
  • sloc: cpp: 17,621; ansic: 385; makefile: 27; xml: 11; sh: 7
file content (537 lines) | stat: -rw-r--r-- 12,110 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/*
   DDS, a bridge double dummy solver.

   Copyright (C) 2006-2014 by Bo Haglund /
   2014-2018 by Bo Haglund & Soren Hein.

   See LICENSE and README.
*/


#ifndef DDS_DLL_H
#define DDS_DLL_H

#include <stdbool.h>

#if defined(_WIN32) || defined(__CYGWIN__)
  #define DLLEXPORT __declspec(dllexport)
  #define STDCALL __stdcall
#else
  #define DLLEXPORT
  #define STDCALL
  #define INT8 char
#endif

#ifdef __cplusplus
  #define EXTERN_C extern "C"
#else
  #define EXTERN_C
#endif

/* Version 2.9.0. Allowing for 2 digit minor versions */
#define DDS_VERSION 20900


#define DDS_HANDS 4
#define DDS_SUITS 4
#define DDS_STRAINS 5


#define MAXNOOFBOARDS 200

#define MAXNOOFTABLES 40


// Error codes. See interface document for more detail.
// Call ErrorMessage(code, line[]) to get the text form in line[].

// Success.
#define RETURN_NO_FAULT 1
#define TEXT_NO_FAULT "Success"

// Currently happens when fopen() fails or when AnalyseAllPlaysBin()
// get a different number of boards in its first two arguments.
#define RETURN_UNKNOWN_FAULT -1
#define TEXT_UNKNOWN_FAULT "General error"

// SolveBoard()
#define RETURN_ZERO_CARDS -2
#define TEXT_ZERO_CARDS "Zero cards"

// SolveBoard()
#define RETURN_TARGET_TOO_HIGH -3
#define TEXT_TARGET_TOO_HIGH "Target exceeds number of tricks"

// SolveBoard()
#define RETURN_DUPLICATE_CARDS -4
#define TEXT_DUPLICATE_CARDS "Cards duplicated"

// SolveBoard()
#define RETURN_TARGET_WRONG_LO -5
#define TEXT_TARGET_WRONG_LO "Target is less than -1"

// SolveBoard()
#define RETURN_TARGET_WRONG_HI -7
#define TEXT_TARGET_WRONG_HI "Target is higher than 13"

// SolveBoard()
#define RETURN_SOLNS_WRONG_LO -8
#define TEXT_SOLNS_WRONG_LO "Solutions parameter is less than 1"

// SolveBoard()
#define RETURN_SOLNS_WRONG_HI -9
#define TEXT_SOLNS_WRONG_HI "Solutions parameter is higher than 3"

// SolveBoard(), self-explanatory.
#define RETURN_TOO_MANY_CARDS -10
#define TEXT_TOO_MANY_CARDS "Too many cards"

// SolveBoard()
#define RETURN_SUIT_OR_RANK -12
#define TEXT_SUIT_OR_RANK \
  "currentTrickSuit or currentTrickRank has wrong data"

// SolveBoard
#define RETURN_PLAYED_CARD -13
#define TEXT_PLAYED_CARD "Played card also remains in a hand"

// SolveBoard()
#define RETURN_CARD_COUNT -14
#define TEXT_CARD_COUNT "Wrong number of remaining cards in a hand"

// SolveBoard()
#define RETURN_THREAD_INDEX -15
#define TEXT_THREAD_INDEX "Thread index is not 0 .. maximum"

// SolveBoard()
#define RETURN_MODE_WRONG_LO -16
#define TEXT_MODE_WRONG_LO "Mode parameter is less than 0"

// SolveBoard()
#define RETURN_MODE_WRONG_HI -17
#define TEXT_MODE_WRONG_HI "Mode parameter is higher than 2"

// SolveBoard()
#define RETURN_TRUMP_WRONG -18
#define TEXT_TRUMP_WRONG "Trump is not in 0 .. 4"

// SolveBoard()
#define RETURN_FIRST_WRONG -19
#define TEXT_FIRST_WRONG "First is not in 0 .. 2"

// AnalysePlay*() family of functions.
// (a) Less than 0 or more than 52 cards supplied.
// (b) Invalid suit or rank supplied.
// (c) A played card is not held by the right player.
#define RETURN_PLAY_FAULT -98
#define TEXT_PLAY_FAULT "AnalysePlay input error"

// Returned from a number of places if a PBN string is faulty.
#define RETURN_PBN_FAULT -99
#define TEXT_PBN_FAULT "PBN string error"

// SolveBoard() and AnalysePlay*()
#define RETURN_TOO_MANY_BOARDS -101
#define TEXT_TOO_MANY_BOARDS "Too many boards requested"

// Returned from multi-threading functions.
#define RETURN_THREAD_CREATE -102
#define TEXT_THREAD_CREATE "Could not create threads"

// Returned from multi-threading functions when something went
// wrong while waiting for all threads to complete.
#define RETURN_THREAD_WAIT -103
#define TEXT_THREAD_WAIT "Something failed waiting for thread to end"

// Tried to set a multi-threading system that is not present in DLL.
#define RETURN_THREAD_MISSING -104
#define TEXT_THREAD_MISSING "Multi-threading system not present"

// CalcAllTables*()
#define RETURN_NO_SUIT -201
#define TEXT_NO_SUIT "Denomination filter vector has no entries"

// CalcAllTables*()
#define RETURN_TOO_MANY_TABLES -202
#define TEXT_TOO_MANY_TABLES "Too many DD tables requested"

// SolveAllChunks*()
#define RETURN_CHUNK_SIZE -301
#define TEXT_CHUNK_SIZE "Chunk size is less than 1"



struct futureTricks
{
  int nodes;
  int cards;
  int suit[13];
  int rank[13];
  int equals[13];
  int score[13];
};

struct deal
{
  int trump;
  int first;
  int currentTrickSuit[3];
  int currentTrickRank[3];
  unsigned int remainCards[DDS_HANDS][DDS_SUITS];
};


struct dealPBN
{
  int trump;
  int first;
  int currentTrickSuit[3];
  int currentTrickRank[3];
  char remainCards[80];
};


struct boards
{
  int noOfBoards;
  struct deal deals[MAXNOOFBOARDS];
  int target[MAXNOOFBOARDS];
  int solutions[MAXNOOFBOARDS];
  int mode[MAXNOOFBOARDS];
};

struct boardsPBN
{
  int noOfBoards;
  struct dealPBN deals[MAXNOOFBOARDS];
  int target[MAXNOOFBOARDS];
  int solutions[MAXNOOFBOARDS];
  int mode[MAXNOOFBOARDS];
};

struct solvedBoards
{
  int noOfBoards;
  struct futureTricks solvedBoard[MAXNOOFBOARDS];
};

struct ddTableDeal
{
  unsigned int cards[DDS_HANDS][DDS_SUITS];
};

struct ddTableDeals
{
  int noOfTables;
  struct ddTableDeal deals[MAXNOOFTABLES * DDS_STRAINS];
};

struct ddTableDealPBN
{
  char cards[80];
};

struct ddTableDealsPBN
{
  int noOfTables;
  struct ddTableDealPBN deals[MAXNOOFTABLES * DDS_STRAINS];
};

struct ddTableResults
{
  int resTable[DDS_STRAINS][DDS_HANDS];
};

struct ddTablesRes
{
  int noOfBoards;
  struct ddTableResults results[MAXNOOFTABLES * DDS_STRAINS];
};

struct parResults
{
  /* index = 0 is NS view and index = 1
     is EW view. By 'view' is here meant
     which side that starts the bidding. */
  char parScore[2][16];
  char parContractsString[2][128];
};


struct allParResults
{
  struct parResults presults[MAXNOOFTABLES];
};

struct parResultsDealer
{
  /* number: Number of contracts yielding the par score.
     score: Par score for the specified dealer hand.
     contracts:  Par contract text strings.  The first contract
       is in contracts[0], the last one in contracts[number-1].
       The detailed text format is is given in the DLL interface
       document.
  */
  int number;
  int score;
  char contracts[10][10];
};

struct contractType
{
  int underTricks; /* 0 = make 1-13 = sacrifice */
  int overTricks; /* 0-3, e.g. 1 for 4S + 1. */
  int level; /* 1-7 */
  int denom; /* 0 = No Trumps, 1 = trump Spades, 2 = trump Hearts,
				  3 = trump Diamonds, 4 = trump Clubs */
  int seats; /* One of the cases N, E, W, S, NS, EW;
				   0 = N 1 = E, 2 = S, 3 = W, 4 = NS, 5 = EW */
};

struct parResultsMaster
{
  int score; /* Sign according to the NS view */
  int number; /* Number of contracts giving the par score */
  struct contractType contracts[10]; /* Par contracts */
};

struct parTextResults
{
  char parText[2][128]; /* Short text for par information, e.g.
				Par -110: EW 2S EW 2D+1 */
  bool equal; /* true in the normal case when it does not matter who
			starts the bidding. Otherwise, false. */
};


struct playTraceBin
{
  int number;
  int suit[52];
  int rank[52];
};

struct playTracePBN
{
  int number;
  char cards[106];
};

struct solvedPlay
{
  int number;
  int tricks[53];
};

struct playTracesBin
{
  int noOfBoards;
  struct playTraceBin plays[MAXNOOFBOARDS];
};

struct playTracesPBN
{
  int noOfBoards;
  struct playTracePBN plays[MAXNOOFBOARDS];
};

struct solvedPlays
{
  int noOfBoards;
  struct solvedPlay solved[MAXNOOFBOARDS];
};

struct DDSInfo
{
  // Version 2.8.0 has 2, 8, 0 and a string of 2.8.0
  int major, minor, patch; 
  char versionString[10];

  // Currently 0 = unknown, 1 = Windows, 2 = Cygwin, 3 = Linux, 4 = Apple
  int system;

  // We know 32 and 64-bit systems.
  int numBits;

  // Currently 0 = unknown, 1 = Microsoft Visual C++, 2 = mingw,
  // 3 = GNU g++, 4 = clang
  int compiler;

  // Currently 0 = none, 1 = DllMain, 2 = Unix-style
  int constructor;

  int numCores;

  // Currently 
  // 0 = none, 
  // 1 = Windows (native), 
  // 2 = OpenMP, 
  // 3 = GCD,
  // 4 = Boost,
  // 5 = STL,
  // 6 = TBB,
  // 7 = STLIMPL (for_each), experimental only
  // 8 = PPLIMPL (for_each), experimental only
  int threading;

  // The actual number of threads configured
  int noOfThreads;

  // This will break if there are > 128 threads...
  // The string is of the form LLLSSS meaning 3 large TT memories
  // and 3 small ones.
  char threadSizes[128];

  char systemString[1024];
};



EXTERN_C DLLEXPORT void STDCALL SetMaxThreads(
  int userThreads);

EXTERN_C DLLEXPORT int STDCALL SetThreading(
  int code);

EXTERN_C DLLEXPORT void STDCALL SetResources(
  int maxMemoryMB,
  int maxThreads);

EXTERN_C DLLEXPORT void STDCALL FreeMemory();

EXTERN_C DLLEXPORT int STDCALL SolveBoard(
  struct deal dl,
  int target,
  int solutions,
  int mode,
  struct futureTricks * futp,
  int threadIndex);

EXTERN_C DLLEXPORT int STDCALL SolveBoardPBN(
  struct dealPBN dlpbn,
  int target,
  int solutions,
  int mode,
  struct futureTricks * futp,
  int thrId);

EXTERN_C DLLEXPORT int STDCALL CalcDDtable(
  struct ddTableDeal tableDeal,
  struct ddTableResults * tablep);

EXTERN_C DLLEXPORT int STDCALL CalcDDtablePBN(
  struct ddTableDealPBN tableDealPBN,
  struct ddTableResults * tablep);

EXTERN_C DLLEXPORT int STDCALL CalcAllTables(
  struct ddTableDeals * dealsp,
  int mode,
  int trumpFilter[DDS_STRAINS],
  struct ddTablesRes * resp,
  struct allParResults * presp);

EXTERN_C DLLEXPORT int STDCALL CalcAllTablesPBN(
  struct ddTableDealsPBN * dealsp,
  int mode,
  int trumpFilter[DDS_STRAINS],
  struct ddTablesRes * resp,
  struct allParResults * presp);

EXTERN_C DLLEXPORT int STDCALL SolveAllBoards(
  struct boardsPBN * bop,
  struct solvedBoards * solvedp);

EXTERN_C DLLEXPORT int STDCALL SolveAllChunks(
  struct boardsPBN * bop,
  struct solvedBoards * solvedp,
  int chunkSize);

EXTERN_C DLLEXPORT int STDCALL SolveAllChunksBin(
  struct boards * bop,
  struct solvedBoards * solvedp,
  int chunkSize);

EXTERN_C DLLEXPORT int STDCALL SolveAllChunksPBN(
  struct boardsPBN * bop,
  struct solvedBoards * solvedp,
  int chunkSize);

EXTERN_C DLLEXPORT int STDCALL Par(
  struct ddTableResults * tablep,
  struct parResults * presp,
  int vulnerable);

EXTERN_C DLLEXPORT int STDCALL CalcPar(
  struct ddTableDeal tableDeal,
  int vulnerable,
  struct ddTableResults * tablep,
  struct parResults * presp);

EXTERN_C DLLEXPORT int STDCALL CalcParPBN(
  struct ddTableDealPBN tableDealPBN,
  struct ddTableResults * tablep,
  int vulnerable,
  struct parResults * presp);

EXTERN_C DLLEXPORT int STDCALL SidesPar(
  struct ddTableResults * tablep,
  struct parResultsDealer sidesRes[2],
  int vulnerable);

EXTERN_C DLLEXPORT int STDCALL DealerPar(
  struct ddTableResults * tablep,
  struct parResultsDealer * presp,
  int dealer,
  int vulnerable);

EXTERN_C DLLEXPORT int STDCALL DealerParBin(
  struct ddTableResults * tablep,
  struct parResultsMaster * presp,
  int dealer, 
  int vulnerable);

EXTERN_C DLLEXPORT int STDCALL SidesParBin(
  struct ddTableResults * tablep,
  struct parResultsMaster sidesRes[2],
  int vulnerable);

EXTERN_C DLLEXPORT int STDCALL ConvertToDealerTextFormat(
  struct parResultsMaster * pres,
  char * resp);

EXTERN_C DLLEXPORT int STDCALL ConvertToSidesTextFormat(
  struct parResultsMaster * pres,
  struct parTextResults * resp);

EXTERN_C DLLEXPORT int STDCALL AnalysePlayBin(
  struct deal dl,
  struct playTraceBin play,
  struct solvedPlay * solved,
  int thrId);

EXTERN_C DLLEXPORT int STDCALL AnalysePlayPBN(
  struct dealPBN dlPBN,
  struct playTracePBN playPBN,
  struct solvedPlay * solvedp,
  int thrId);

EXTERN_C DLLEXPORT int STDCALL AnalyseAllPlaysBin(
  struct boards * bop,
  struct playTracesBin * plp,
  struct solvedPlays * solvedp,
  int chunkSize);

EXTERN_C DLLEXPORT int STDCALL AnalyseAllPlaysPBN(
  struct boardsPBN * bopPBN,
  struct playTracesPBN * plpPBN,
  struct solvedPlays * solvedp,
  int chunkSize);

EXTERN_C DLLEXPORT void STDCALL GetDDSInfo(
  struct DDSInfo * info);

EXTERN_C DLLEXPORT void STDCALL ErrorMessage(
  int code,
  char line[80]);

#endif