public static Dictionary <RegionWithEquipment, AStar.Node> CreateNodes(Dictionary <Point, GeographicalRegion> geographicalRegions, RegionWithEquipment target) { var nodeId = 1; var equipmentSet = Enum.GetValues(typeof(Equipment)); var nodeMap = new Dictionary <RegionWithEquipment, AStar.Node>(); foreach (var geographicalRegion in geographicalRegions) { foreach (Equipment equipment in equipmentSet) { var regionWithEquipment = new RegionWithEquipment(geographicalRegion.Value, equipment); var node = new AStar.Node(nodeId++, regionWithEquipment.Location.ManhattanDistance(target.Location), regionWithEquipment.ToString()); nodeMap.Add(regionWithEquipment, node); } } foreach (var regionNode in nodeMap) { var regionWithEquipment = regionNode.Key; var node = regionNode.Value; var neighbors = regionWithEquipment.Neighbors(geographicalRegions); node.Neighbors = neighbors .Select(n => new AStar.Neighbor(nodeMap[n], regionWithEquipment.DistanceTo(n))) .ToList(); } return(nodeMap); }
public static int FewestMinutesToTarget(int depth, Point targetLocation) { var geographicalRegions = CalculateGeology(depth, targetLocation); var start = new RegionWithEquipment(geographicalRegions[new Point(0, 0)], Equipment.Torch); var target = new RegionWithEquipment(geographicalRegions[targetLocation], Equipment.Torch); var nodeMap = CreateNodes(geographicalRegions, target); var startNode = nodeMap[start]; var targetNode = nodeMap[target]; var terminationNode = AStar.Search(startNode, targetNode); return(terminationNode.MovementCost); }
public List <RegionWithEquipment> Neighbors(Dictionary <Point, GeographicalRegion> geographicalRegions) { var adjacent = Region.Location.AdjacentInMainDirections(); var neighbors = new List <RegionWithEquipment>(); foreach (var neighborLocation in adjacent.Where(geographicalRegions.ContainsKey)) { var neighborRegion = geographicalRegions[neighborLocation]; foreach (Equipment equipment in Enum.GetValues(typeof(Equipment))) { if (EquipmentValidFor(equipment, Region.GeologicalType) && EquipmentValidFor(equipment, neighborRegion.GeologicalType)) { var neighbor = new RegionWithEquipment(neighborRegion, equipment); neighbors.Add(neighbor); } } } return(neighbors); }
protected bool Equals(RegionWithEquipment other) { return(Equipment == other.Equipment && Region.Location == other.Region.Location); }
public int DistanceTo(RegionWithEquipment other) { return(Equipment == other.Equipment ? 1 : 8); }