Exemple #1
0
 private void DrawPuzzle(LibraryPuzzle libraryPuzzle, RectInt r)
 {
     foreach (var(inner, outer) in r.InnerVsOuter())
     {
         Renderer[outer] = Style[libraryPuzzle.Puzzle[inner]];
     }
 }
        public ConsoleAnimatedSokobanGame(LibraryPuzzle puzzle, IRenderer <SokobanPixel> renderer, PlayPuzzleScene parent, DisplayStyle style) : base(puzzle)
        {
            this.renderer = renderer;
            this.parent   = parent;
            this.style    = style;

            Text = new ConsoleElement()
            {
                Paint = (el) =>
                {
                    foreach (var(item, index) in Text.lines.WithIndex())
                    {
                        renderer.DrawText(renderer.Geometry.TL + (0, index + 2), item.Text, parent.DefaultStyle, TextAlign.Left);
                    }
                }
            };
            MouseMoveElement = new MouseMoveElement(parent.Input)
            {
                Paint = PaintMouse
            };
            Tutorial = new TutorialElement()
            {
                Paint = (el) =>
                {
                    if (Tutorial.CurrentMessageText != null)
                    {
                        renderer.DrawText((PuzzleSurface.ML.X / 2, PuzzleSurface.ML.Y), Tutorial.CurrentMessageText, style.Info.AsPixel(), TextAlign.Middle);
                    }
                }
            };
        }
Exemple #3
0
 public SolverResultSummary(LibraryPuzzle puzzle, List <Path> solutions, ExitConditions.Conditions exited, string text, TimeSpan duration, SolverStatistics statistics)
 {
     Puzzle     = puzzle;
     Solutions  = solutions;
     Exited     = exited;
     Text       = text;
     Duration   = duration;
     Statistics = statistics;
 }
 protected AnimatedSokobanGame(LibraryPuzzle puzzle) : base(puzzle.Puzzle)
 {
     LibraryPuzzle = puzzle;
     RootElements  = new List <GameElement>();
     AllElements   = new List <GameElement>();
     Bookmarks     = new List <Bookmark>();
     Text          = new ConsoleElement();
     ToBeRemoved   = new List <GameElement>();
 }
Exemple #5
0
        private int StoreAttempt(ISolver solver, LibraryPuzzle dto, SolverState state, string desc)
        {
            var best = state.Solutions?.OrderBy(x => x.Count).FirstOrDefault();


            var sol = new SolutionDTO
            {
                IsAutomated        = true,
                PuzzleIdent        = dto.Ident.ToString(),
                Path               = best?.ToString(),
                Created            = DateTime.Now,
                Modified           = DateTime.Now,
                MachineName        = Environment.MachineName,
                MachineCPU         = DevHelper.DescribeCPU(),
                SolverType         = solver.GetType().Name,
                SolverVersionMajor = solver.VersionMajor,
                SolverVersionMinor = solver.VersionMinor,
                SolverDescription  = solver.VersionDescription,
                TotalNodes         = solver.Statistics.First().TotalNodes,
                TotalSecs          = solver.Statistics.First().DurationInSec,
                Description        = desc
            };

            var exists = Repository.GetPuzzleSolutions(dto.Ident);

            if (exists != null && exists.Any())
            {
                var onePerMachine = exists.FirstOrDefault(x => x.MachineName == sol.MachineName && x.SolverType == sol.SolverType);
                if (onePerMachine != null)
                {
                    if (sol.HasSolution)
                    {
                        if (!onePerMachine.HasSolution)
                        {
                            sol.SolutionId = onePerMachine.SolutionId; // replace
                            Repository.Store(sol);
                            return(sol.SolutionId);
                        }
                        else if (sol.TotalNodes < onePerMachine.TotalSecs)
                        {
                            sol.SolutionId = onePerMachine.SolutionId; // replace
                            Repository.Store(sol);
                            return(sol.SolutionId);
                        }
                        else
                        {
                            // drop
                        }
                    }
                    else
                    {
                        if (!onePerMachine.HasSolution && sol.TotalNodes > onePerMachine.TotalNodes)
                        {
                            sol.SolutionId = onePerMachine.SolutionId; // replace
                            Repository.Store(sol);
                            return(sol.SolutionId);
                        }
                    }
                }
                else
                {
                    Repository.Store(sol);
                    return(sol.SolutionId);
                }
            }
            else
            {
                Repository.Store(sol);
                return(sol.SolutionId);
            }

            return(-1);
        }
 public void Solve(LibraryPuzzle libraryPuzzle)
 {
     //Parent.SetGoalFPS(10);    // We want it slow
     Current = new SolverScene(this, libraryPuzzle.Puzzle);
     Current.Init();
 }
 public void PlayPuzzle(LibraryPuzzle libraryPuzzle)
 {
     Current = puzzle = new PlayPuzzleScene(this, libraryPuzzle);
     puzzle.Init();
 }
Exemple #8
0
 public PlayPuzzleScene(SokoSolveMasterGameLoop parent, LibraryPuzzle libraryPuzzle) : base(parent)
 {
     LibraryPuzzle = libraryPuzzle;
     GameLogic     = new ConsoleAnimatedSokobanGame(LibraryPuzzle, parent.Renderer, this, parent.Style);
 }