private void MoveDroidToSecurityCheckpoint(Droid droid, ShipGraph shipGraph) { var(path, _) = GraphSearch.Dijkstra(shipGraph, droid.Room, "== Security Checkpoint =="); foreach (var nextRoom in path) { droid.TakeDoor((Direction)shipGraph.GetDoorDirection(droid.Room, nextRoom)); } }
private ShipGraph ExploreAndTakeItems(Droid droid) { var shipGraph = new ShipGraph(); shipGraph.AddRoom(droid); var unexploredRooms = new HashSet <string> { droid.Room }; var path = new List <Direction>(); while (unexploredRooms.Any()) { var lastRoom = droid.Room; if (unexploredRooms.Contains(droid.Room)) { droid.TakeItems(droid.FloorItems.Except(blacklistItems)); foreach (var door in shipGraph.GetUnexploredDoorsOf(droid.Room)) { droid.TakeDoor(door); if (droid.Room != lastRoom) { if (!shipGraph.ContainsNode(droid.Room)) { shipGraph.AddRoom(droid); unexploredRooms.Add(droid.Room); } shipGraph.AddDoorKnowledge(lastRoom, droid.Room, door); droid.TakeDoor(door.Opposite()); } } unexploredRooms.Remove(lastRoom); } else { var neighbours = shipGraph.Neighbours(droid.Room).Select(node => node.nb); var unexploredNextToCurrent = unexploredRooms.Intersect(neighbours); Direction door; if (unexploredNextToCurrent.Any()) { var nextRoom = unexploredNextToCurrent.First(); var direction = shipGraph.GetDoorDirection(droid.Room, nextRoom); door = (Direction)direction; path.Add(door); } else { door = path.Last().Opposite(); path.RemoveAt(path.Count - 1); } droid.TakeDoor(door); } } return(shipGraph); }