public void CanUseNegativePositions() { var map = new Map3D <float>(); map[-4, -4, -4] = 4.0f; Assert.That(Math.Abs(map[-4, -4, -4] - 4.0f) < 0.001); }
public void MapSerializer() { var map = new Map3D <float>(); map[0, 0, 0] = 1.0f; // Chunk: (0,0,0) map[16, 16, 16] = 2.0f; // Chunk: (1,1,1) map[32, 32, 32] = 4.0f; // Chunk: (2,2,2) var list = new List <ChunkSpace>(); map.RegisterWriter((xyz, tuple) => { Console.WriteLine("Writing: ({0},{1},{2})", xyz.X, xyz.Y, xyz.Z); list.Add(xyz); }); map.UnloadArea((0, 0, 0), (32, 32, 32)); Assert.AreEqual(3, list.Count); Assert.That(list.Contains(new ChunkSpace(0L, 0L, 0L))); Assert.That(list.Contains(new ChunkSpace(1L, 1L, 1L))); Assert.That(list.Contains(new ChunkSpace(2L, 2L, 2L))); map.UnregisterWriter(); map[48, 48, 48] = 4.0f; map.UnloadArea((0, 0, 0), (48, 48, 48)); Assert.AreEqual(3, list.Count); }
public void CanUseContains() { var map = new Map3D <float>(); map[1, 2, 1] = 4.0f; Assert.That(map.Contains(4.0f)); Assert.That(map.Contains(4.0f, new EqualityLambda <float>((a, b) => Math.Abs(a - b) < 0.001))); }
public void SparseCreation() { var map = new Map3D <float>(); map[-8, -8, -8] = 4.0f; map[-1024, -887, -900] = 8.0f; // With only two areas in memory, we only have (16*16*16)*2 blocks Assert.AreEqual(8192, map.Count); }
public void CanEnumerateRanges() { var map = new Map3D <float>(); map[1, 1, 1] = 4.0f; Assert.That(map.Within(new WorldSpace(0, 0, 0), new WorldSpace(2, 2, 2)).Any()); Assert.That(map.Within(new WorldSpace(0, 0, 0), new WorldSpace(2, 2, 2)) .Any(i => Math.Abs(i - 4.0f) < 0.001)); }
public override Maps.Map3DSurfaces GetMap3DSurfaces(Map3D map3D) { if (map3D is Museum) { return(Lob3DSurfaces.Archives); } else { return(Lob3DSurfaces.IslandCaverns); } }
public void CanAccessRandomly() { var map = new Map3D <float>(); map[-8, -8, -8] = 4.0f; map[-240, -778, -255] = 8.0f; map[8, 8, 8] = 16.0f; map[240, 778, 255] = 32.0f; Assert.That(Math.Abs(map[-240, -778, -255] - 8.0f) < 0.001); Assert.That(Math.Abs(map[240, 778, 255] - 32.0f) < 0.001); }
public void ThreeDimensionalTest() { _map3D = new Map3D(4, 4, 2); var pathFinder = new PathFinder <Tile>(_heuristic, 4 * 4 * 2, _map3D.IndexMap(), _map3D.Neighbours()); _map3D.Tiles[3, 3, 0].IsStairs = true; _map3D.Tiles[3, 3, 1].IsStairs = true; var path = pathFinder.Path(_map3D.Tiles[0, 0, 0], _map3D.Tiles[0, 0, 1]); Assert.AreEqual(13, path.Length); }
public void SupportsAddingEntities() { var map = new Map3D <float>(16, 16, 16); var oldBoot = new Entity { Name = "Old Boot" }; map.PutEntity(new WorldSpace(1, 1, 1), oldBoot); Assert.That(map.GetEntitiesAt(1, 1, 1).Any()); Assert.That(oldBoot.X == 1 && oldBoot.Y == 1); }
public void WhenImpossibleShouldReturnEmptyPath() { _map3D = new Map3D(4, 4, 1); var pathFinder = new PathFinder <Tile>(_heuristic, 4 * 4, _map3D.IndexMap(), _map3D.Neighbours()); _map3D.Tiles[0, 1, 0].IsBlocking = true; _map3D.Tiles[1, 0, 0].IsBlocking = true; var path = pathFinder.Path(_map3D.Tiles[0, 0, 0], _map3D.Tiles[3, 3, 0]); Assert.AreEqual(0, path.Length); }
public void SupportsUnloading() { var map = new Map3D <float>(); map[0, 0, 0] = 2.0f; map[16, 16, 16] = 2.0f; map[33, 33, 33] = 4.0f; Assert.AreEqual((16 * 16 * 16) * 3, map.Count); map.UnloadArea((0, 0, 0), (33, 33, 33)); Assert.AreEqual(0, map.Count); }
public Day17() { var input = File.ReadAllLines("Day17\\input.txt"); var xExpandsToMax = input[0].Length + (Cycles * 2); var yExpandsToMax = input.Length + (Cycles * 2); var zExpandsToMax = 1 + (Cycles * 2); var initialMap = ParseInitialMap(input, '#'); _mapPart1 = new Map3D <bool>(xExpandsToMax, yExpandsToMax, zExpandsToMax); _mapPart1.PlaceInMiddle(initialMap); _mapPart2 = new Map4D <bool>(xExpandsToMax, yExpandsToMax, zExpandsToMax, zExpandsToMax); _mapPart2.PlaceInMiddle(initialMap); }
public void SupportsUnloadingWithPersistance() { var map = new Map3D <float>(); map[0, 0, 0] = 2.0f; map[16, 16, 16] = 2.0f; map[33, 33, 33] = 4.0f; Assert.AreEqual((16 * 16 * 16) * 3, map.Count); map.MakePersistant((1, 1, 1)); map.UnloadArea((0, 0, 0), (33, 33, 33)); Assert.AreEqual((16 * 16 * 16), map.Count); }
public override Map3DSurfaces GetMap3DSurfaces(Map3D map) { if (map is Museum) { return(Lota3DSurfaces.Museum); } if (map.MapID == 71 || map.MapID == 73) { return(Lota3DSurfaces.DungeonBlue); } else { return(Lota3DSurfaces.DungeonBrown); } }
public void ProfilerTest() { for (var i = 0; i < 4; i++) { _map3D = new Map3D(20, 20, 1); var pathFinder = new PathFinder <Tile>(_heuristic, 20 * 20, _map3D.IndexMap(), _map3D.Neighbours()); var stopWatch = new Stopwatch(); stopWatch.Start(); for (var ii = 0; ii < 500; ii++) { pathFinder.Path(_map3D.Tiles[0, 0, 0], _map3D.Tiles[10, 19, 0]); } stopWatch.Stop(); Console.WriteLine(stopWatch.ElapsedMilliseconds); } }
public void SupportsQuantumEntanglementPrevention() { var map = new Map3D <float>(16, 16, 16); var oldBoot = new Entity { Name = "Old Boot" }; map.PutEntity(new WorldSpace(1, 1, 1), oldBoot); Assert.That(map.GetEntitiesAt(1, 1, 1).Any()); Assert.That(oldBoot.X == 1 && oldBoot.Y == 1); // Put the boot somewhere else, moving it. map.PutEntity(new WorldSpace(17, 17, 17), oldBoot); oldBoot.Name = "Spooky Old Boot"; Assert.That(map.GetEntitiesAt(1, 1, 1).Any() == false); Assert.That(map.GetEntitiesAt(17, 17, 17).Any()); }
public void SupportsAddingAndRemovingEntities() { var map = new Map3D <float>(16, 16, 16); var oldBoot = new Entity { Name = "Old Boot" }; map.PutEntity(new WorldSpace(1, 1, 1), oldBoot); Assert.That(map.GetEntitiesAt(1, 1, 1).Any()); Assert.That(oldBoot.X == 1 && oldBoot.Y == 1); map.RemoveEntity(oldBoot); Assert.That(map.GetEntitiesAt(1, 1, 1).Any() == false); // After removing, items have null coordinates. Assert.That(oldBoot.X == null); Assert.That(oldBoot.Y == null); Assert.That(oldBoot.Z == null); }
public void SupportsUnloadingOutsideArea() { var map = new Map3D <float>(16, 16, 16); { map[4, 4, 0] = 2.0f; map[63, 63, 0] = 4.0f; // Two chunks loaded Assert.AreEqual((16 * 16 * 16) * 2, map.Count); var begin = new WorldSpace(0, 0, 0); var end = new WorldSpace(15, 15, 0); map.UnloadAreaOutside(begin, end); // Ony one chunk left Assert.AreEqual((16 * 16 * 16), map.Count); } // Non-zero test { map[0, 0, 0] = 2.0f; map[16, 16, 0] = 2.0f; map[32, 32, 0] = 4.0f; map[48, 48, 7] = 8.0f; map[64, 64, 15] = 16.0f; map[80, 80, 15] = 32.0f; map[96, 96, 0] = 64.0f; map[128, 128, 0] = 128.0f; Assert.AreEqual((16 * 16 * 16) * 8, map.Count); var begin = new WorldSpace(48, 48, 0); var end = new WorldSpace(80, 80, 15); map.UnloadAreaOutside(begin, end); Assert.AreEqual((16 * 16 * 16) * 3, map.Count); } }
public void CanInsertItems() { var mapStruct = new Map3D <StructItem>(); mapStruct[4, 4, 4] = new StructItem() { ItemId = 4 }; Assert.That(mapStruct[4, 4, 4].ItemId == 4); var mapPrim = new Map3D <float>(); mapPrim[4, 4, 4] = 4.0f; Assert.That(Math.Abs(mapPrim[4, 4, 4] - 4.0f) < 0.001); var mapClass = new Map3D <ClassItem>(); mapClass[4, 4, 4] = new ClassItem() { ItemId = 4 }; Assert.That(mapClass[4, 4, 4].ItemId == 4); }
public void SupportsGettingEntitiesInLocalArea() { var map = new Map3D <float>(16, 16, 16); var oldBoot = new Entity { Name = "Old Boot" }; var oldCan = new Entity { Name = "Old Boot" }; var oldBucket = new Entity { Name = "Old Boot" }; map.PutEntity(new WorldSpace(1, 1, 1), oldBoot); map.PutEntity(new WorldSpace(1, 1, 1), oldBucket); map.PutEntity(new WorldSpace(1, 1, 1), oldCan); Assert.That(map.GetEntitiesAt(1, 1, 1).Any()); Assert.That(oldBoot.X == 1 && oldBoot.Y == 1); Assert.That(map.GetEntitiesInChunk(new WorldSpace(0, 0, 0)).Count() == 3); }
public void MapDeserializer() { var map = new Map3D <float>(); int i = 0; // Assert that the Reader function is called for each new chunk loaded into memory map.RegisterReader(tuple => { i++; return(new Chunk <float>(16, 16, 16)); }); map[0, 0, 0] = 1.0f; // Chunk: (0,0,0) map[16, 16, 16] = 2.0f; // Chunk: (1,1,1) map[32, 32, 32] = 4.0f; // Chunk: (2,2,2) Assert.AreEqual(3, i); map.UnregisterReader(); map[48, 48, 48] = 8.0f; // Assert that after unregistering, the callback is not invoked. Assert.AreEqual(3, i); }
public void IsCubic() { var map = new Map3D <float>(); // 'Ground Level' map[1, 1, 1] = 1.0f; // 'Cloud Level' map[1, 1, 64] = 64.0f; // 'Atmosphere' map[1, 1, 128] = 128.0f; // Spaaaace map[1, 1, 256] = 256.0f; // Dad, are we space now? map[1, 1, 2048] = 2048.0f; // No son, we are Aldebaran. map[1, 1, Int64.MaxValue] = 8192.0f; Assert.AreEqual(((16 * 16 * 16) * 6), map.Count); }
protected Map3DTestBase(IntSize3 size) { m_map = new Map3D(size); }
protected Map3DTestBase(IntSize3 size) { m_map = new Map3D(size); }
public abstract Maps.Map3DSurfaces GetMap3DSurfaces(Map3D map3D);
public void ChunkGathering() { var map = new Map3D <float>(16, 16, 16); map[1, 1, 1] = 2.0f; map[1, 1, 17] = 4.0f; map[1, 1, 33] = 8.0f; // Assert we have 3 chunks in memory. Assert.AreEqual((16 * 16 * 16) * 3, map.Count); // A single chunk at the bottom of the stack { var begin = new WorldSpace(0, 0, 0); var end = new WorldSpace(15, 15, 15); var chunksFound = map.ChunksWithin(begin, end, createIfNull: false).ToList(); Assert.AreEqual(1, chunksFound.Count()); Assert.AreEqual(0, chunksFound.Select(s => s.Item1.Z).First()); // Assert that it is the correct chunk Assert.That(chunksFound.ElementAt(0).Item2.Contains(2.0f)); } // All three chunks stacked on top of each other { var begin = new WorldSpace(0, 0, 0); var end = new WorldSpace(15, 15, 33); var chunksFound = map.ChunksWithin(begin, end, createIfNull: false).ToList(); Assert.AreEqual(3, chunksFound.Count()); IEnumerable <long> zSequences = new List <long> { 0, 1, 2 }; var chunks = chunksFound.Select(chunk => chunk.Item1.Z).OrderBy(s => s).AsEnumerable(); Assert.AreEqual(3, chunks.Union(zSequences).Count()); // Assert we have the actual chunks Assert.That(chunksFound.ElementAt(0).Item2.Contains(2.0f)); Assert.That(chunksFound.ElementAt(1).Item2.Contains(4.0f)); Assert.That(chunksFound.ElementAt(2).Item2.Contains(8.0f)); } // The two top most stacks { var begin = new WorldSpace(0, 0, 16); var end = new WorldSpace(15, 15, 33); var chunksFound = map.ChunksWithin(begin, end, createIfNull: false).ToList(); Assert.AreEqual(2, chunksFound.Count()); // Assert that we got back the right chunks in terms of Z level startings var zSequences = new List <long> { 1, 2 }; var chunks = chunksFound.Select(chunk => chunk.Item1.Z).OrderBy(s => s); Assert.AreEqual(2, chunks.Union(zSequences).Count()); // Assert we have the actual chunks. Assert.That(chunksFound.ElementAt(0).Item2.Contains(4.0f)); Assert.That(chunksFound.ElementAt(1).Item2.Contains(8.0f)); } }