function selector bug fix

This commit is contained in:
2025-08-29 17:44:39 +09:00
committed by cdemeyer-teachx
parent 89e094d3f8
commit c643fd165a
2 changed files with 19 additions and 17 deletions

View File

@@ -264,5 +264,6 @@ using SudokuSolver = WFC::Builder<Sudoku>
} }
} }
} }
}), 1, 2, 3, 4, 5, 6, 7, 8, 9> }), 1, 2, 3, 4, 5, 6, 7, 8, 9>
::Build; ::Build;

View File

@@ -149,14 +149,14 @@ template<std::size_t I,
typename NewConstrainerFunctionT, typename NewConstrainerFunctionT,
typename SelectedIDsVariableIDMapT, typename SelectedIDsVariableIDMapT,
typename EmptyFunctionT> typename EmptyFunctionT>
using MergedConstrainerElementSelector = std::conditional_t< using MergedConstrainerElementSelector =
(I < ConstrainerFunctionMapT::size()), // if the index is within the size of the tuple std::conditional_t<SelectedIDsVariableIDMapT::template HasValue<VariableIDMapT::GetValueConsteval(I)>(), // if the value is in the selected IDs
std::conditional_t<SelectedIDsVariableIDMapT::template HasValue<VariableIDMapT::GetValueConsteval(I)>(), // if the value is in the selected IDs NewConstrainerFunctionT,
NewConstrainerFunctionT, std::conditional_t<(I < ConstrainerFunctionMapT::size()), // if the index is within the size of the tuple
std::tuple_element_t<std::min(I, ConstrainerFunctionMapT::size() - 1), typename ConstrainerFunctionMapT::TupleType> std::tuple_element_t<std::min(I, ConstrainerFunctionMapT::size() - 1), typename ConstrainerFunctionMapT::TupleType>,
>, EmptyFunctionT
EmptyFunctionT >
>; >;
// Helper to make a merged constrainer function map // Helper to make a merged constrainer function map
template<typename VariableIDMapT, template<typename VariableIDMapT,
@@ -368,11 +368,13 @@ public:
if (!Propagate(state)) if (!Propagate(state))
return false; return false;
if (state.wave.IsFullyCollapsed()) { if (state.wave.HasContradiction())
return false;
if (state.wave.IsFullyCollapsed())
return true; return true;
} else {
Branch(state); Branch(state);
}
} }
return false; return false;
} }
@@ -426,7 +428,7 @@ private:
assert(!state.wave.IsCollapsed(minEntropyCell)); assert(!state.wave.IsCollapsed(minEntropyCell));
// create a list of possible values // create a list of possible values
size_t availableValues = state.wave.Entropy(minEntropyCell); uint16_t availableValues = state.wave.Entropy(minEntropyCell);
std::array<uint16_t, VariableIDMapT::ValuesRegisteredAmount> possibleValues; // inplace vector std::array<uint16_t, VariableIDMapT::ValuesRegisteredAmount> possibleValues; // inplace vector
MaskType mask = state.wave.GetMask(minEntropyCell); MaskType mask = state.wave.GetMask(minEntropyCell);
for (size_t i = 0; i < availableValues; ++i) for (size_t i = 0; i < availableValues; ++i)
@@ -441,10 +443,10 @@ private:
} }
// randomly select a value from possible values // 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<uint16_t> dist(0, availableValues - 1); std::uniform_int_distribution<size_t> dist(0, availableValues - 1);
uint16_t selectedValue = possibleValues[dist(state.rng)]; size_t selectedValue = possibleValues[dist(state.rng)];
{ {
// copy the state and branch out // copy the state and branch out
@@ -503,7 +505,6 @@ private:
} }
} }
private:
static void PropogateInitialValues(SolverState& state) static void PropogateInitialValues(SolverState& state)
{ {
auto allValues = VariableIDMapT::GetAllValues(); auto allValues = VariableIDMapT::GetAllValues();