fix bug where starting index was set incorrectly when populating graph
This commit is contained in:
@ -51,11 +51,11 @@ public:
|
||||
instancing_shader.locs[SHADER_LOC_VECTOR_VIEW] =
|
||||
GetShaderLocation(instancing_shader, "viewPos");
|
||||
|
||||
infoln("LOC vertexPosition: {}",
|
||||
rlGetLocationAttrib(instancing_shader.id, "vertexPosition"));
|
||||
infoln("LOC instanceTransform: {}",
|
||||
rlGetLocationAttrib(instancing_shader.id, "instanceTransform"));
|
||||
infoln("LOC instanceColor: {}", rlGetLocationAttrib(instancing_shader.id, "instanceColor"));
|
||||
// infoln("LOC vertexPosition: {}",
|
||||
// rlGetLocationAttrib(instancing_shader.id, "vertexPosition"));
|
||||
// infoln("LOC instanceTransform: {}",
|
||||
// rlGetLocationAttrib(instancing_shader.id, "instanceTransform"));
|
||||
// infoln("LOC instanceColor: {}", rlGetLocationAttrib(instancing_shader.id, "instanceColor"));
|
||||
|
||||
// vertex_mat.maps[MATERIAL_MAP_DIFFUSE].color = VERTEX_COLOR;
|
||||
vertex_mat.shader = instancing_shader;
|
||||
|
||||
@ -34,7 +34,7 @@ private:
|
||||
std::unordered_set<size_t>
|
||||
path_indices; // For faster lookup if a vertex is part of the path in renderer
|
||||
|
||||
std::stack<size_t> move_history; // Moves between the starting state and the current state
|
||||
std::vector<size_t> move_history; // Moves between the starting state and the current state
|
||||
std::unordered_map<size_t, int> visit_counts; // How often each state was visited
|
||||
|
||||
size_t starting_state_index = 0;
|
||||
|
||||
@ -498,7 +498,7 @@ auto puzzle::explore_state_space() const
|
||||
ZoneScoped;
|
||||
#endif
|
||||
|
||||
infoln("Exploring state space, this might take a while...");
|
||||
// infoln("Exploring state space, this might take a while...");
|
||||
|
||||
std::vector<puzzle> state_pool;
|
||||
std::unordered_map<puzzle, std::size_t> state_indices; // Helper to construct the links vector
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include <ios>
|
||||
|
||||
#ifdef TRACY
|
||||
#include <tracy/Tracy.hpp>
|
||||
#include <tracy/Tracy.hpp>
|
||||
#endif
|
||||
|
||||
auto state_manager::synced_try_insert_state(const puzzle& state) -> size_t
|
||||
@ -35,8 +35,7 @@ auto state_manager::synced_insert_link(size_t first_index, size_t second_index)
|
||||
}
|
||||
|
||||
auto state_manager::synced_insert_statespace(const std::vector<puzzle>& states,
|
||||
const std::vector<std::pair<size_t, size_t>>& _links)
|
||||
-> void
|
||||
const std::vector<std::pair<size_t, size_t>>& _links) -> void
|
||||
{
|
||||
if (!state_pool.empty() || !state_indices.empty() || !links.empty()) {
|
||||
warnln("Inserting statespace but collections haven't been cleared");
|
||||
@ -71,7 +70,7 @@ auto state_manager::synced_clear_statespace() -> void
|
||||
winning_path.clear();
|
||||
path_indices.clear();
|
||||
|
||||
move_history = std::stack<size_t>();
|
||||
// move_history.clear();
|
||||
visit_counts.clear();
|
||||
|
||||
// Queue an update to the physics engine state to keep in sync
|
||||
@ -186,7 +185,7 @@ auto state_manager::update_current_state(const puzzle& p) -> void
|
||||
current_state_index = index;
|
||||
|
||||
if (current_state_index != previous_state_index) {
|
||||
move_history.push(previous_state_index);
|
||||
move_history.emplace_back(previous_state_index);
|
||||
}
|
||||
|
||||
if (p.won()) {
|
||||
@ -208,7 +207,7 @@ auto state_manager::edit_starting_state(const puzzle& p) -> void
|
||||
{
|
||||
clear_graph_and_add_current(p);
|
||||
|
||||
move_history = std::stack<size_t>();
|
||||
move_history.clear();
|
||||
total_moves = 0;
|
||||
for (int& visits : visit_counts | std::views::values) {
|
||||
visits = 0;
|
||||
@ -226,7 +225,7 @@ auto state_manager::goto_starting_state() -> void
|
||||
visits = 0;
|
||||
}
|
||||
visit_counts[current_state_index]++;
|
||||
move_history = std::stack<size_t>();
|
||||
move_history.clear();
|
||||
total_moves = 0;
|
||||
}
|
||||
|
||||
@ -251,11 +250,11 @@ auto state_manager::goto_previous_state() -> void
|
||||
return;
|
||||
}
|
||||
|
||||
update_current_state(get_state(move_history.top()));
|
||||
update_current_state(get_state(move_history.back()));
|
||||
|
||||
// Pop twice because update_current_state adds the state again...
|
||||
move_history.pop();
|
||||
move_history.pop();
|
||||
move_history.pop_back();
|
||||
move_history.pop_back();
|
||||
}
|
||||
|
||||
auto state_manager::goto_most_distant_state() -> void
|
||||
@ -287,23 +286,24 @@ auto state_manager::goto_closest_target_state() -> void
|
||||
|
||||
auto state_manager::populate_graph() -> void
|
||||
{
|
||||
#ifdef TRACY
|
||||
#ifdef TRACY
|
||||
ZoneScoped;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Need to make a copy before clearing the state_pool
|
||||
const puzzle s = get_starting_state();
|
||||
const puzzle p = get_current_state();
|
||||
|
||||
// Clear the graph first so we don't add duplicates somehow
|
||||
synced_clear_statespace();
|
||||
|
||||
// Explore the entire statespace starting from the current state
|
||||
const auto& [states, _links] = p.explore_state_space();
|
||||
const auto& [states, _links] = s.explore_state_space();
|
||||
synced_insert_statespace(states, _links);
|
||||
|
||||
current_state_index = state_indices.at(p);
|
||||
previous_state_index = current_state_index;
|
||||
starting_state_index = current_state_index;
|
||||
starting_state_index = state_indices.at(s);
|
||||
|
||||
// Search for cool stuff
|
||||
populate_winning_indices();
|
||||
@ -345,9 +345,9 @@ auto state_manager::populate_winning_indices() -> void
|
||||
|
||||
auto state_manager::populate_node_target_distances() -> void
|
||||
{
|
||||
#ifdef TRACY
|
||||
#ifdef TRACY
|
||||
ZoneScoped;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (links.empty() || winning_indices.empty()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user