Exemple #1
0
        public void Load(LibraryComponent lib, string fileName)
        {
            Init();

            var idents = new List <PuzzleIdent>();
            var file   = TrivialNameValueFileFormat.Load(lib.GetPathData(fileName));

            foreach (var pair in file)
            {
                if (pair.Key == "PuzzleExit.Duration")
                {
                    BatchExit.Duration = TimeSpan.FromSeconds(int.Parse(pair.Value));
                }

                if (pair.Key == "BatchExit.Duration")
                {
                    BatchExit.Duration = TimeSpan.FromSeconds(int.Parse(pair.Value));
                }

                if (pair.Key.StartsWith("Puzzle."))
                {
                    idents.Add(PuzzleIdent.Parse(pair.Value));
                }
            }

            AddRange(lib.LoadAllPuzzles(idents));
        }
        public IActionResult SolveStart(string id, bool stopOnSolution, double duration = 1)
        {
            var ident = PuzzleIdent.Parse(id);
            var p     = compLib.GetPuzzleWithCaching(ident);

            var solver        = new MultiThreadedForwardReverseSolver(new SolverNodeFactoryPoolingConcurrentBag("byteseq"));
            var solverCommand = new SolverCommand()
            {
                Puzzle         = p.Puzzle,
                ExitConditions = new ExitConditions()
                {
                    Duration       = TimeSpan.FromMinutes(duration),
                    StopOnSolution = true
                }
            };
            var model = new SolverModel()
            {
                Token   = DateTime.Now.Ticks,
                Puzzle  = p,
                Command = solverCommand,
                State   = solver.Init(solverCommand)
            };

            staticState[model.Token] = model;

            model.Task = Task.Run(() =>
            {
                solver.Solve(model.State);
                model.IsFinished = true;
            });

            return(RedirectToAction("SolveMem", new { id, token = model.Token }));
        }
Exemple #3
0
 public override int GetHashCode()
 {
     #if NETSTANDARD2_1
     return(HashCode.Combine(SolutionId, PuzzleIdent));
     #else
     return(SolutionId.GetHashCode() << 4 ^ PuzzleIdent.GetHashCode());
     #endif
 }
 public IReadOnlyCollection <SolutionDTO>?GetPuzzleSolutions(PuzzleIdent puzzleId)
 {
     if (data.ByPuzzles.TryGetValue(puzzleId.ToString(), out var s))
     {
         return(s);
     }
     return(null);
 }
        public IActionResult StaticAnalysis(string id)
        {
            var ident = PuzzleIdent.Parse(id);
            var p     = compLib.GetPuzzleWithCaching(ident);

            return(View(new HomeModel()
            {
                Puzzle = p,
                StaticAnalysis = new StaticAnalysisMaps(p.Puzzle)
            }));
        }
        public IActionResult Svg(string id, float w = 16, float h = 16)
        {
            var ident = PuzzleIdent.Parse(id);
            var p     = compLib.GetPuzzleWithCaching(ident);
            var sols  = repSol.GetPuzzleSolutions(ident);

            var sb = new StringBuilder();

            using (var tw = new StringWriter(sb))
            {
                var dia = new PuzzleDiagram()
                {
                    GetResource = x => "/img/" + x
                };
                dia.Draw(tw, p.Puzzle, new Vector2(w, h));
            }

            return(Content(sb.ToString(), "image/svg+xml"));
        }
Exemple #7
0
        public IActionResult StartFromFile(string file)
        {
            var fileName = Path.GetFileName(file);
            var ident    = PuzzleIdent.Parse(fileName.Substring(0, fileName.IndexOf("-")));
            var p        = compLib.GetPuzzleWithCaching(ident);

            var solver        = new MultiThreadedForwardReverseSolver(new SolverNodeFactoryPoolingConcurrentBag("byteseq"));
            var solverCommand = new SolverCommand()
            {
                Puzzle         = p.Puzzle,
                ExitConditions = new ExitConditions()
                {
                    Duration       = TimeSpan.FromMinutes(0),
                    StopOnSolution = true
                }
            };
            var model = new SolverModel()
            {
                Token   = DateTime.Now.Ticks,
                Puzzle  = p,
                Command = solverCommand,
            };

            staticState[model.Token] = model;

            model.Task = Task.Run(() =>
            {
                var ser = new BinaryNodeSerializer();
                using (var f = System.IO.File.OpenRead(file))
                {
                    using (var br = new BinaryReader(f))
                    {
                        model.RootForward = ser.AssembleTree(br);
                    }
                }
                model.IsFinished = true;
            });

            return(RedirectToAction("SolveMem", new { id = ident.ToString(), token = model.Token }));
        }