void CheckBasic(IBitmap b) { b[1, 1] = true; b[2, 2] = false; Assert.True(b[1, 1]); Assert.False(b[2, 2]); Assert.True(b[new VectorInt2(1, 1)]); Assert.False(b[new VectorInt2(2, 2)]); Assert.Equal(1, b.Count()); var asList = b.ForEach().ToList(); Assert.Contains((new VectorInt2(1, 1), true), asList); Assert.Contains((new VectorInt2(2, 2), false), asList); var hash = b.GetHashCode(); Assert.NotEqual(0, hash); var clone = new Bitmap(b); Assert.Equal(b, clone); Assert.True(b.Equals(clone)); Assert.Equal(0, b.CompareTo(clone)); Assert.Equal(b, b.BitwiseOR(b)); Assert.Equal(b, b.BitwiseAND(b)); Assert.True(b.SizeInBytes() > 0); }
public static Path ConvertForwardNodeToPath(SolverNode node, IBitmap walls) { var pathToRoot = node.PathToRoot(); var offset = GeneralHelper.OffsetWalk(pathToRoot); var r = new Path(); foreach (var pair in offset) { var boundry = walls.BitwiseOR(pair.Item1.CrateMap); var start = pair.Item1.PlayerAfter; var end = pair.Item2.PlayerBefore; var walk = PathFinder.Find(boundry, start, end); if (walk == null) { throw new Exception("bad Path\n"); // Not solution } r.AddRange(walk); r.Add(pair.Item2.PlayerAfter - pair.Item2.PlayerBefore); } return(r); }
public static Path ConvertReverseNodeToPath(SolverNode node, IBitmap walls) { var pathToRoot = node.PathToRoot(); pathToRoot.Reverse(); pathToRoot.RemoveAt(pathToRoot.Count - 1); var offset = GeneralHelper.OffsetWalk(pathToRoot); var r = new Path(); var cc = 0; foreach (var pair in offset) { r.Add(pair.Item1.PlayerBefore - pair.Item1.PlayerAfter); var boundry = walls.BitwiseOR(pair.Item2.CrateMap); var start = pair.Item1.PlayerBefore; var end = pair.Item2.PlayerAfter; var walk = PathFinder.Find(boundry, start, end); if (walk == null) { throw new Exception(string.Format("Bad Path at {0}, path={1}", cc, r)); // Not solution } r.AddRange(walk); cc++; } if (pathToRoot.Count > 1) { var last = pathToRoot[pathToRoot.Count - 1]; r.Add(last.CrateBefore - last.CrateAfter); } return(r); }
public static Path ConvertSolutionNodeToPath(SolverNode node, IBitmap walls, Puzzle puzzle) { if (node.Evaluator.GetType() == typeof(ReverseEvaluator)) { var pathToRoot = node.PathToRoot(); pathToRoot.Reverse(); var offset = GeneralHelper.OffsetWalk(pathToRoot).ToList(); var r = new Path(); var cc = 0; // PuzzleStart to First Push var b = walls.BitwiseOR(puzzle.ToMap(puzzle.Definition.AllCrates)); var f = puzzle.Player.Position; var t = pathToRoot[0].PlayerAfter; var first = PathFinder.Find(b, f, t); if (first == null) { //throw new Exception(string.Format("Bad Path at INIT. {0} => {1}. This is an indicator or a FALSE positive. Ie. An invalid start position.\n{2}", f, t, b)); // Not solution return(null); } r.AddRange(first); foreach (var pair in offset) { if (pair.Item2.Parent == null) { break; } r.Add(pair.Item1.PlayerBefore - pair.Item1.PlayerAfter); var boundry = walls.BitwiseOR(pair.Item2.CrateMap); var start = pair.Item1.PlayerBefore; var end = pair.Item2.PlayerAfter; var walk = PathFinder.Find(boundry, start, end); if (walk == null) { throw new Exception($"Bad Path at step {cc}\n"); // Not solution } r.AddRange(walk); //Console.WriteLine("PAIR: {0}", cc); //Console.WriteLine("{0} => {1}", pair.Item1.PlayerBefore, pair.Item1.PlayerAfter); //Console.WriteLine(pair.Item1.ToStringDebug()); //Console.WriteLine("{0} => {1}", pair.Item2.PlayerBefore, pair.Item2.PlayerAfter); //Console.WriteLine(pair.Item2.ToStringDebug()); //var debug = boundry.ToCharMap(); //debug[start] = 'S'; //debug[end] = 'E'; //var d = debug.ToString(); //Console.WriteLine(d); //Console.WriteLine(r); cc++; } if (pathToRoot.Count > 1) { var last = pathToRoot[pathToRoot.Count - 2]; r.Add(last.PlayerBefore - last.PlayerAfter); } return(r); } return(ConvertForwardNodeToPath(node, walls)); }