Cluedo Solver v1.0
Cluedo game solver making deductions.
Loading...
Searching...
No Matches
Card.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <string_view>
6
9
10namespace Cluedo {
11
13enum class CardCategory : std::uint8_t {
14 Suspect = 0,
15 Weapon = 6,
16 Room = 12
17};
18
23std::string_view format_as(CardCategory);
24
27#define _ENUMERATE_SUSPECTS \
28 _ENUMERATE_CARD(Green) \
29 _ENUMERATE_CARD(Mustard) \
30 _ENUMERATE_CARD(Orchid) \
31 _ENUMERATE_CARD(Peacock) \
32 _ENUMERATE_CARD(Plum) \
33 _ENUMERATE_CARD(Scarlet)
34
37#define _ENUMERATE_WEAPONS \
38 _ENUMERATE_CARD(Candlestick) \
39 _ENUMERATE_CARD(Knife) \
40 _ENUMERATE_CARD(Pipe) \
41 _ENUMERATE_CARD(Pistol) \
42 _ENUMERATE_CARD(Rope) \
43 _ENUMERATE_CARD(Wrench)
44
47#define _ENUMERATE_ROOMS \
48 _ENUMERATE_CARD(BilliardRoom) \
49 _ENUMERATE_CARD(Ballroom) \
50 _ENUMERATE_CARD(DiningRoom) \
51 _ENUMERATE_CARD(Greenhouse) \
52 _ENUMERATE_CARD(Hall) \
53 _ENUMERATE_CARD(Kitchen) \
54 _ENUMERATE_CARD(Library) \
55 _ENUMERATE_CARD(Lounge) \
56 _ENUMERATE_CARD(Study)
57
60#define _ENUMERATE_CARDS \
61 _ENUMERATE_SUSPECTS \
62 _ENUMERATE_WEAPONS \
63 _ENUMERATE_ROOMS
64
66enum class Card : std::uint8_t {
67#define _ENUMERATE_CARD(x) x,
69#undef _ENUMERATE_CARD
70 _Count
71};
72
77std::string_view format_as(Card);
78
80struct CardUtils {
82 static constexpr std::size_t CARD_COUNT = static_cast<std::size_t>(Card::_Count);
85
89 static constexpr CardCategory card_category(Card card) {
90 auto card_u8 = static_cast<std::uint8_t>(card);
91
92 if (card_u8 < static_cast<std::uint8_t>(CardCategory::Weapon))
94
95 if (card_u8 < static_cast<std::uint8_t>(CardCategory::Room))
97
98 return CardCategory::Room;
99 }
100
103 std::uint8_t index;
104
108 constexpr CardIterator(std::uint8_t i)
109 : index(i) {}
110
114 constexpr Card operator*() const { return static_cast<Card>(index); }
115
121 constexpr bool operator!=(CardIterator const& other) const { return index != other.index; }
122
124 constexpr void operator++() { ++index; }
125 };
126
128 struct cards {
132 constexpr CardIterator begin() const { return 0; }
136 constexpr CardIterator end() const { return static_cast<std::uint8_t>(Card::_Count); }
137 };
138
142
144 explicit constexpr cards_per_category(CardCategory c)
145 : category(c) {}
146
148 constexpr std::uint8_t count() const {
149 switch (category) {
151 return 6;
153 return 6;
155 return 9;
156 }
157
158 return 0;
159 }
160
164 constexpr CardIterator begin() const { return static_cast<std::uint8_t>(category); }
168 constexpr CardIterator end() const { return static_cast<std::uint8_t>(category) + count(); }
169 };
170};
171
172};
CardCategory
The categories of the cards in Cluedo.
Definition Card.hpp:13
@ Suspect
Suspect cards.
Definition Card.hpp:14
@ Weapon
Weapon cards.
Definition Card.hpp:15
@ Room
Room cards.
Definition Card.hpp:16
#define _ENUMERATE_CARDS
Enumerates all the cards.
Definition Card.hpp:60
Card
All the cards in Cluedo.
Definition Card.hpp:66
An iterator for cards.
Definition Card.hpp:102
constexpr CardIterator(std::uint8_t i)
Definition Card.hpp:108
constexpr bool operator!=(CardIterator const &other) const
Definition Card.hpp:121
constexpr void operator++()
Advances the iterator to the next card.
Definition Card.hpp:124
constexpr Card operator*() const
Definition Card.hpp:114
std::uint8_t index
The index of the card.
Definition Card.hpp:103
constexpr std::uint8_t count() const
Returns the number of cards in the category.
Definition Card.hpp:148
constexpr cards_per_category(CardCategory c)
Constructs the helper class.
Definition Card.hpp:144
constexpr CardIterator begin() const
Definition Card.hpp:164
CardCategory category
The category of the cards to iterate on.
Definition Card.hpp:141
constexpr CardIterator end() const
Definition Card.hpp:168
Helper class for iterator on all the cards.
Definition Card.hpp:128
constexpr CardIterator begin() const
Definition Card.hpp:132
constexpr CardIterator end() const
Definition Card.hpp:136
A series of utilities for the cards.
Definition Card.hpp:80
static constexpr std::size_t CARD_COUNT
The number of cards in Cluedo.
Definition Card.hpp:82
static constexpr std::array card_categories
The categories of the cards stored as an array.
Definition Card.hpp:84
static constexpr CardCategory card_category(Card card)
Definition Card.hpp:89