public static void Main(string[] args) { var src = MatrixDeserializer.Deserialize(File.ReadAllBytes(@"..\..\..\data\problemsF\FR001_src.mdl")); var tgt = MatrixDeserializer.Deserialize(File.ReadAllBytes(@"..\..\..\data\problemsF\FR001_tgt.mdl")); var mongoOplogWriter = new JsonOpLogWriter(new MongoJsonWriter()); mongoOplogWriter.WriteLogName("ComponentFinder"); var state = State.CreateInitial(src.R, mongoOplogWriter); mongoOplogWriter.WriteInitialState(state); var rand = new Random(); foreach (var comp in new ComponentFinder(src ^ tgt, tgt).Find()) { if (comp.Fill) { var color = new[] { "00FF00", "FF0000", "0000FF", "FFFF00" }[rand.Next(3)]; mongoOplogWriter.WriteGroupColor(comp.Points.ToArray(), color, 0.8); } } mongoOplogWriter.Save(); }
// = new FakeSolver(); //= new JenyaRomaSolver(new FakeOpLog()); static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, a) => { Console.Error.WriteLine("Unhandled exception: " + a.ExceptionObject); Environment.Exit(31337); }; var srcPath = args.SingleOrDefault(a => a.StartsWith("--src="))?.Substring(6); var tgtPath = args.SingleOrDefault(a => a.StartsWith("--tgt="))?.Substring(6); var tracePath = args.Single(a => a.StartsWith("--trace=")).Substring(8); var tgtMatrix = tgtPath == null ? null : MatrixDeserializer.Deserialize(File.ReadAllBytes(tgtPath)); var srcMatrix = srcPath == null ? null : MatrixDeserializer.Deserialize(File.ReadAllBytes(srcPath)); var trace = Solver.Solve(srcMatrix, tgtMatrix); if (trace == null) { return; } var traceBytes = TraceBinarySerializer.Create().Serialize(trace); File.WriteAllBytes(tracePath, traceBytes); }
public static void Visualize(string modelPath, string name = null) { var resultMatrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(modelPath)); name = name ?? Path.GetFileNameWithoutExtension(modelPath); Visualize(resultMatrix, name); }
public static void Main(string[] args) { var modelFilePath = @"\\vm-dev-cont1\c$\data\problemsF\FA019_tgt.mdl"; var mongoOplogWriter = new JsonOpLogWriter(new MongoJsonWriter()); var jenyaRomaSolver = new JenyaRomaSolver(mongoOplogWriter); var tgtMatrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(modelFilePath)); var trace = jenyaRomaSolver.Solve(srcMatrix: null, tgtMatrix: tgtMatrix); var traceBytes = TraceBinarySerializer.Create().Serialize(trace); File.WriteAllBytes(@"FA019.nbt", traceBytes); }
public static void Test() { var modelFilePath = @"..\..\..\data\models\LA020_tgt.mdl"; var matrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(modelFilePath)); var mongoOplogWriter = new JsonOpLogWriter(new MongoJsonWriter()); mongoOplogWriter.WriteLogName("GreedyGravityAI_IsGrounded"); var state = State.CreateInitial(matrix.R, mongoOplogWriter); mongoOplogWriter.WriteInitialState(state); var groundedChecker = new IsGroundedChecker(matrix); var vertexex = new List <Vector>(); for (int y = 0; y < matrix.R; y++) { for (int x = 0; x < matrix.R; x++) { for (int z = 0; z < matrix.R; z++) { var vector = new Vector(x, y, z); if (matrix.IsVoid(vector)) { continue; } vertexex.Add(vector); } } } var rand = new Random(); vertexex = vertexex.OrderBy(_ => rand.NextDouble()).ToList(); foreach (var vector in vertexex) { if (groundedChecker.CanRemove(vector)) { groundedChecker.UpdateWithClear(vector); continue; } mongoOplogWriter.WriteFill(vector); } mongoOplogWriter.Save(); }
private long GetActualEnergy(string tracePath, string anyModelPath) { var fileAi = new FileAI(tracePath); var matrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(anyModelPath)); var state = State.CreateInitial(matrix.R); while (true) { var commands = fileAi.NextStep(state).ToList(); simulator.NextStep(state, new Trace(commands)); if (commands.Count == 1 && commands[0] is HaltCommand) { break; } } return(state.Energy); }
public static void SearchTest() { //var trackFilePath = @"..\..\..\data\track\LA001.nbt"; var modelFilePath = @"..\..\..\data\models\LA180_tgt.mdl"; var matrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(modelFilePath)); //var ai = new GreedyGravityAI(matrix); Console.WriteLine("matrix loaded"); var mongoOplogWriter = new JsonOpLogWriter(new MongoJsonWriter()); mongoOplogWriter.WriteLogName("GreedyGravityAI_IsGrounded"); var state = State.CreateInitial(matrix.R, mongoOplogWriter); mongoOplogWriter.WriteInitialState(state); var groundedChecker = new IsGroundedChecker(matrix); var startPosition = new Vector(0, 0, 0); for (int i = 0; i < matrix.R; i++) { for (int j = 0; j < matrix.R; j++) { for (int k = 0; k < matrix.R; k++) { var vector = new Vector(i, j, k); if (matrix.IsVoid(vector)) { continue; } mongoOplogWriter.WriteColor(vector, "0000FF", 0.5); } } } Console.WriteLine("matrix inited"); var rand = new Random(15); var forbidden = new HashSet <Vector>(); Console.WriteLine("start"); for (int i = 0; i < 1002; i++) { var endPosition = new Vector(rand.Next(matrix.R), rand.Next(matrix.R), rand.Next(matrix.R)); while (forbidden.Contains(endPosition) || matrix.IsFull(endPosition)) { endPosition = new Vector(rand.Next(matrix.R), rand.Next(matrix.R), rand.Next(matrix.R)); } mongoOplogWriter.WriteColor(endPosition, "00FF00", 1); DateTime d = DateTime.UtcNow; var pathBuilder = new BotMoveSearcher(matrix, state.Matrix, startPosition, vector => forbidden.Contains(vector), 39, endPosition, groundedChecker); pathBuilder.FindPath(out var movePath, out var commands, out var iterations); if (movePath == null) { break; } Console.WriteLine($"{commands.Count}: {d - DateTime.UtcNow} - {iterations}"); movePath.ForEach(c => forbidden.Add(c)); foreach (var vector in movePath) { mongoOplogWriter.WriteFill(vector); } mongoOplogWriter.WriteColor(endPosition, "0000FF", 1); startPosition = endPosition; } mongoOplogWriter.Save(); }
public static void Main(string[] args) { var srcModelPath = @"..\..\..\data\problemsF\FR002_src.mdl"; var tgtModelPath = @"..\..\..\data\problemsF\FR002_tgt.mdl"; var sourceMatrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(srcModelPath)); var targetMatrix = MatrixDeserializer.Deserialize(File.ReadAllBytes(tgtModelPath)); // sourceMatrix = new Matrix(targetMatrix.R); var mongoOplogWriter = new JsonOpLogWriter(new MongoJsonWriter()); mongoOplogWriter.WriteLogName("FigureDecomposer"); var state = State.CreateInitial(sourceMatrix.R, mongoOplogWriter); mongoOplogWriter.WriteInitialState(state); var tasks = new FigureDecomposer(targetMatrix, sourceMatrix).Decompose(); var fillPoints = new List <Vector>(); var voidPoints = new List <Vector>(); var rand = new Random(); foreach (var task in tasks) { if (task.Type == BuildingTaskType.GFill || task.Type == BuildingTaskType.GVoid) { var points = new List <Vector>(); for (var x = task.Region.Min.X; x <= task.Region.Max.X; x++) { for (var y = task.Region.Min.Y; y <= task.Region.Max.Y; y++) { for (var z = task.Region.Min.Z; z <= task.Region.Max.Z; z++) { points.Add(new Vector(x, y, z)); } } } var fill = task.Type == BuildingTaskType.GFill; mongoOplogWriter.WriteGroupColor(points.ToArray(), fill ? $"00FF{rand.Next(10, 99)}" : $"FF00{rand.Next(10, 99)}", fill ? 0.8 : 0.5); } else if (task.Type == BuildingTaskType.Fill || task.Type == BuildingTaskType.Void) { if (task.Type == BuildingTaskType.Fill) { fillPoints.Add(task.Region.Min); } else { voidPoints.Add(task.Region.Min); } } } mongoOplogWriter.WriteGroupColor(fillPoints.ToArray(), "0000FF", 0.8); mongoOplogWriter.WriteGroupColor(voidPoints.ToArray(), "FFFF00", 0.5); mongoOplogWriter.Save(); Console.WriteLine("Saved to MongoDB"); Console.ReadLine(); }