Esempio n. 1
0
        private static void ActualMain(string[] args)
        {
            if (args.Length != 3)
            {
                throw new CommandLineException(
                          $"Usage: {GetProgramName()} YOUR_NBT SOURCE_MDL TARGET_MDL");
            }

            Matrix source = null;
            Matrix target = null;

            if (args[1] != "-")
            {
                source = ModelFile.Load(args[1]);
            }
            if (args[2] != "-")
            {
                target = ModelFile.Load(args[2]);
            }
            if (source == null)
            {
                source = Matrix.Empty(target.R);
            }
            if (target == null)
            {
                target = Matrix.Empty(source.R);
            }

            var commands = new List <Command>();
            var state    = new State(source);

            state.DoesAutoVerify = source.R <= MaxVerifyR;

            foreach (Command c in TraceFile.Load(args[0]))
            {
                commands.Add(c);
                if (commands.Count == state.Bots.Count)
                {
                    state.DoTurn(commands);
                    commands.Clear();
                }
            }

            if (!Matrix.AreEqual(state.Matrix, target))
            {
                throw new InvalidOperationException("Matrix does not match the target.");
            }
            if (state.Bots.Count > 0)
            {
                throw new InvalidOperationException("System has not been halted.");
            }

            Console.WriteLine(state.Energy);
        }
Esempio n. 2
0
 private static void Encode(string sourceFile, string outputFile)
 {
     using (var source = OpenSourceReader(sourceFile))
     using (var output = OpenOutputStream(outputFile))
         TraceFile.Save(output, TraceFile.LoadText(source));
 }
Esempio n. 3
0
 private static void Decode(string sourceFile, string outputFile)
 {
     using (var source = OpenSourceStream(sourceFile))
     using (var output = OpenOutputWriter(outputFile))
         TraceFile.SaveText(output, TraceFile.Load(source));
 }
Esempio n. 4
0
 public void SaveToNbt(string filename)
 => TraceFile.Save(filename, mTrace);