From c643fd165a82fa661552f5734397bda620ec7255 Mon Sep 17 00:00:00 2001 From: Connor De Meyer Date: Fri, 29 Aug 2025 17:44:39 +0900 Subject: [PATCH] function selector bug fix --- demos/sudoku/sudoku.h | 1 + include/nd-wfc/wfc.hpp | 35 ++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/demos/sudoku/sudoku.h b/demos/sudoku/sudoku.h index 3e71bff..d22b0f7 100644 --- a/demos/sudoku/sudoku.h +++ b/demos/sudoku/sudoku.h @@ -264,5 +264,6 @@ using SudokuSolver = WFC::Builder } } } + }), 1, 2, 3, 4, 5, 6, 7, 8, 9> ::Build; \ No newline at end of file diff --git a/include/nd-wfc/wfc.hpp b/include/nd-wfc/wfc.hpp index 2f9fc91..f5fab33 100644 --- a/include/nd-wfc/wfc.hpp +++ b/include/nd-wfc/wfc.hpp @@ -149,14 +149,14 @@ template -using MergedConstrainerElementSelector = std::conditional_t< - (I < ConstrainerFunctionMapT::size()), // if the index is within the size of the tuple - std::conditional_t(), // if the value is in the selected IDs - NewConstrainerFunctionT, - std::tuple_element_t - >, - EmptyFunctionT ->; +using MergedConstrainerElementSelector = + std::conditional_t(), // if the value is in the selected IDs + NewConstrainerFunctionT, + std::conditional_t<(I < ConstrainerFunctionMapT::size()), // if the index is within the size of the tuple + std::tuple_element_t, + EmptyFunctionT + > + >; // Helper to make a merged constrainer function map template possibleValues; // inplace vector MaskType mask = state.wave.GetMask(minEntropyCell); for (size_t i = 0; i < availableValues; ++i) @@ -441,10 +443,10 @@ private: } // randomly select a value from possible values - for (size_t i = 0; i < availableValues; ++i) + for (size_t i = 0; i < availableValues; ++i) { - std::uniform_int_distribution dist(0, availableValues - 1); - uint16_t selectedValue = possibleValues[dist(state.rng)]; + std::uniform_int_distribution dist(0, availableValues - 1); + size_t selectedValue = possibleValues[dist(state.rng)]; { // copy the state and branch out @@ -503,7 +505,6 @@ private: } } -private: static void PropogateInitialValues(SolverState& state) { auto allValues = VariableIDMapT::GetAllValues();