Compare commits

...

3 Commits

Author SHA1 Message Date
81620d8709 add more puzzles 2026-02-25 16:53:24 +01:00
5e3d007a9d display puzzle title 2026-02-25 16:53:13 +01:00
5a2172cb00 fix crash when resetting an edited board 2026-02-25 16:06:13 +01:00
7 changed files with 67 additions and 29 deletions

View File

@ -4,7 +4,7 @@ project(MassSprings)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wno-unused-parameter -Wunreachable-code")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wno-unused-parameter -Wunreachable-code")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2 -ggdb") # -fsanitize=address already fails on InitWindow(), -fsanitize=undefined, -fsanitize=leak
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -march=native")

View File

@ -1,38 +1,53 @@
// 1 Block, 1 Axis, no goal
# 1 Block, 1 Axis, no goal
R459912......................................
// 2 Blocks, 2 Axes, no goal
# 2 Blocks, 2 Axes, no goal
R45991212....................................
// 3 Blocks, 3 Axes, still no goal
# 3 Blocks, 3 Axes, still no goal
R4599121212..................................
// Square with no goal
# Square with no goal
F449921....111222..11......111111....
// RushHour 1
# RushHour 1
R6642..13..21..13..................ba..........12............21..............
// RushHour 2
# RushHour 2
R664231........13................12ba..........1221..12..12..21........31....
// RushHour 3
# RushHour 3
R66421231....1213..31........ba..121212..21................1221..........21..
// RushHour 4
# RushHour 4
R664231....12....1221......12..ba..1212..21..12....12......21......21..21....
// Thin Klotski
# RushHour 5
R66421321....12....1212....13......ba....31....12........12..21..21....21....
# Dad's Puzzler
F4503bb..21......21..1111....121221......21..
# Nine Block (Worse)
F45031212........21..121221......bb..1111....
# Quzzle
F4520bb..21......1212........1221..11..21..11
# Thin Klotski
F451412..ba....22..11......1122..1111....1111
// Klotski
# Klotski
F451312bb..12........1221..12..1111..11....11
// Fat Klotski
# Fat Klotski
F4513..bb..1111....121122....11......111121..
// Century
# Century
F451311bb..1112....12..12....11....1121..21..
// Super Century
# Super Century
F451312111111..12bb..12........21..11....21..
# Supercompo
F4513..bb....11....111221..12..21....1121..11

View File

@ -12,12 +12,12 @@
// Window
constexpr int INITIAL_WIDTH = 800;
constexpr int INITIAL_HEIGHT = 800;
constexpr int MENU_HEIGHT = 200;
constexpr int MENU_HEIGHT = 250;
// Menu
constexpr int MENU_PAD = 5;
constexpr int BUTTON_PAD = 12;
constexpr int MENU_ROWS = 4;
constexpr int MENU_ROWS = 5;
constexpr int MENU_COLS = 3;
// Camera Controls

View File

@ -16,6 +16,7 @@ public:
ThreadedPhysics &physics;
std::vector<State> presets;
std::vector<std::string> comments;
// Some stuff is faster to map from state to mass (e.g. in the renderer)
std::unordered_map<State, std::size_t> states;

View File

@ -13,7 +13,8 @@
#include <tracy/Tracy.hpp>
#endif
// TODO: Click states to display them in the board
// TODO: Click states in the graph to display them in the board
// TODO: Add walls (unmoveable blocks)
// NOTE: Tracy uses a huge amount of memory. For longer testing disable Tracy.

View File

