Porytiles
Loading...
Searching...
No Matches
shuffle_strategy.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cctype>
5#include <format>
6#include <optional>
7#include <ostream>
8#include <string>
9
11
12/*
13 * NOTE: DO NOT EDIT THIS FILE DIRECTLY. It is AUTO-GENERATED from config_schema.yaml.
14 * To add new config values or make other changes, edit config_schema.yaml and regenerate via:
15 *
16 * uv run scripts/generate_config.py
17 */
18
19namespace porytiles {
20
30enum class ShuffleStrategy {
42 random
43};
44
60[[nodiscard]] inline std::optional<ShuffleStrategy> shuffle_strategy_from_str(const std::string &str)
61{
62 // Phase 1: Exact match against C++ constant names
63 if (str == "single_ffd") {
64 return std::optional{ ShuffleStrategy::single_ffd };
65 }
66 if (str == "noisy_ffd") {
67 return std::optional{ ShuffleStrategy::noisy_ffd };
68 }
69 if (str == "random") {
70 return std::optional{ ShuffleStrategy::random };
71 }
72
73 // Phase 2: Case-insensitive fuzzy match
74 std::string lower_str = str;
75 std::ranges::transform(
76 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
77
78 // Fuzzy names for single_ffd
79 if (lower_str == "single-ffd") {
80 return std::optional{ ShuffleStrategy::single_ffd };
81 }
82 if (lower_str == "single_ffd") {
83 return std::optional{ ShuffleStrategy::single_ffd };
84 }
85 if (lower_str == "singleffd") {
86 return std::optional{ ShuffleStrategy::single_ffd };
87 }
88 // Fuzzy names for noisy_ffd
89 if (lower_str == "noisy-ffd") {
90 return std::optional{ ShuffleStrategy::noisy_ffd };
91 }
92 if (lower_str == "noisy_ffd") {
93 return std::optional{ ShuffleStrategy::noisy_ffd };
94 }
95 if (lower_str == "noisyffd") {
96 return std::optional{ ShuffleStrategy::noisy_ffd };
97 }
98 // Fuzzy names for random
99 if (lower_str == "random") {
100 return std::optional{ ShuffleStrategy::random };
101 }
102
103 return std::nullopt;
104}
105
116[[nodiscard]] inline std::string to_string(const ShuffleStrategy m)
117{
118 switch (m) {
120 return "single_ffd";
122 return "noisy_ffd";
124 return "random";
125 }
126 panic("unhandled ShuffleStrategy value");
127}
128
136inline std::ostream &operator<<(std::ostream &os, const ShuffleStrategy m)
137{
138 return os << to_string(m);
139}
140
141} // namespace porytiles
142
143template <>
144struct std::formatter<porytiles::ShuffleStrategy> {
145 constexpr auto parse(std::format_parse_context &ctx)
146 {
147 return ctx.begin();
148 }
149
150 auto format(const porytiles::ShuffleStrategy &value, auto &ctx) const
151 {
152 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
153 }
154};
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
ShuffleStrategy
Controls how tile orderings are generated during multi-start packing.
@ single_ffd
One FFD attempt only, no multi-start retries.
@ random
FFD first, then fully random shuffles (original behavior).
@ noisy_ffd
FFD first, then perturbed FFD orderings that preserve the large-first property.
std::optional< ShuffleStrategy > shuffle_strategy_from_str(const std::string &str)
Parses a string into a ShuffleStrategy with fuzzy matching.
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
auto format(const porytiles::ShuffleStrategy &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)