add button to move to a state farthest from any win condition

This commit is contained in:
2026-02-25 03:20:40 +01:00
parent 271902ab1f
commit 3f8274f1d9
6 changed files with 33 additions and 8 deletions

View File

@ -82,6 +82,10 @@ public:
auto FindTargetPath() -> void;
auto FindWorstState() -> State;
auto GoToWorst() -> void;
auto CurrentMassIndex() const -> std::size_t;
};

View File

@ -2,7 +2,6 @@
#include "config.hpp"
#include <cstddef>
#include <iostream>
#include <queue>
#ifdef TRACY

View File

@ -1,6 +1,5 @@
#include "input.hpp"
#include "config.hpp"
#include "distance.hpp"
#include <algorithm>
#include <raylib.h>
@ -154,6 +153,8 @@ auto InputHandler::HandleKeys() -> void {
mark_path = !mark_path;
} else if (IsKeyPressed(KEY_SPACE)) {
state.NextPath();
} else if (IsKeyPressed(KEY_V)) {
state.GoToWorst();
} else if (IsKeyPressed(KEY_F)) {
state.current_state.ToggleRestricted();
state.ClearGraph();

View File

@ -3,7 +3,6 @@
#include <raymath.h>
#include "config.hpp"
#include "distance.hpp"
#include "input.hpp"
#include "physics.hpp"
#include "renderer.hpp"
@ -16,8 +15,7 @@
// TODO: Graph interaction
// - 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: Add a move history and backspace to go back
auto main(int argc, char *argv[]) -> int {
std::string preset_file;

View File

@ -351,7 +351,8 @@ auto Renderer::DrawMenu(const std::vector<Vector3> &masses) -> void {
input.mark_path, input.mark_solutions,
input.connect_solutions),
DARKPURPLE);
draw_btn(2, 3, std::format("Move along Path (Space)"), DARKPURPLE);
draw_btn(2, 3, std::format("Path forward (Space) / To worst (V)"),
DARKPURPLE);
DrawLine(0, MENU_HEIGHT - 1, GetScreenWidth(), MENU_HEIGHT - 1, BLACK);
EndTextureMode();

View File

@ -193,8 +193,30 @@ auto StateManager::FindTargetPath() -> void {
}
winning_path = GetPath(target_distances, CurrentMassIndex());
// std::cout << "Nearest target is " << winning_path.size() << " moves away."
// << std::endl;
std::cout << "Nearest target is " << winning_path.size() << " moves away."
<< std::endl;
}
auto StateManager::FindWorstState() -> State {
if (target_distances.Empty()) {
return current_state;
}
int max = 0;
int index = 0;
for (std::size_t i = 0; i < target_distances.distances.size(); ++i) {
if (target_distances.distances[i] > max) {
max = target_distances.distances[i];
index = i;
}
}
return masses.at(index);
}
auto StateManager::GoToWorst() -> void {
current_state = FindWorstState();
FindTargetPath();
}
auto StateManager::CurrentMassIndex() const -> std::size_t {