Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
AIDecisionUtility.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "AIUtility.hpp"
4#include "AITradeUtility.hpp"
5
6#include <array>
7#include <cstdint>
8#include <optional>
9#include <span>
10
12{
22
23 inline constexpr std::array<double, 8> MonopolyAverageLandingFrequency{
24 0.785, 0.883, 0.957, 1.103, 1.093, 1.003, 0.957, 0.890};
25
26 [[nodiscard]] std::int64_t excessCashAvailable(
29 bool cashOnly,
31 std::int64_t minCashOnHand,
32 std::int64_t moneyOwed = 0) noexcept;
33
35 const rules::GameState& state,
36 rules::PlayerNumber player,
38 std::int64_t minCashOnHand,
39 std::int64_t moneyOwed = 0) noexcept;
40
42 const rules::GameState& state,
43 rules::PlayerNumber player,
44 rules::board::SquareType property,
46 std::int64_t minCashOnHand,
47 std::span<const std::int64_t> moneyOwed = {}) noexcept;
48
52 std::int64_t moneyOwed = 0) noexcept;
53
55
56 [[nodiscard]] rules::board::SquareType hypotheticalUnmortgageMonopolyProperty(
57 rules::GameState& state,
58 rules::PlayerNumber player,
60 std::int64_t minCashOnHand,
61 std::int64_t moneyOwed = 0) noexcept;
62
63 [[nodiscard]] rules::board::SquareType hypotheticalUnmortgageProperty(
64 rules::GameState& state,
65 rules::PlayerNumber player,
66 bool onlyMonopolies,
68 std::int64_t minCashOnHand,
69 std::int64_t moneyOwed = 0) noexcept;
70
72 const rules::GameState& state,
73 rules::PlayerNumber player,
75 std::int64_t minCashOnHand,
76 std::int64_t moneyOwed = 0) noexcept;
77
79 {
80 No = 0,
81 Yes = 1,
82 Later = 2
83 };
84
85 inline constexpr std::uint8_t HouseBuyAtLeast3 = 1u << 0;
86 inline constexpr std::uint8_t HouseBuyWithin12 = 1u << 1;
87
92 std::int64_t minCashOnHand,
93 std::uint8_t housingPurchaseStrategy,
94 std::int64_t moneyOwed = 0) noexcept;
95
104
115
116 [[nodiscard]] EconomicActionPlan planBuyHouseAction(
117 const rules::GameState& state,
118 rules::PlayerNumber player,
120 std::int64_t minCashOnHand,
121 std::uint8_t housingPurchaseStrategy,
122 std::int64_t moneyOwed = 0) noexcept;
123
125 {
126 House = 0,
127 Hotel
128 };
129
130 [[nodiscard]] std::optional<rules::board::SquareType> chooseHousingAuctionSquare(
131 const rules::GameState& state,
132 rules::PlayerNumber player,
135 std::int64_t minCashOnHand,
137 bool reservedBuilding = false,
138 std::int64_t moneyOwed = 0) noexcept;
139
140 [[nodiscard]] EconomicActionPlan planHouseSaleAction(
141 const rules::GameState& state,
142 rules::board::SquareType referenceSquare) noexcept;
143
144 [[nodiscard]] EconomicActionPlan planDebtLiquidationStep(
145 const rules::GameState& state,
146 rules::PlayerNumber player,
147 bool sellHouses) noexcept;
148
149 [[nodiscard]] EconomicActionPlan planUnmortgagePropertyAction(
150 const rules::GameState& state,
151 rules::PlayerNumber player,
153 std::int64_t minCashOnHand,
154 std::int64_t moneyOwed = 0) noexcept;
155
156 [[nodiscard]] std::optional<bool> chooseFractionTax(
157 const rules::GameState& state,
158 rules::PlayerNumber player) noexcept;
159
161 {
162 Roll = 0,
163 Pay = 1,
164 Card = 2
165 };
166
167 [[nodiscard]] std::optional<JailExitChoice> chooseJailExitChoice(
168 const rules::GameState& state,
169 rules::PlayerNumber player,
170 bool canRollDoubles,
171 bool canPayFee,
172 bool canUseCard) noexcept;
173
175 {
176 std::array<double, 8> property{};
177 std::array<double, 6> cashCow{};
178 };
179
180 [[nodiscard]] std::int64_t totalWorthWithFactors(
181 const rules::GameState& state,
182 rules::PlayerNumber player,
183 const WorthFactors& factors) noexcept;
184
187 rules::PlayerNumber player,
188 bool sellHouses,
189 bool mortgageMonopoly) noexcept;
190
192
194 {
195 std::array<CashStrategy, rules::MaxPlayers> cashStrategy{};
196 std::array<std::int64_t, rules::MaxPlayers> minCashOnHand{};
197 std::array<std::int64_t, rules::MaxPlayers> moneyOwed{};
203 };
204
206 const rules::GameState& state,
207 rules::PlayerNumber player,
208 const WinningChanceConfig& config,
209 std::span<double> savePlayerChances = {}) noexcept;
210
224
231
232 [[nodiscard]] std::int64_t tradeBidForProperty(
234 rules::board::SquareType property, std::int64_t currentBid,
235 rules::PlayerNumber currentBidder, const AuctionBidConfig& config) noexcept;
236
237 [[nodiscard]] std::int64_t bidForAuctionItem(
239 rules::board::SquareType item, std::int64_t currentBid,
240 rules::PlayerNumber currentBidder, const AuctionBidConfig& config,
241 bool useTenDollarIncrement) noexcept;
242
243 [[nodiscard]] double evaluateTrade(
244 const rules::GameState& state,
245 rules::PlayerNumber player,
248 const TradeEvaluationConfig& config) noexcept;
249
251 const rules::GameState& state,
252 std::span<const rules::PlayerNumber> players,
256 const TradeEvaluationConfig& config,
257 std::span<double> evaluations) noexcept;
258
260 {
262 std::array<double, rules::MaxPlayers> playerAttitude{};
264 std::array<bool, rules::MaxPlayers> localAIPlayer{};
267 };
268
269 [[nodiscard]] bool makeTradeFair(
270 const rules::GameState& state,
271 rules::PlayerNumber player,
272 std::span<const rules::PlayerNumber> partners,
273 std::int64_t giveMost,
274 bool givingMonopoly,
276 const FairTradeConfig& config,
277 std::span<const ai::trade::FutureImmunityRecord> immunities = {}) noexcept;
278
284
286 const rules::GameState& state,
287 rules::PlayerNumber player,
289 std::span<const rules::PlayerNumber> partners,
290 const ai::trade::PropertySets& properties,
292 const MonopolyProposalConfig& config) noexcept;
293
295 const rules::GameState& state,
296 rules::PlayerNumber player,
298 const ai::trade::PropertySets& properties,
300 const MonopolyProposalConfig& config) noexcept;
301
303 {
304 std::array<rules::board::SquareGroup, 8> wantedGroups{};
305 std::array<rules::board::SquareGroup, 8> offeredGroups{};
307 double partnerRoll{};
308 std::uint32_t wantedPropertyRoll{};
309 std::uint32_t offeredPropertyRoll{};
310 std::uint8_t importance{};
314 };
315
317 const rules::GameState& state,
318 rules::PlayerNumber player,
319 std::span<const double> playerAttitudes,
320 const ai::trade::PropertySets& properties,
323 const MonopolyProposalConfig& config) noexcept;
324
325 enum class ProactiveTradeKind : std::uint8_t
326 {
327 None = 0,
332 };
333
335 {
336 std::uint8_t importance{};
339 std::array<rules::board::SquareGroup, 8> monopolyGroups{};
340 std::optional<SemiImportantTradeInputs> semiImportant{};
341 };
342
348
349 [[nodiscard]] ProactiveTradeResult buildProactiveTrade(
350 const rules::GameState& state,
351 rules::PlayerNumber player,
352 std::span<const double> playerAttitudes,
353 const ai::trade::PropertySets& properties,
354 const ProactiveTradeInputs& inputs,
355 const MonopolyProposalConfig& config) noexcept;
356
371
378
388
397
405
406 [[nodiscard]] CounterProposalPreflightResult counterProposalPreflight(
407 const rules::GameState& state,
408 rules::PlayerNumber player,
409 const ai::trade::TradeProposalList& currentTrade,
410 const CounterProposalPreflightInputs& inputs,
411 const CounterProposalPreflightConfig& config,
412 CounterProposalSession& session,
413 std::span<const ai::trade::FutureImmunityRecord> immunities = {}) noexcept;
414
415 enum class CounterProposalBalanceStatus : std::uint8_t
416 {
417 Ready = 0,
419 TooPoor,
423 };
424
441
442 [[nodiscard]] CounterProposalBalanceResult counterProposalBalance(
443 const rules::GameState& state,
444 rules::PlayerNumber player,
445 const CounterProposalPreflightResult& preflight,
447 const CounterProposalBalanceConfig& config,
448 std::span<const ai::trade::FutureImmunityRecord> immunities = {}) noexcept;
449
451 const rules::GameState& state,
452 rules::PlayerNumber player,
454 std::int64_t minCashOnHand,
455 int maxHousesPerSquareForGiveAway,
456 std::span<const std::int64_t> moneyOwed = {}) noexcept;
457}
std::array< rules::PlayerNumber, rules::MaxPlayers > players
std::uint16_t group
unsigned state
unsigned index
constexpr std::uint8_t HouseBuyWithin12
EconomicActionPlan planBuyHouseAction(const rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, std::uint8_t housingPurchaseStrategy, std::int64_t moneyOwed) noexcept
CounterProposalPreflightResult counterProposalPreflight(const rules::GameState &state, rules::PlayerNumber player, const ai::trade::TradeProposalList &currentTrade, const CounterProposalPreflightInputs &inputs, const CounterProposalPreflightConfig &config, CounterProposalSession &session, std::span< const ai::trade::FutureImmunityRecord > immunities) noexcept
EconomicActionPlan planDebtLiquidationStep(const rules::GameState &state, rules::PlayerNumber player, bool sellHouses) noexcept
bool hypotheticalBuyHouse(rules::GameState &state, rules::PlayerNumber player, std::int64_t moneyOwed) noexcept
bool shouldGiveAwayMonopoly(const rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, int maxHousesPerSquareForGiveAway, std::span< const std::int64_t > moneyOwed) noexcept
bool mortgageWorstProperty(rules::GameState &state, rules::PlayerNumber player, bool sellHouses, bool mortgageMonopoly) noexcept
bool buildSemiImportantTrade(const rules::GameState &state, rules::PlayerNumber player, std::span< const double > playerAttitudes, const ai::trade::PropertySets &properties, const SemiImportantTradeInputs &inputs, ai::trade::TradeProposalList &proposals, const MonopolyProposalConfig &config) noexcept
double evaluateTrade(const rules::GameState &state, rules::PlayerNumber player, rules::PlayerNumber strategyPlayer, const ai::trade::TradeProposalList &proposals, const TradeEvaluationConfig &config) noexcept
CounterProposalBalanceResult counterProposalBalance(const rules::GameState &state, rules::PlayerNumber player, const CounterProposalPreflightResult &preflight, ai::trade::TradeProposalList &proposals, const CounterProposalBalanceConfig &config, std::span< const ai::trade::FutureImmunityRecord > immunities) noexcept
HousePurchaseDecision shouldBuyHouse(const rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, std::uint8_t housingPurchaseStrategy, std::int64_t moneyOwed) noexcept
std::int64_t cashAvailableAfterHousing(const rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, std::int64_t moneyOwed) noexcept
bool buildMonopolyTrade(const rules::GameState &state, rules::PlayerNumber player, rules::board::SquareGroup group, std::span< const rules::PlayerNumber > partners, const ai::trade::PropertySets &properties, ai::trade::TradeProposalList &proposals, const MonopolyProposalConfig &config) noexcept
std::int64_t excessCashAvailable(const rules::GameState &state, rules::PlayerNumber player, bool cashOnly, CashStrategy strategy, std::int64_t minCashOnHand, std::int64_t moneyOwed) noexcept
std::int64_t tradeBidForProperty(const rules::GameState &state, rules::PlayerNumber player, rules::board::SquareType property, std::int64_t currentBid, rules::PlayerNumber currentBidder, const AuctionBidConfig &config) noexcept
bool shouldBuyProperty(const rules::GameState &state, rules::PlayerNumber player, rules::board::SquareType property, CashStrategy strategy, std::int64_t minCashOnHand, std::span< const std::int64_t > moneyOwed) noexcept
std::optional< rules::board::SquareType > chooseHousingAuctionSquare(const rules::GameState &state, rules::PlayerNumber player, HousingAuctionBuilding building, CashStrategy strategy, std::int64_t minCashOnHand, rules::board::PropertySet legalSquares, bool reservedBuilding, std::int64_t moneyOwed) noexcept
EconomicActionPlan planUnmortgagePropertyAction(const rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, std::int64_t moneyOwed) noexcept
std::int64_t bidForAuctionItem(const rules::GameState &state, rules::PlayerNumber player, rules::board::SquareType item, std::int64_t currentBid, rules::PlayerNumber currentBidder, const AuctionBidConfig &config, bool useTenDollarIncrement) noexcept
bool buildMonopolyForCash(const rules::GameState &state, rules::PlayerNumber player, rules::PlayerNumber firstPartner, const ai::trade::PropertySets &properties, ai::trade::TradeProposalList &proposals, const MonopolyProposalConfig &config) noexcept
std::optional< bool > chooseFractionTax(const rules::GameState &state, rules::PlayerNumber player) noexcept
double evaluateWinningChances(const rules::GameState &state, rules::PlayerNumber player, const WinningChanceConfig &config, std::span< double > savePlayerChances) noexcept
EconomicActionPlan planHouseSaleAction(const rules::GameState &state, rules::board::SquareType referenceSquare) noexcept
ProactiveTradeResult buildProactiveTrade(const rules::GameState &state, rules::PlayerNumber player, std::span< const double > playerAttitudes, const ai::trade::PropertySets &properties, const ProactiveTradeInputs &inputs, const MonopolyProposalConfig &config) noexcept
constexpr std::uint8_t CriticalHousingLevel
std::int64_t totalWorthWithFactors(const rules::GameState &state, rules::PlayerNumber player, const WorthFactors &factors) noexcept
bool shouldUnmortgageProperty(const rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, std::int64_t moneyOwed) noexcept
rules::board::SquareType hypotheticalUnmortgageProperty(rules::GameState &state, rules::PlayerNumber player, bool onlyMonopolies, CashStrategy strategy, std::int64_t minCashOnHand, std::int64_t moneyOwed) noexcept
void mortgageNegativeCashPlayers(rules::GameState &state) noexcept
constexpr std::uint8_t HouseBuyAtLeast3
std::optional< JailExitChoice > chooseJailExitChoice(const rules::GameState &state, rules::PlayerNumber player, bool canRollDoubles, bool canPayFee, bool canUseCard) noexcept
rules::board::SquareType hypotheticalUnmortgageMonopolyProperty(rules::GameState &state, rules::PlayerNumber player, CashStrategy strategy, std::int64_t minCashOnHand, std::int64_t moneyOwed) noexcept
void evaluateTradePlayerList(const rules::GameState &state, std::span< const rules::PlayerNumber > players, rules::PlayerNumber strategyPlayer, const ai::trade::TradeProposalList &proposals, bool givingMonopolyForCash, const TradeEvaluationConfig &config, std::span< double > evaluations) noexcept
bool makeTradeFair(const rules::GameState &state, rules::PlayerNumber player, std::span< const rules::PlayerNumber > partners, std::int64_t giveMost, bool givingMonopoly, ai::trade::TradeProposalList &proposals, const FairTradeConfig &config, std::span< const ai::trade::FutureImmunityRecord > immunities) noexcept
constexpr std::array< double, 8 > MonopolyAverageLandingFrequency
std::array< MonopolyTradeGenerosity, WhatToTradeEntries > WhatToTradeTable
std::array< double, WhatToTradeEntries > CashMultiplierTable
std::array< rules::board::PropertySet, rules::MaxPlayers > PropertySets
std::array< TradeProposalRecord, rules::MaxPlayers > TradeProposalList
std::uint32_t PropertySet
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
std::array< double, rules::MaxPlayers > playerAttitude
std::array< bool, rules::MaxPlayers > localAIPlayer
std::array< double, rules::MaxPlayers > playerAttitude
ai::trade::CashMultiplierTable cashMultipliers
std::optional< SemiImportantTradeInputs > semiImportant
std::array< rules::board::SquareGroup, 8 > monopolyGroups
std::array< rules::board::SquareGroup, 8 > offeredGroups
std::array< rules::board::SquareGroup, 8 > wantedGroups
ai::trade::PropertyImportanceConfig propertyImportance
std::array< std::int64_t, rules::MaxPlayers > minCashOnHand
std::array< CashStrategy, rules::MaxPlayers > cashStrategy
std::array< std::int64_t, rules::MaxPlayers > moneyOwed