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(); }
public Dictionary <int, Vector> DoWork(IsGroundedChecker groundedChecker, Func <Vector, bool> isForbidden, out List <ICommand> commands, out List <Vector> volatiles) { if (figure.Where(isForbidden).Any()) { throw new ArgumentException("`figure` should not intersect `prohibited`"); } if (!figure.Contains(start)) { throw new ArgumentException("`figure` should contain `start`"); } var gravity = CalcGravity(figure, start); Console.WriteLine("figure.Count = {0}", figure.Count); Console.WriteLine("gravity.Count = {0}", gravity.Count); var voided = new HashSet <Vector> { start }; if (matrix.IsFull(start)) { groundedChecker.UpdateWithClear(start); } var curPoint = start; volatiles = new List <Vector>(); commands = new List <ICommand>(); while (voided.Count < figure.Count) { var nextPoint = curPoint.GetAdjacents() .Where(p => figure.Contains(p) && !voided.Contains(p)) .Where(groundedChecker.CanRemove) .OrderByDescending(f => f.GetAdjacents().Count(f1 => matrix.Contains(f1) && matrix.IsFull(f1) && !voided.Contains(f1)) == 1) .ThenByDescending(p => gravity[p]) .FirstOrDefault(); List <Vector> curPath; List <ICommand> curCommands; if (nextPoint == null) { break; } MoveStraight(curPoint, nextPoint, out curPath, out curCommands); foreach (var vector in curPath.Where(vector => voided.Contains(vector))) { mongoOplogWriter?.WriteColor(vector, "FFFF00", 0.5); } voided.Add(nextPoint); groundedChecker.UpdateWithClear(nextPoint); commands.AddRange(curCommands); volatiles.AddRange(curPath); curPoint = nextPoint; } foreach (var vector in commands.OfType <VoidCommand>().Select(c => c.RealVoid).Reverse()) { groundedChecker.UpdateWithFill(vector); } return(new Dictionary <int, Vector> { { BotId, curPoint } }); }