public void TestOnSamleTraces(string commandFilename, string problemFilename)
        {
            var content  = File.ReadAllBytes(commandFilename);
            var commands = CommandSerializer.Load(content);
            var state    = new DeluxeState(null, Matrix.Load(File.ReadAllBytes(problemFilename)));

            new Interpreter(state).Run(commands);
        }
        public void TestOnSamleTraces([ValueSource(nameof(GetModels))] string filename)
        {
            var content    = File.ReadAllBytes(filename);
            var commands   = CommandSerializer.Load(content);
            var newContent = CommandSerializer.Save(commands);

            Assert.AreEqual(content, newContent);
        }
        public TraceResult Trace(string file, int startTick = 0, int count = 2000)
        {
            var problemName = file.Split("-")[0];
            var problem     = ProblemSolutionFactory.CreateProblem($"../data/problemsF/{problemName}_tgt.mdl");
            var solution    = CommandSerializer.Load(System.IO.File.ReadAllBytes($"../data/solutions/{problemName}.nbt"));

            var state        = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix);
            var queue        = new Queue <ICommand>(solution);
            var results      = new List <TickResult>();
            var filledVoxels = new HashSet <Vec>(state.GetFilledVoxels());
            var tickIndex    = 0;

            try
            {
                var newFilledVoxels  = new List <Vec>(state.GetFilledVoxels());
                var newClearedVoxels = new List <Vec>();
                var interpreter      = new Interpreter(state);
                while (queue.Any() && tickIndex < startTick + count)
                {
                    interpreter.Tick(queue);

                    foreach (var vec in interpreter.LastChangedCells)
                    {
                        if (state.Matrix[vec])
                        {
                            if (!filledVoxels.Contains(vec))
                            {
                                newFilledVoxels.Add(vec);
                                filledVoxels.Add(vec);
                            }
                        }
                        else if (filledVoxels.Contains(vec))
                        {
                            newClearedVoxels.Add(vec);
                            filledVoxels.Remove(vec);
                        }
                    }
                    if (tickIndex >= startTick)
                    {
                        results.Add(new TickResult
                        {
                            filled  = newFilledVoxels.Select(v => new[] { v.X, v.Y, v.Z }).ToArray(),
                            cleared = newClearedVoxels.Select(v => new[] { v.X, v.Y, v.Z }).ToArray(),
                            bots    = state.Bots
                                      .Select(x => new[] { x.Position.X, x.Position.Y, x.Position.Z })
                                      .ToArray(),
                            tickIndex = tickIndex
                        });
                        newFilledVoxels.Clear();
                    }
                    tickIndex++;
                }
            }
            catch (Exception e)
            {
                var arr = results.ToArray();
                return(new TraceResult
                {
                    Exception = e.ToString(),
                    R = problem.R,
                    startTick = startTick,
                    totalTicks = arr.Length - 1,
                    Ticks = arr
                });
            }

            var ticks = results.ToArray();

            return(new TraceResult
            {
                R = problem.R,
                startTick = startTick,
                totalTicks = ticks.Length - 1,
                Ticks = ticks
            });
        }