public Solved Solve(State state2)
        {
            var list = Storage.GetSingleMeta(state2.ProblemId).Select(
                solutionMeta =>
            {
                if (!string.IsNullOrEmpty(solutionMeta.BuyBlob))
                {
                    return(null);
                }
                var solved = Emulator.ParseSolved(solutionMeta.SolutionBlob, solutionMeta.BuyBlob);
                if (solved.Actions.Any(aa => aa.Any(a => a is UseDrill || a is UseFastWheels)))
                {
                    return(null);
                }

                return(new { solutionMeta, solved });
            })
                       .Where(x => x != null)
                       .ToList();

            var selected = list.OrderBy(x => x.solutionMeta.OurTime).DistinctBy(x => x.solutionMeta.OurTime).Take(10).ToList();

            var    bestTime   = int.MaxValue;
            Solved bestSolved = null;

            foreach (var sss in selected)
            {
                var state = ProblemReader.Read(sss.solutionMeta.ProblemId).ToState();
                Emulator.Emulate(state, sss.solved);
                var postprocessor = new PostprocessorSimple(state, sss.solved);
                postprocessor.TransferSmall();

                var buildSolved = state.History.BuildSolved();

                try
                {
                    state = ProblemReader.Read(sss.solutionMeta.ProblemId).ToState();
                    Emulator.Emulate(state, buildSolved);
                    if (state.UnwrappedLeft > 0)
                    {
                        throw new InvalidOperationException("Bad mother f****r!");
                    }
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine(e);
                    continue;
                }

                var time = buildSolved.CalculateTime();
                if (time < bestTime)
                {
                    bestTime   = time;
                    bestSolved = buildSolved;
                }
            }

            return(bestSolved);
        }
Beispiel #2
0
        public void SavePuzzle(Solved solved, int blockId)
        {
            var text     = solved.FormatSolution();
            var fileName = Path.Combine(FileHelper.PatchDirectoryName("problems"), "puzzles", $"block{blockId:000}.sol");

            File.WriteAllText(fileName, text);
            Save(solved, 500 + blockId);
        }
Beispiel #3
0
 void Start()
 {
     temp2 = temp6 = 0;
     tries = new Tries(15, this);
     // 6 is the no. of minigames
     solved         = new Solved(15, this);
     _score         = 0;
     Time.timeScale = 0;
 }
Beispiel #4
0
        public void Save(Solved solved, int id, string suffix = null)
        {
            var text        = solved.FormatSolution();
            var fileName    = Path.Combine(FileHelper.PatchDirectoryName("problems"), "all", $"prob-{id:000}{suffix}.sol");
            var buyFileName = Path.Combine(FileHelper.PatchDirectoryName("problems"), "all", $"prob-{id:000}{suffix}.buy");

            File.WriteAllText(fileName, text);
            File.WriteAllText(buyFileName, solved.FormatBuy());
        }
 public PostprocessorSimple(State state, Solved solved)
 {
     this.state   = state;
     startIndexes = Enumerable.Range(0, solved.Actions.Count).Select(x => 0).ToArray();
     for (int i = 0; i < solved.Actions[0].Count; i++)
     {
         if (solved.Actions[0][i] is UseExtension || solved.Actions[0][i] is UseCloning)
         {
             startIndexes[0] = i + 2;
         }
     }
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Solved.Problem66();

            sw.Stop();
            Console.WriteLine("Done in {0:0.000}s", sw.ElapsedMilliseconds / 1000f);
            Console.ReadKey();
        }
Beispiel #7
0
        public bool Save()
        {
            ImageFormat imgF = Source == Sources.Game ? ImageFormat.Jpeg : ImageFormat.Png;

            Blocks.UpdateBlocksGroups();
            try {
                Dictionary <string, string> dict = new Dictionary <string, string>
                {
                    { "Title", Title }
                };
                if (Source == Sources.Workshop)
                {
                    dict.Add("Creator", Author.ToString());
                    dict.Add("WorkhopID", WorkshopID.ToString());
                }
                dict.Add("IsAdvanced", Advanced.ToString());
                dict.Add("Solved", Solved.ToString());
                dict.Add("AllowedBlockTypes", String.Join(",", AllowedBlocks.Select <int, string>(i => i.ToString())));
                dict.Add("AdvEnvironment", ((int)Environment).ToString());
                dict.Add("AdvInputRate", InputDelay.ToString());
                dict.Add("AdvForceConstantInputRatio", ConstantInputRatio.ToString());
                dict.Add("AdvCreateInputTops", InputTops.ToString());
                dict.Add("AdvNoTopsForOneBlockInputs", NoOneBlockTops.ToString());
                dict.Add("Inputs", Blocks.ToBase64(Block.Roles.In));
                dict.Add("Outputs", Blocks.ToBase64(Block.Roles.Out));
                dict.Add("WorldBlocks", Blocks.ToBase64(Block.Roles.World));
                if (keyVals.ContainsKey("PreviewImage"))
                {
                    dict.Add("PreviewImage", BitmapToBase64(Preview, imgF));
                }
                if (keyVals.ContainsKey("AdvPreviewImage"))
                {
                    dict.Add("AdvPreviewImage", BitmapToBase64(Screenshot, imgF));
                }
                using (StreamWriter sr = new StreamWriter(Path, false))
                {
                    foreach (KeyValuePair <string, string> keyval in dict)
                    {
                        sr.WriteLine(keyval.Key + " = " + keyval.Value);
                    }
                }
            }
            catch
            {
                return(false);
            }
            Saved = true;
            return(true);
        }
