function selector bug fix
This commit is contained in:
@@ -264,5 +264,6 @@ using SudokuSolver = WFC::Builder<Sudoku>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}), 1, 2, 3, 4, 5, 6, 7, 8, 9>
|
||||
::Build;
|
||||
@@ -149,14 +149,14 @@ template<std::size_t I,
|
||||
typename NewConstrainerFunctionT,
|
||||
typename SelectedIDsVariableIDMapT,
|
||||
typename EmptyFunctionT>
|
||||
using MergedConstrainerElementSelector = std::conditional_t<
|
||||
(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
|
||||
NewConstrainerFunctionT,
|
||||
std::tuple_element_t<std::min(I, ConstrainerFunctionMapT::size() - 1), typename ConstrainerFunctionMapT::TupleType>
|
||||
>,
|
||||
EmptyFunctionT
|
||||
>;
|
||||
using MergedConstrainerElementSelector =
|
||||
std::conditional_t<SelectedIDsVariableIDMapT::template HasValue<VariableIDMapT::GetValueConsteval(I)>(), // 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<std::min(I, ConstrainerFunctionMapT::size() - 1), typename ConstrainerFunctionMapT::TupleType>,
|
||||
EmptyFunctionT
|
||||
>
|
||||
>;
|
||||
|
||||
// Helper to make a merged constrainer function map
|
||||
template<typename VariableIDMapT,
|
||||
@@ -368,11 +368,13 @@ public:
|
||||
if (!Propagate(state))
|
||||
return false;
|
||||
|
||||
if (state.wave.IsFullyCollapsed()) {
|
||||
if (state.wave.HasContradiction())
|
||||
return false;
|
||||
|
||||
if (state.wave.IsFullyCollapsed())
|
||||
return true;
|
||||
} else {
|
||||
Branch(state);
|
||||
}
|
||||
|
||||
Branch(state);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -426,7 +428,7 @@ private:
|
||||
assert(!state.wave.IsCollapsed(minEntropyCell));
|
||||
|
||||
// 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
|
||||
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<uint16_t> dist(0, availableValues - 1);
|
||||
uint16_t selectedValue = possibleValues[dist(state.rng)];
|
||||
std::uniform_int_distribution<size_t> 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();
|
||||
|
||||
Reference in New Issue
Block a user