public List <int> Solve() { openSet.Add(start, 0); int testerino = openSet.Count; while (openSet.Count != 0 && !closedSet.Contains(goal)) { current = openSet.First().Key; openSet.Remove(current); closedSet.Add(current); currentNeighbours = aStarHelper.GetNeighbours(current); float distance; foreach (int neighbour in currentNeighbours) { if (!closedSet.Contains(neighbour)) { if (!openSet.ContainsKey(neighbour)) { dungeon.Get(neighbour).pathfindingParentID = current; distance = (float)Distance(dungeon.Get(neighbour).GetCenter(), dungeon.Get(goal).GetCenter()); openSet.Add(neighbour, distance); openSet.OrderBy(x => x.Value); } } } } if (!closedSet.Contains(goal)) { return(null); } path = closedSet; return(path); }
/** * Randomly chooses a {@link MZRoom} within the given collection that has at * least one adjacent empty space. * * @param roomCollection the collection of rooms to choose from * @return the room that was chosen, or null if there are no rooms with * adjacent empty spaces */ protected MZRoom ChooseRoomWithFreeEdge(List <MZRoom> roomCollection, int keyLevel) { List <MZRoom> rooms = new List <MZRoom>(roomCollection); Shuffle(rooms); for (int i = 0; i < rooms.Count; ++i) { MZRoom room = rooms[i]; foreach (KeyValuePair <Double, int> next in constraints.GetAdjacentRooms(room.id, keyLevel)) { if (dungeon.Get(next.Value) == null) { return(room); } } } return(null); }
public List <int> GetNeighbours(int roomId) { List <int> ids = new List <int>(); foreach (MZEdge edge in dungeon.Get(roomId).GetEdges()) { if (!edge.HasSymbol() || edge.GetSymbol().GetValue() < keyLevel) { ids.Add(edge.GetTargetRoomId()); } } return(ids); }