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
/*
DDS, a bridge double dummy solver.
Copyright (C) 2006-2014 by Bo Haglund /
2014-2018 by Bo Haglund & Soren Hein.
See LICENSE and README.
*/
/// @file constants.h
/// @brief Utility constants and lookup tables for card representation.
/// @defgroup utility_constants Utility Constants
/// @{
/// Global bridge game dimensions
constexpr int DDS_STRAINS = 5; ///< Number of strains (4 suits + no trump)
constexpr int DDS_HANDS = 4; ///< Number of hands (N/E/S/W)
constexpr int DDS_SUITS = 4; ///< Number of suits (S/H/D/C)
constexpr int DDS_NOTRUMP = 4; ///< No trump strain index
/// @name Hand Relationship Arrays
/// Precomputed lookup tables for hand relationships. Each array maps
/// an absolute hand (0-3) to the corresponding related hand.
/// @{
/// @brief Left-hand opponent for each hand (index -> hand value).
/// Precomputed lookup: lho[i] gives the hand number of the player sitting to hand i's left.
/// Values: lho[0]=1 (North's LHO is East), lho[1]=2 (East's LHO is South),
/// lho[2]=3 (South's LHO is West), lho[3]=0 (West's LHO is North)
extern const int lho;
/// @brief Right-hand opponent for each hand (index -> hand value).
/// Precomputed lookup: rho[i] gives the hand number of the player sitting to hand i's right.
/// Values: rho[0]=3 (North's RHO is West), rho[1]=0 (East's RHO is North),
/// rho[2]=1 (South's RHO is East), rho[3]=2 (West's RHO is South)
extern const int rho;
/// @brief Partner for each hand (index -> hand value).
/// Precomputed lookup: partner[i] gives the hand number of the player partnered with hand i.
/// Values: partner[0]=2 (North's partner is South), partner[1]=3 (East's partner is West),
/// partner[2]=0 (South's partner is North), partner[3]=1 (West's partner is East)
extern const int partner;
/// @}
/// @name Card Representation Lookup Tables
/// These tables provide efficient O(1) conversions between different
/// card representations (bitmask, rank, suit, hand).
/// @{
/// @brief Bitmask representation for card ranks.
/// Maps absolute rank (0-15) to bitmask (0x0000-0x2000).
/// Rank 2->0x0001, Rank 3->0x0002, ..., Rank Ace(14)->0x1000.
/// Indices 0, 1, 15 are sentinel values.
extern const unsigned short bit_map_rank;
/// @brief Character representation for card ranks.
/// Maps absolute rank (0-15) to printable character.
/// Valid ranks: 2-A map to '2'-'A', Ace is 'A', sentinel values are 'x', '-'.
extern const unsigned char card_rank;
/// @brief Character representation for suits.
/// Maps suit index (0-4) to character: S/H/D/C/N (no trump).
extern const unsigned char card_suit;
/// @brief Character representation for hands.
/// Maps hand (0-3) to character: N/E/S/W (North/East/South/West).
extern const unsigned char card_hand;
/// @}
/// @}