branch bug fix
This commit is contained in:
@@ -212,12 +212,12 @@ public:
|
||||
|
||||
private:
|
||||
void ApplyMask(size_t cellId, MaskType mask) {
|
||||
if (m_wave.IsCollapsed(cellId)) return;
|
||||
bool wasCollapsed = m_wave.IsCollapsed(cellId);
|
||||
|
||||
m_wave.Collapse(cellId, mask);
|
||||
assert(!m_wave.HasContradiction() && "Contradiction found");
|
||||
|
||||
if (m_wave.IsCollapsed(cellId)) {
|
||||
bool collapsed = m_wave.IsCollapsed(cellId);
|
||||
if (!wasCollapsed && collapsed) {
|
||||
m_propagationQueue.push(cellId);
|
||||
}
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public:
|
||||
bool Run(WorldT& world, bool propagateInitialValues = false)
|
||||
{
|
||||
//auto seed = std::random_device{}();
|
||||
auto seed = 1844803044ull;
|
||||
auto seed = 1844803044ul;
|
||||
std::mt19937 random{ seed };
|
||||
SolverState state(world, m_variables.size(), random);
|
||||
return Run(state, propagateInitialValues);
|
||||
@@ -307,12 +307,11 @@ public:
|
||||
constexpr size_t maxIterations = 1024;
|
||||
for (size_t i = 0; i < maxIterations; ++i)
|
||||
{
|
||||
Propagate(state);
|
||||
if (!Propagate(state))
|
||||
return false;
|
||||
|
||||
if (state.wave.IsFullyCollapsed()) {
|
||||
return true;
|
||||
} else if (state.wave.HasContradiction()) {
|
||||
return false;
|
||||
} else {
|
||||
Branch(state);
|
||||
}
|
||||
@@ -414,19 +413,22 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
void Propagate(SolverState& state)
|
||||
bool Propagate(SolverState& state)
|
||||
{
|
||||
while (!state.propagationQueue.empty())
|
||||
{
|
||||
size_t cellId = state.propagationQueue.front();
|
||||
state.propagationQueue.pop();
|
||||
|
||||
if (state.wave.IsContradicted(cellId)) return false;
|
||||
|
||||
assert(state.wave.IsCollapsed(cellId) && "Cell was not collapsed");
|
||||
|
||||
uint16_t variableID = state.wave.GetVariableID(cellId);
|
||||
Constrainer<VariableIDMapT> constrainer(state.wave, state.propagationQueue);
|
||||
m_variables[variableID].constraintFunc(state.world, cellId, WorldValue<VarT>{VariableIDMapT::GetValue(variableID), variableID}, constrainer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PopulateWorld(SolverState& state)
|
||||
|
||||
Reference in New Issue
Block a user