Пример #1
0
        public void Solve()
        {
            AllSolutions = new C.ConcurrentBag <LLint>();

            List <T.Task> allTasks = new List <T.Task>();

            foreach (var start in AllEdges(Starts))
            {
                if (AllSolutions.Count() < MaxCountSolutions)
                {
                    var Ta = new T.Task(
                        (edgeAndStartObject) =>
                    {
                        var edgeAndStart = (Tuple <LLint, LLint>)edgeAndStartObject;
                        Backtracking(edgeAndStart.Item1, edgeAndStart.Item2);
                    }, new Tuple <LLint, LLint>(Fn.Clone(AllEdges(Horizontals.Concat(Verticals.Concat(Diagonals))).Where(e => !Fn.Equal(e, start))), Fn.L(start)));

                    allTasks.Add(Ta);
                    Ta.Start();
                }
            }

            T.Task.WaitAll(allTasks.ToArray());

#if DEBUG
            DebugViewResult();
#endif
        }
Пример #2
0
        void Backtracking(LLint Edges, LLint Path)
        {
            // Nur bis zu 4 Linienzüge untersuchen
            if (Path.Count() < MaxPathLength && AllSolutions.Count() <= MaxCountSolutions)
            {
                int currentEndpoint = Path.Last().Last();

                foreach (var edge in Edges.Where(e => IsEndpoint(currentEndpoint, e)))
                {
                    var PathExt = edge.First() == currentEndpoint?Path.Concat(Fn.L(edge)) : Path.Concat(Fn.L(edge.Reverse()));

                    if (IsSolution(PathExt))
                    {
                        AllSolutions.Add(PathExt);
                    }
                    else
                    {
                        Backtracking(Edges.Where(e => !Fn.Equal(e, edge)), PathExt);
                    }
                }
            }
        }