MCPcopy Create free account
hub / github.com/dds-bridge/dds / dict_to_deal

Function dict_to_deal

python/src/converters.cpp:53–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53auto dict_to_deal(const py::dict& deal_input) -> Deal
54{
55 Deal deal{};
56
57 const int trump = py::cast<int>(deal_input["trump"]);
58 if (trump < 0 || trump > DDS_STRAINS - 1) {
59 throw py::value_error(
60 "trump has invalid value " + std::to_string(trump) +
61 " (expected range 0.." + std::to_string(DDS_STRAINS - 1) + ")");
62 }
63
64 const int first = py::cast<int>(deal_input["first"]);
65 if (first < 0 || first > DDS_HANDS - 1) {
66 throw py::value_error(
67 "first has invalid value " + std::to_string(first) +
68 " (expected range 0.." + std::to_string(DDS_HANDS - 1) + ")");
69 }
70
71 deal.trump = trump;
72 deal.first = first;
73 const auto trick_suit = sequence_to_bounded_int_vector(
74 py::cast<py::sequence>(deal_input["current_trick_suit"]),
75 3,
76 0,
77 DDS_SUITS - 1,
78 "current_trick_suit");
79 const auto trick_rank = sequence_to_bounded_int_vector(
80 py::cast<py::sequence>(deal_input["current_trick_rank"]),
81 3,
82 0,
83 14,
84 "current_trick_rank");
85 for (const int value : trick_rank) {
86 if (value != 0 && (value < 2 || value > 14)) {
87 throw py::value_error(
88 "current_trick_rank has invalid value " + std::to_string(value) +
89 " (expected 0 or 2..14)");
90 }
91 }
92
93 for (int i = 0; i < 3; ++i) {
94 deal.currentTrickSuit[i] = trick_suit[static_cast<std::size_t>(i)];
95 deal.currentTrickRank[i] = trick_rank[static_cast<std::size_t>(i)];
96 }
97
98 const auto remain_cards_rows = py::cast<py::sequence>(deal_input["remain_cards"]);
99 if (remain_cards_rows.size() != DDS_HANDS) {
100 throw py::value_error(
101 "remain_cards must have " + std::to_string(DDS_HANDS) + " rows");
102 }
103
104 for (int hand = 0; hand < DDS_HANDS; ++hand) {
105 const auto row = py::cast<py::sequence>(remain_cards_rows[hand]);
106 if (row.size() != DDS_SUITS) {
107 throw py::value_error(
108 "each remain_cards row must have " + std::to_string(DDS_SUITS) + " values");
109 }
110 for (int suit = 0; suit < DDS_SUITS; ++suit) {

Callers 1

register_solve_bindingsFunction · 0.85

Calls 1

Tested by

no test coverage detected