Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
CardDeckRuntime.cpp
Go to the documentation of this file.
1#include "CardDeckRuntime.hpp"
2#include "Messaging.hpp"
3
4#include <cstddef>
5#include <cstdint>
6
8{
9 namespace
10 {
14 {
15 return state.cards[
16 static_cast<std::size_t>(deck)
17 ];
18 }
19 }
20
21
25 {
26 // DealCardFromTopOfDeck() original.
27
30
31
32 if (workingDeck.cardCount == 0)
33 {
34 return CardType::None;
35 }
36
37
38 const CardType card =
39 static_cast<CardType>(
40 workingDeck.cardPile[0]
41 );
42
43
44 --workingDeck.cardCount;
45
46
47 // Source :
48 //
49 // for (i = 1; i <= cardCount; i++)
50 // pile[i - 1] = pile[i];
51
52 for (std::uint8_t i = 1;
53 i <= workingDeck.cardCount;
54 ++i)
55 {
56 workingDeck.cardPile[
57 i - 1
58 ] =
59 workingDeck.cardPile[i];
60 }
61
62
63 return card;
64 }
65
66
70 {
71 // ReturnCard() original.
72
73 const std::uint8_t raw =
74 static_cast<std::uint8_t>(card);
75
76
77 DeckType deck{};
78
79
80 if (
81 raw >= ChanceFirst &&
83 {
85 }
86 else if (
89 {
91 }
92 else
93 {
94 return;
95 }
96
97
100
101
102 if (
103 workingDeck.cardCount >=
105 {
106 return;
107 }
108
109
110 workingDeck.cardPile[
111 workingDeck.cardCount++
112 ] = raw;
113 }
114
117 PlayerNumber fromPlayer,
118 PlayerNumber toPlayer,
120 {
121 // TransferGetOutOfJail() original.
122
123 if (fromPlayer >= MaxPlayers)
124 {
125 fromPlayer = NobodyPlayer;
126 }
127
128 if (toPlayer >= MaxPlayers)
129 {
130 toPlayer = NobodyPlayer;
131 }
132
133
134 const std::size_t deckIndex =
135 static_cast<std::size_t>(
137 );
138
139 if (deckIndex >=
140 static_cast<std::size_t>(
142 ))
143 {
144 return false;
145 }
146
147
148 CardDeck& deck =
150
151
152 if (deck.jailOwner != fromPlayer)
153 {
154 return false;
155 }
156
157
158 // Joueur -> paquet :
159 // la carte retourne physiquement au bas du paquet.
160 if (
161 deck.jailOwner < MaxPlayers &&
162 toPlayer == NobodyPlayer)
163 {
165 state,
169 );
170 }
171
172
173 deck.jailOwner =
174 toPlayer;
175
176 deck.jailOfferedInTradeTo =
178
179
184 deck.jailOwner,
185 static_cast<std::int64_t>(
187 )
188 );
189
190
191 return true;
192 }
193}
194
unsigned index
bool sendAction(const actions::Message &message)
void returnToBottom(GameState &state, CardType card)
CardType dealFromTop(GameState &state, DeckType deck)
bool transferGetOutOfJail(GameState &state, PlayerNumber fromPlayer, PlayerNumber toPlayer, DeckType deckType)
constexpr PlayerNumber BankPlayer
Definition RuleTypes.hpp:15
constexpr std::uint8_t CommunityCount
Definition CardTypes.hpp:52
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr std::size_t MaxCardsInDeck
Definition CardTypes.hpp:54
constexpr std::uint8_t CommunityFirst
Definition CardTypes.hpp:51
const GameState & state()
constexpr PlayerNumber MaxPlayers
Definition RuleTypes.hpp:14
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
constexpr std::uint8_t ChanceFirst
Definition CardTypes.hpp:48
constexpr std::uint8_t ChanceCount
Definition CardTypes.hpp:49
constexpr PlayerNumber AllPlayers
Definition RuleTypes.hpp:17
std::array< CardDeck, static_cast< std::size_t >(DeckType::Count) > cards