Skip to content

Commit 437e06d

Browse files
authored
Merge pull request #355 from dds-bridge/chore/reorganise_headers
Split public API headers into constants + data types
2 parents 2103f1f + 7af1edb commit 437e06d

49 files changed

Lines changed: 861 additions & 688 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

library/src/ab_search.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#pragma once
1111

12-
#include <api/dds.h>
12+
#include <api/dds_data_types.hpp>
1313
#include <solver_context/solver_context.hpp>
1414

1515
auto ab_search(

library/src/api/BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ exports_files(
1111
visibility = ["//visibility:public"],
1212
)
1313

14+
# Compile-time constants and macros shared with the whole solver. Kept as its
15+
# own dependency-free target so //library/src/utility:constants can fold its
16+
# bridge dimensions in here without a dependency cycle.
17+
cc_library(
18+
name = "dds_constants",
19+
hdrs = ["dds_constants.hpp"],
20+
include_prefix = "api",
21+
visibility = ["//visibility:public"],
22+
deps = [],
23+
)
24+
1425
cc_library(
1526
name = "api_definitions",
1627
hdrs = [
1728
"calc_dd_table.hpp",
1829
"calc_par.hpp",
1930
"dds.h",
31+
"dds_c_data_types.h",
32+
"dds_data_types.hpp",
2033
"dll.h",
2134
"dds_api.hpp",
2235
"dds_c_api.h",
@@ -27,6 +40,7 @@ cc_library(
2740
include_prefix = "api",
2841
visibility = ["//visibility:public"],
2942
deps = [
43+
":dds_constants",
3044
"//library/src/utility:constants",
3145
],
3246
)

library/src/api/PBN.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#pragma once
1111

12-
#include <api/dll.h>
12+
#include <api/dds_data_types.hpp>
1313

1414

1515
/**

library/src/api/calc_dd_table.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#pragma once
1414

15-
#include <api/dds.h>
15+
#include <api/dds_data_types.hpp>
1616
#include <solver_context/solver_context.hpp>
1717

1818
// Naming note: New C++ APIs in DDS 3 use snake_case (calc_dd_table).

library/src/api/calc_par.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#pragma once
1313

14-
#include <api/dds.h>
14+
#include <api/dds_data_types.hpp>
1515
#include <solver_context/solver_context.hpp>
1616

1717
// Naming note: New C++ APIs in DDS 3 use snake_case (calc_par, calc_par_from_table).

library/src/api/dds.h

Lines changed: 6 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -16,199 +16,9 @@
1616
#include <crtdbg.h>
1717
#endif
1818

19-
// Project headers
20-
#include <api/dll.h>
21-
22-
23-
constexpr int THREADMEM_SMALL_MAX_MB = 30;
24-
constexpr int THREADMEM_SMALL_DEF_MB = 20;
25-
constexpr int THREADMEM_LARGE_MAX_MB = 160;
26-
constexpr int THREADMEM_LARGE_DEF_MB = 95;
27-
28-
constexpr int MAXNODE = 1;
29-
constexpr int MINNODE = 0;
30-
31-
constexpr int SIMILARDEALLIMIT = 5;
32-
constexpr int SIMILARMAXWINNODES = 700000;
33-
34-
35-
/* "hand" is leading hand, "relative" is hand relative leading
36-
hand.
37-
The handId macro implementation follows a solution
38-
by Thomas Andrews.
39-
All hand identities are given as
40-
0=NORTH, 1=EAST, 2=SOUTH, 3=WEST. */
41-
42-
#include <utility/constants.h>
43-
44-
/**
45-
* @brief Calculate relative hand position.
46-
* @param hand Base hand position (0=NORTH, 1=EAST, 2=SOUTH, 3=WEST)
47-
* @param relative Relative offset (0-3)
48-
* @return Resulting hand position (0-3)
49-
*/
50-
#define HAND_ID(hand, relative) ((hand + relative) & 3)
51-
52-
/**
53-
* @brief Represents a single card move in the game.
54-
*
55-
* Contains information about a card that can be played, including
56-
* its suit, rank, sequence status, and sorting weight.
57-
*/
58-
struct MoveType
59-
{
60-
int suit; ///< Suit of the card (0-3: spades, hearts, diamonds, clubs)
61-
int rank; ///< Rank of the card (2-14: 2 through Ace)
62-
int sequence; ///< Whether this move is the first in a sequence
63-
int weight; ///< Weight used for sorting during move generation
64-
};
65-
66-
/**
67-
* @brief Collection of moves available at a single ply.
68-
*
69-
* Stores all possible moves at a given point in the game,
70-
* along with tracking of current and last move indices.
71-
*/
72-
struct MovePlyType
73-
{
74-
MoveType move[14]; ///< Array of possible moves (max 13 cards + sentinel)
75-
int current; ///< Index of current move being considered
76-
int last; ///< Index of last valid move in array
77-
};
78-
79-
/**
80-
* @brief Identifies a high card by rank and holding hand.
81-
*
82-
* Used to track high cards in each suit during analysis.
83-
*/
84-
struct HighCardType
85-
{
86-
int rank; ///< Rank of the high card (2-14)
87-
int hand; ///< Hand holding the card (0-3: N, E, S, W)
88-
};
89-
90-
/**
91-
* @brief Complete position state during game analysis.
92-
*
93-
* Represents the full state of a bridge position including card distribution,
94-
* trump information, and current play state. This is the core data structure
95-
* used throughout the solver.
96-
*/
97-
struct Pos
98-
{
99-
unsigned short int rank_in_suit[DDS_HANDS][DDS_SUITS]; ///< Bitmask of ranks held by each hand in each suit
100-
unsigned short int aggr[DDS_SUITS]; ///< Aggregate bitmask of all cards in each suit
101-
unsigned char length[DDS_HANDS][DDS_SUITS]; ///< Number of cards each hand holds in each suit
102-
int hand_dist[DDS_HANDS]; ///< Total number of cards held by each hand
103-
104-
unsigned short int win_ranks[50][DDS_SUITS]; ///< Cards that win by rank at each depth
105-
int first[50]; ///< Hand that leads the trick for each ply
106-
MoveType move[50]; ///< Presently winning move at each ply
107-
int hand_rel_first; ///< Current hand, relative to first hand
108-
int tricks_max; ///< Aggregated tricks won by maximizing side
109-
HighCardType winner[DDS_SUITS]; ///< Winning rank of trick in each suit
110-
HighCardType second_best[DDS_SUITS]; ///< Second best rank in each suit
111-
};
112-
113-
/**
114-
* @brief Trick-level data for current play state.
115-
*
116-
* Tracks information about the current trick being played,
117-
* including play counts, best cards, and lead information.
118-
*/
119-
struct TrickDataType
120-
{
121-
int play_count[DDS_SUITS]; ///< Number of cards played in each suit
122-
int best_rank; ///< Rank of best card played so far
123-
int best_suit; ///< Suit of best card played so far
124-
int best_sequence; ///< Sequence of best card
125-
int rel_winner; ///< Relative position of current trick winner
126-
int next_lead_hand; ///< Hand that will lead next trick
127-
};
128-
129-
/**
130-
* @brief Evaluation result for a position.
131-
*
132-
* Contains the number of tricks that can be won and which specific
133-
* card ranks can win in each suit.
134-
*/
135-
struct EvalType
136-
{
137-
int tricks; ///< Number of tricks that can be won from this position
138-
unsigned short int win_ranks[DDS_SUITS]; ///< Bitmask of winning ranks in each suit
139-
};
140-
141-
/**
142-
* @brief Simple card representation.
143-
*
144-
* Basic structure identifying a card by suit and rank.
145-
*/
146-
struct Card
147-
{
148-
int suit; ///< Suit of the card (0-3: spades, hearts, diamonds, clubs)
149-
int rank; ///< Rank of the card (2-14: 2 through Ace)
150-
};
151-
152-
/**
153-
* @brief Extended card representation with sequence information.
154-
*
155-
* Like Card but includes sequence information for tracking
156-
* equivalent cards during move generation.
157-
*/
158-
struct ExtCard
159-
{
160-
int suit; ///< Suit of the card (0-3: spades, hearts, diamonds, clubs)
161-
int rank; ///< Rank of the card (2-14: 2 through Ace)
162-
int sequence; ///< Sequence identifier for equivalent cards
163-
};
164-
165-
/**
166-
* @brief Absolute rank with holding hand.
167-
*
168-
* Compact representation (2 bytes) identifying a card rank
169-
* and which hand holds it.
170-
*/
171-
struct AbsRankType // 2 bytes
172-
{
173-
char rank; ///< Rank of the card (2-14)
174-
signed char hand; ///< Hand holding the card (0-3: N, E, S, W)
175-
};
176-
177-
/**
178-
* @brief Relative rank table for all suits.
179-
*
180-
* Contains absolute rank information for all possible card positions
181-
* across all suits. Used for quick lookup during position analysis.
182-
*/
183-
struct RelRanksType // 120 bytes
184-
{
185-
AbsRankType abs_rank[15][DDS_SUITS]; ///< Rank information indexed by position and suit
186-
};
187-
188-
/**
189-
* @brief Parameters for batch board solving.
190-
*
191-
* Contains input/output structures for solving multiple boards
192-
* in a single operation.
193-
*/
194-
struct ParamType
195-
{
196-
int no_of_boards; ///< Number of boards to solve
197-
Boards const * bop; ///< Pointer to input boards
198-
SolvedBoards * solvedp; ///< Pointer to output solutions
199-
int error; ///< Error code from operation
200-
};
201-
202-
/**
203-
* @brief Execution mode for solver operations.
204-
*
205-
* Determines how the solver processes a position - solving for best play,
206-
* calculating all possible outcomes, or tracing a specific line of play.
207-
*/
208-
enum class RunMode
209-
{
210-
DDS_RUN_SOLVE = 0, ///< Solve mode: find optimal play
211-
DDS_RUN_CALC = 1, ///< Calculate mode: compute all outcomes
212-
DDS_RUN_TRACE = 2, ///< Trace mode: analyze specific play sequence
213-
DDS_RUN_SIZE = 3 ///< Size sentinel (not a valid mode)
214-
};
19+
// Aggregator for the solver's compile-time constants and data model. The
20+
// public function-declaration surface (SolveBoard, CalcDDtable, ...) lives in
21+
// <api/dll.h> and is included only by API consumers and the API implementation
22+
// files, never by internal solver code.
23+
#include <api/dds_constants.hpp>
24+
#include <api/dds_data_types.hpp> // also pulls in <utility/constants.h>

library/src/api/dds_c_api.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
and ctypes a single clean, stable ABI to bind against.
1010
1111
NOTE: the *exported symbols* are a pure C ABI, but this header is not itself
12-
compilable by a C front-end: it includes <api/dll.h>, whose flat API is
13-
declared with C++ trailing-return syntax (auto ... -> int). Consume the ABI
14-
by binding to the compiled library's symbols (FFM/ctypes/.NET) or by parsing
15-
the headers with a C++ mode (jextract); do not #include this from a C
12+
compilable by a C front-end: it pulls in <api/dds_c_data_types.h>, which in
13+
turn includes <api/dds_constants.hpp>, where the shared constants are C++
14+
`constexpr` (and other declarations use C++-only syntax). Consume the ABI by
15+
binding to the compiled library's symbols (FFM/ctypes/.NET) or by parsing
16+
the headers with a C++ mode (jextract); do not include this from a C
1617
translation unit.
1718
1819
See LICENSE and README.
1920
*/
2021

2122
#pragma once
2223

23-
#include <api/dll.h> /* struct Deal, FutureTricks, DdTableDeal, DdTableResults, ParResults */
24+
#include <api/dds_c_data_types.h> /* struct Deal, FutureTricks, DdTableDeal, DdTableDealPBN, DdTableResults, ParResults; DLLEXPORT */
2425

2526
#ifdef __cplusplus
2627
extern "C" {

library/src/api/dds_c_data_types.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
DDS, a bridge double dummy solver.
3+
4+
Copyright (C) 2006-2014 by Bo Haglund /
5+
2014-2018 by Bo Haglund & Soren Hein.
6+
7+
See LICENSE and README.
8+
*/
9+
10+
#pragma once
11+
12+
/// @file dds_c_data_types.h
13+
/// @brief The plain-old-data structures that cross the pure-C ABI shim.
14+
///
15+
/// This is the subset of the legacy data types that appear in
16+
/// `dds_c_api.h` signatures (`struct Deal`, `struct FutureTricks`,
17+
/// `struct DdTableDeal`, `struct DdTableDealPBN`, `struct DdTableResults`,
18+
/// `struct ParResults`). It is split out from `dds_data_types.hpp` so the
19+
/// C-ABI shim can pull in exactly what it passes by pointer and nothing
20+
/// else. Every remaining legacy and internal type lives in
21+
/// `dds_data_types.hpp`, which includes this header.
22+
23+
#include <api/dds_constants.hpp>
24+
25+
/**
26+
* @brief Stores the result of a double dummy analysis for a single position.
27+
*
28+
* Contains the number of nodes searched, the number of cards in the result,
29+
* and arrays for each card's suit, rank, equality group, and score.
30+
*/
31+
struct FutureTricks
32+
{
33+
int nodes;
34+
int cards;
35+
int suit[13];
36+
int rank[13];
37+
int equals[13];
38+
int score[13];
39+
};
40+
41+
/**
42+
* @brief Represents a bridge Deal for double dummy analysis.
43+
*
44+
* @param trump The trump suit (0 = NT, 1 = Spades, ...)
45+
* @param first The hand to play first (0 = N, 1 = E, ...)
46+
* @param currentTrickSuit Suits of cards played in the current trick
47+
* @param currentTrickRank Ranks of cards played in the current trick
48+
* @param remainCards Remaining cards in each hand and suit
49+
*/
50+
struct Deal
51+
{
52+
int trump;
53+
int first;
54+
int currentTrickSuit[3];
55+
int currentTrickRank[3];
56+
unsigned int remainCards[DDS_HANDS][DDS_SUITS];
57+
};
58+
59+
struct DdTableDeal
60+
{
61+
unsigned int cards[DDS_HANDS][DDS_SUITS];
62+
};
63+
64+
struct DdTableDealPBN
65+
{
66+
char cards[80];
67+
};
68+
69+
struct DdTableResults
70+
{
71+
int res_table[DDS_STRAINS][DDS_HANDS];
72+
};
73+
74+
struct ParResults
75+
{
76+
/* index = 0 is NS view and index = 1
77+
is EW view. By 'view' is here meant
78+
which side that starts the bidding. */
79+
char par_score[2][16];
80+
char par_contracts_string[2][128];
81+
};

0 commit comments

Comments
 (0)