simplify deck parsing function

This commit is contained in:
Maximilian Keßler 2023-08-05 13:05:21 +02:00
parent 52f114b020
commit 426807f730
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -64,16 +64,12 @@ namespace Hanabi {
std::vector<Hanabi::Card> parse_deck(const boost::json::value& deck_json) { std::vector<Hanabi::Card> parse_deck(const boost::json::value& deck_json) {
auto deck = boost::json::value_to<std::vector<Hanabi::Card>>(deck_json); auto deck = boost::json::value_to<std::vector<Hanabi::Card>>(deck_json);
std::array<std::array<Hanabi::rank_t, 5>, 6> next_copy_indices {};
for(size_t i = 0; i < deck.size(); i++) { for(size_t i = 0; i < deck.size(); i++) {
auto &card = deck[i]; auto &card = deck[i];
assert(card.rank < 5); assert(card.rank < 5);
assert(card.rank >= 0); assert(card.rank >= 0);
assert(card.suit < 6); assert(card.suit < 6);
assert(card.suit >= 0); assert(card.suit >= 0);
card.index = i;
card.copy = next_copy_indices[card.suit][card.rank];
next_copy_indices[card.suit][card.rank]++;
} }
return deck; return deck;
} }