|
16 | 16 | #include <crtdbg.h> |
17 | 17 | #endif |
18 | 18 |
|
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> |
0 commit comments