protected void FindSolution(Step current) { if (CancellationPending) { return; } if (current.Number > _stepLimit) { current.Stop(StopReason.StepLimit); return; } current.Status = StepStatus.InProgress; current.Variants.Clear(); var moves = current.GetPossibleMoves(); if (moves.Count == 0) { current.Stop(StopReason.NoMoves); return; } foreach (var m in moves) { var step = ProcessMove(current, m); if (step.StopReason == StopReason.FieldFoundEarly) { continue; } SetLevelForProgress(step); SetLevelField(step); current.Variants.Add(step); } if (CancellationPending) { return; } var toProcess = current.Variants.Where(e => e.Status == StepStatus.New).ToArray(); foreach (var step in toProcess) { AddInProgress(step); } current.Stop(StopReason.Solved); }
private void FindSolution(Step current) { if (this.CancellationPending) { return; } if (current.Number > StepLimit) { current.Stop(StopReason.StepLimit); return; } current.Status = StepStatus.InProgress; current.Variants.Clear(); var moves = current.GetPossibleMoves(); if (moves.Count == 0) { current.Stop(StopReason.NoMoves); return; } foreach (var m in moves) { var step = ProcessMove(current, m); if (step.StopReason == StopReason.FieldFoundEarly && MemoryOptimization) { continue; } SetLevelForProgress(step); SetLevelField(step); current.Variants.Add(step); } var toProcess = current.Variants.Where(e => e.Status == StepStatus.New).ToArray(); foreach (var step in toProcess) { Step s = step; AddInProgress(new async(() => FindSolution(s), _threadPool)); } current.Stop(StopReason.Solved); }