From 4f6e98bae8da001aab9674ecb7bea79e338a51a9 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 23 Feb 2026 14:38:53 +0100 Subject: [PATCH] mark visited and starting states --- include/renderer.hpp | 5 +++-- include/state.hpp | 3 +++ src/main.cpp | 5 ++--- src/renderer.cpp | 17 ++++++++++++++++- src/state.cpp | 6 ++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/renderer.hpp b/include/renderer.hpp index 143af01..92612fe 100644 --- a/include/renderer.hpp +++ b/include/renderer.hpp @@ -71,8 +71,9 @@ public: auto UpdateTextureSizes() -> void; auto DrawMassSprings(const MassSpringSystem &mass_springs, - const State ¤t_state, - const std::unordered_set &winning_states) -> void; + const State ¤t_state, const State &starting_state, + const std::unordered_set &winning_states, + const std::unordered_set &visited_states) -> void; auto DrawKlotski(const State &state, int hov_x, int hov_y, int sel_x, int sel_y, int block_add_x, int block_add_y, diff --git a/include/state.hpp b/include/state.hpp index 3512ec7..3678360 100644 --- a/include/state.hpp +++ b/include/state.hpp @@ -19,6 +19,7 @@ public: bool edited = false; std::unordered_set winning_states; + std::unordered_set visited_states; public: StateManager(MassSpringSystem &mass_springs) @@ -52,6 +53,8 @@ public: auto FindWinningStates() -> void; + auto CurrentGenerator() -> StateGenerator; + auto CurrentWinCondition() -> WinCondition; }; diff --git a/src/main.cpp b/src/main.cpp index 2a4794a..fd7d0c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,8 +23,6 @@ // - Click states to display them in the board // - Find shortest path to any winning state and mark it in the graph // - Also mark the next move along the path on the board -// TODO: Mark the starting state -// TODO: Mark the visited states auto main(int argc, char *argv[]) -> int { // if (argc < 2) { @@ -103,7 +101,8 @@ auto main(int argc, char *argv[]) -> int { renderer.UpdateTextureSizes(); renderer.DrawMassSprings(mass_springs, state.current_state, - state.winning_states); + state.CurrentGenerator()(), state.winning_states, + state.visited_states); renderer.DrawKlotski(state.current_state, input.hov_x, input.hov_y, input.sel_x, input.sel_y, input.block_add_x, diff --git a/src/renderer.cpp b/src/renderer.cpp index 831febd..57f7ad2 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -63,7 +63,9 @@ auto Renderer::ReallocateGraphInstancingIfNecessary( auto Renderer::DrawMassSprings(const MassSpringSystem &mass_springs, const State ¤t_state, - const std::unordered_set &winning_states) + const State &starting_state, + const std::unordered_set &winning_states, + const std::unordered_set &visited_states) -> void { ZoneScoped; @@ -124,6 +126,19 @@ auto Renderer::DrawMassSprings(const MassSpringSystem &mass_springs, } } + // Mark visited states + for (const auto &state : visited_states) { + const Mass &visited_mass = mass_springs.GetMass(state); + + DrawCube(visited_mass.position, VERTEX_SIZE * 1.5, VERTEX_SIZE * 1.5, + VERTEX_SIZE * 1.5, PURPLE); + } + + // Mark starting state + const Mass &starting_mass = mass_springs.GetMass(starting_state); + DrawCube(starting_mass.position, VERTEX_SIZE * 2, VERTEX_SIZE * 2, + VERTEX_SIZE * 2, ORANGE); + // Mark current state const Mass ¤t_mass = mass_springs.GetMass(current_state); DrawCube(current_mass.position, VERTEX_SIZE * 2, VERTEX_SIZE * 2, diff --git a/src/state.cpp b/src/state.cpp index 3e22cb7..7c515f5 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -64,11 +64,13 @@ auto StateManager::UpdateGraph() -> void { if (win_conditions[current_preset](current_state)) { winning_states.insert(current_state); } + visited_states.insert(current_state); } } auto StateManager::ClearGraph() -> void { winning_states.clear(); + visited_states.clear(); mass_springs.Clear(); mass_springs.AddMass(MASS, false, current_state); @@ -88,6 +90,10 @@ auto StateManager::FindWinningStates() -> void { << std::endl; } +auto StateManager::CurrentGenerator() -> StateGenerator { + return generators[current_preset]; +} + auto StateManager::CurrentWinCondition() -> WinCondition { return win_conditions[current_preset]; }