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// NOTE: DO NOT EDIT THIS FILE DIRECTLY. It is AUTO-GENERATED from config_schema.yaml.
13// To add new config values or make other changes, edit config_schema.yaml and regenerate via:
14//
15// uv run scripts/generate_config.py
16
17namespace porytiles {
18
26enum class ShuffleStrategy {
32 random
33};
34
48[[nodiscard]] inline std::optional<ShuffleStrategy> shuffle_strategy_from_str(const std::string &str)
49{
50 // Phase 1: Exact match against C++ constant names
51 if (str == "single_ffd") {
52 return std::optional{ShuffleStrategy::single_ffd};
53 }
54 if (str == "noisy_ffd") {
55 return std::optional{ShuffleStrategy::noisy_ffd};
56 }
57 if (str == "random") {
58 return std::optional{ShuffleStrategy::random};
59 }
60
61 // Phase 2: Case-insensitive fuzzy match
62 std::string lower_str = str;
63 std::ranges::transform(
64 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
65
66 // Fuzzy names for single_ffd
67 if (lower_str == "single-ffd") {
68 return std::optional{ShuffleStrategy::single_ffd};
69 }
70 if (lower_str == "single_ffd") {
71 return std::optional{ShuffleStrategy::single_ffd};
72 }
73 if (lower_str == "singleffd") {
74 return std::optional{ShuffleStrategy::single_ffd};
75 }
76 // Fuzzy names for noisy_ffd
77 if (lower_str == "noisy-ffd") {
78 return std::optional{ShuffleStrategy::noisy_ffd};
79 }
80 if (lower_str == "noisy_ffd") {
81 return std::optional{ShuffleStrategy::noisy_ffd};
82 }
83 if (lower_str == "noisyffd") {
84 return std::optional{ShuffleStrategy::noisy_ffd};
85 }
86 // Fuzzy names for random
87 if (lower_str == "random") {
88 return std::optional{ShuffleStrategy::random};
89 }
90
91 return std::nullopt;
92}
93
102[[nodiscard]] inline std::string to_string(const ShuffleStrategy m)
103{
104 switch (m) {
106 return "single_ffd";
108 return "noisy_ffd";
110 return "random";
111 }
112 panic("unhandled ShuffleStrategy value");
113}
114
120inline std::ostream &operator<<(std::ostream &os, const ShuffleStrategy m)
121{
122 return os << to_string(m);
123}
124
125} // namespace porytiles
126
127template <>
128struct std::formatter<porytiles::ShuffleStrategy> {
129 constexpr auto parse(std::format_parse_context &ctx)
130 {
131 return ctx.begin();
132 }
133
134 auto format(const porytiles::ShuffleStrategy &value, auto &ctx) const
135 {
136 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
137 }
138};
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)