Beispiel #8
0
        public void SolveAsync(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            List <List <HexPoint> > results = new List <List <HexPoint> >();
            int  moves = 1;
            bool done  = false;

            logMoves = false;
            while (!done)
            {
                logMoves      = true;
                possibleMoves = new int[moves];
                results       = Solve(engine.GetPossibleMoves(level.StartPos), level.Copy(), moves, new List <HexPoint>());

                if (results.Count > 0)
                {
                    List <List <HexPoint> > prevResults = results;

                    if (moves > 1)
                    {
                        moves--;
                        logMoves      = true;
                        possibleMoves = new int[moves];

                        results = Solve(engine.GetPossibleMoves(level.StartPos), level.Copy(), moves, new List <HexPoint>());

                        if (results.Count == 0)
                        {
                            results = prevResults;
                        }
                        done = true;
                    }
                }

                moves += 2;
                worker.ReportProgress(moves);
            }

            for (int i = 1; i < possibleMoves.Length; i++)
            {
                Console.WriteLine($"[LevelSolver]: Possible moves with {i} moves: {possibleMoves[possibleMoves.Length - i - 1]}");
            }

            MinMoves  = results.Min(x => x.Count);
            Solutions = results.Where(x => x.Count == MinMoves).ToList();
            worker.ReportProgress(100);
            Solved?.Invoke();
        }
Beispiel #9
0
        public void Solve()
        {
            List <List <HexPoint> > results = new List <List <HexPoint> >();
            int moves = 1;

            while (results.Count == 0)
            {
                results = Solve(engine.GetPossibleMoves(level.StartPos), level.Copy(), moves, new List <HexPoint>());
                moves++;
            }

            MinMoves  = results.Min(x => x.Count);
            Solutions = results.Where(x => x.Count == MinMoves).ToList();
            Solved?.Invoke();
        }
        public static void Emulate(State state, Solved solved)
        {
            if (solved.Buy != null)
            {
                state.BuyBoosters(solved.Buy.ToArray());
            }

            var ix = new List <int> {
                0
            };

            while (true)
            {
                var ixCount  = ix.Count;
                var anyActed = false;
                var actions  = new List <ActionBase>();
                for (var workerIndex = 0; workerIndex < ixCount; workerIndex++)
                {
                    var actionIndex = ix[workerIndex];
                    if (actionIndex >= solved.Actions[workerIndex].Count)
                    {
                        actions.Add(new Wait());
                        ix[workerIndex]++;
                        continue;
                    }
                    actions.Add(solved.Actions[workerIndex][actionIndex]);
                    ix[workerIndex]++;
                    anyActed = true;
                    if (solved.Actions[workerIndex][actionIndex] is UseCloning)
                    {
                        ix.Add(0);
                    }
                }

                if (!anyActed)
                {
                    break;
                }

                state.Apply(state.Workers.Select((w, i) => (w, actions[i])).ToList());
Beispiel #11
0
 /// <summary>
 /// Raises the <see cref="Solved"/> event.
 /// </summary>
 /// <param name="e"></param>
 /// <see cref="IOrProblemSolver.Solved"/>
 protected virtual void OnSolved(EventArgs e) => Solved?.Invoke(this, e);
 /// <summary>
 /// Raises the <see cref="Solved"/> event.
 /// </summary>
 /// <param name="e"></param>
 private void OnSolved(EventArgs e) => Solved?.Invoke(this, e);
Beispiel #13
0
 /// <summary>
 /// Called when the constraint is solved
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnSolved(ConstraintSolvedEventArgs <TOwner> e) => Solved?.Invoke(this, e);
 /// <summary>
 /// Raised the Solved <paramref name="e"/> event arguments.
 /// </summary>
 /// <param name="e"></param>
 protected void OnSolved(SolutionEventArgs e)
 {
     Solved?.Invoke(this, e);
 }
Beispiel #15
0
 private void OnSolved(ChangeMaker solution)
 => Solved?.Invoke(this, new ChangeMakerSolutionEventArgs(solution));
Beispiel #16
0
 private void OnSolved()
 {
     Solved?.Invoke(this, EventArgs.Empty);
 }