public void update_neighbours() { //ARRANGE GameObject hexGO = new GameObject(); GameObject gameObject = new GameObject(); MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>(); mapGeneration.HexagonPrefab = hexGO; mapGeneration.MapRadius = 10; //generate map mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>(); mapGeneration.GenerateMap(); mapGeneration.UpdateHexNeighbours(); mapGeneration.ConnectContentsToHex(); //get random hex Vector3Int coords = new Vector3Int(-3, 2, 1); IHexagon hex = (IHexagon)mapGeneration.HexDict[coords]; //manually calculate its neighbours List <Vector3Int> directions = mapGeneration.GetDirections(); List <IHexagon> neighbours = new List <IHexagon>(); foreach (Vector3Int direction in directions) { neighbours.Add(mapGeneration.HexDict[coords + direction]); } //ASSERT Assert.AreEqual(neighbours, hex.MyHexMap.Neighbours); }
public void pathfinding() { GameObject gameObject = new GameObject(); MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>(); mapGeneration.HexagonPrefab = new GameObject(); mapGeneration.MapRadius = 10; mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>(); mapGeneration.GenerateMap(); mapGeneration.UpdateHexNeighbours(); mapGeneration.ConnectContentsToHex(); IHexagon start_hex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)]; IHexagon end_hex = mapGeneration.HexDict[new Vector3Int(0, -4, 4)]; MapPathfinding mapPathfinding = new MapPathfinding(); MapPath path = mapPathfinding.GeneratePath(start_hex, end_hex); MapPath arbitrary_path = new MapPath(); for (int i = 4; i >= 0; i--) { arbitrary_path.PathStack.Push(mapGeneration.HexDict[new Vector3Int(0, -i, i)]); } arbitrary_path.cost = 4; Assert.AreEqual(arbitrary_path.PathStack, path.PathStack); Assert.AreEqual(arbitrary_path.cost, path.cost); }
public void hexes_in_range() { GameObject gameObject = new GameObject(); MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>(); mapGeneration.HexagonPrefab = new GameObject(); mapGeneration.MapRadius = 10; mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>(); mapGeneration.GenerateMap(); mapGeneration.UpdateHexNeighbours(); mapGeneration.ConnectContentsToHex(); IHexagon startHex = mapGeneration.HexDict[new Vector3Int(0, 0, 0)]; MapPathfinding mapPathfinding = new MapPathfinding(); HashSet <IHexagon> hexesInRange = mapPathfinding.GetHexesInRange(startHex, 1); HashSet <IHexagon> neighboursAndStart = startHex.MyHexMap.Neighbours; neighboursAndStart.Add(startHex); foreach (IHexagon neighbour in startHex.MyHexMap.Neighbours) { Assert.IsTrue(hexesInRange.Contains(neighbour)); } foreach (IHexagon hex in hexesInRange) { Assert.IsTrue(neighboursAndStart.Contains(hex)); } }
public void hex_content_links_to_hex() { GameObject gameObject = new GameObject(); MapGeneration mapGeneration = gameObject.AddComponent <MapGeneration>(); GameObject character = new GameObject(); character.transform.position = new Vector3(5, 0, 3); character.AddComponent <IContentMarker>(); ObjectHexContent moveableCharacter = character.AddComponent <ObjectHexContent>(); mapGeneration.MapRadius = 10; mapGeneration.HexagonPrefab = new GameObject(); mapGeneration.HexDict = new Dictionary <Vector3Int, IHexagon>(); mapGeneration.GenerateMap(); mapGeneration.UpdateHexNeighbours(); mapGeneration.ConnectContentsToHex(); Assert.AreEqual(mapGeneration.HexDict[new Vector3Int(7, 0, -7)], moveableCharacter.Location); }