@ -322,13 +322,26 @@ auto Renderer::DrawMenu(const std::vector<Vector3> &masses) -> void {
auto draw_btn = [&](int x, int y, std::string text, Color color) {
int posx = MENU_PAD + x * (MENU_PAD + btn_width);
int posy = MENU_PAD + y * (MENU_PAD + btn_height);
int posy = MENU_PAD + (y + 1) * (MENU_PAD + btn_height);
DrawRectangle(posx, posy, btn_width, btn_height, Fade(color, 0.7));
DrawRectangleLines(posx, posy, btn_width, btn_height, color);
DrawText(text.data(), posx + BUTTON_PAD, posy + BUTTON_PAD,
btn_height - 2.0 * BUTTON_PAD, WHITE);
};
auto draw_subtitle = [&](std::string text, Color color) {
int posx = MENU_PAD;
int posy = MENU_PAD;
DrawRectangle(posx, posy,
btn_width * MENU_COLS + MENU_PAD * (MENU_COLS - 1),
btn_height, Fade(color, 0.7));
DrawRectangleLines(posx, posy,
btn_width * MENU_COLS + MENU_PAD * (MENU_COLS - 1),
btn_height, color);
DrawText(text.data(), posx + BUTTON_PAD, posy + BUTTON_PAD,
btn_height = 2.0 * BUTTON_PAD, WHITE);
};
// Left column
draw_btn(0, 0,
std::format("States: {} / Transitions: {} / Winning: {}",
@ -336,7 +349,7 @@ auto Renderer::DrawMenu(const std::vector<Vector3> &masses) -> void {
state.winning_states.size()),
ORANGE);
draw_btn(0, 1,
std::format("Preset (M/N): {}, {} (F)", state.current_preset,
std::format("Preset (M/N) / {} (F)",
state.current_state.restricted ? "Restricted" : "Free"),
ORANGE);
draw_btn(0, 2, std::format("Pan (LMB) / Rotate (RMB) / Zoom (Wheel)"),
@ -350,27 +363,31 @@ auto Renderer::DrawMenu(const std::vector<Vector3> &masses) -> void {
draw_btn(1, 0, std::format("Select (LMB) / Move (W, A, S, D) / Target (T)"),
DARKBLUE);
draw_btn(1, 1, std::format("Add/Remove Col/Row (Arrow Keys)"), DARKBLUE);
draw_btn(1, 2, std::format("Add/Remove Block (LMB/RMB), Set Goal (MMB)"),
draw_btn(1, 2, std::format("Add/Remove Block (LMB/RMB) / Set Goal (MMB)"),
DARKBLUE);
draw_btn(1, 3, std::format("Print State (P) / Reset State (R)"), DARKBLUE);
// Right column
draw_btn(2, 0, std::format("Populate Graph (G), Clear Graph (C)"),
draw_btn(2, 0, std::format("Populate Graph (G) / Clear Graph (C)"),
DARKPURPLE);
draw_btn(2, 1,
std::format("Path (U): {} / Goals (I): {} / Connect (O): {}",
std::format("Path (U): {} / Goals (I): {} / Lines (O): {}",
input.mark_path, input.mark_solutions,
input.connect_solutions),
DARKPURPLE);
draw_btn(2, 2, std::format("Best move (Space) / Move back (Backspace)"),
DARKPURPLE);
draw_btn(2, 3,
std::format("Worst (V) / Nearest target (B) / Moves remaining: {}",
std::format("Worst (V) / Target (B) / Distance: {}",
state.winning_path.size() > 0
? state.winning_path.size() - 1
: 0),
DARKPURPLE);
draw_subtitle(std::format("Puzzle {}: {}", state.current_preset + 1,
state.comments.at(state.current_preset)),
BLACK);
DrawLine(0, MENU_HEIGHT - 1, GetScreenWidth(), MENU_HEIGHT - 1, BLACK);
EndTextureMode();
}

View File

@ -1,5 +1,6 @@
#include "state.hpp"
#include "config.hpp"
#include "distance.hpp"
#include <fstream>
#include <ios>
@ -19,25 +20,29 @@ auto StateManager::ParsePresetFile(const std::string &preset_file) -> void {
}
std::string line;
std::vector<std::string> lines;
std::vector<std::string> comment_lines;
std::vector<std::string> preset_lines;
while (std::getline(file, line)) {
if (line.starts_with("F") || line.starts_with("R")) {
lines.push_back(line);
preset_lines.push_back(line);
} else if (line.starts_with("#")) {
comment_lines.push_back(line);
}
}
if (lines.size() == 0) {
if (preset_lines.size() == 0 || comment_lines.size() != preset_lines.size()) {
std::cout << "Preset file \"" << preset_file << "\" couldn't be loaded."
<< std::endl;
return;
}
presets.clear();
for (const auto &preset : lines) {
for (const auto &preset : preset_lines) {
presets.emplace_back(preset);
}
comments = comment_lines;
std::cout << "Loaded " << lines.size() << " presets." << std::endl;
std::cout << "Loaded " << preset_lines.size() << " presets." << std::endl;
}
auto StateManager::LoadPreset(int preset) -> void {
@ -50,7 +55,6 @@ auto StateManager::LoadPreset(int preset) -> void {
auto StateManager::ResetState() -> void {
current_state = presets.at(current_preset);
previous_state = current_state;
FindTargetPath();
if (edited) {
// We also need to clear the graph in case the state has been edited
// because the graph could contain states that are impossible to reach