bool CheckPath(Room room) { for (int i = 0; i < room.exits.Count; i++) { FindPath path = new FindPath(room.grid, Elements.button); if (!path.IsPath(room.entrance, room.exits[i])) { return(false); } } return(true); }
Node PlaceBox(Node start_node, Room room) { List <Node> open_list = new List <Node>(); HashSet <Node> closed_list = new HashSet <Node>(); open_list.Add(start_node); while (open_list.Count > 0) { Node current_node = open_list[0]; open_list.Remove(current_node); closed_list.Add(current_node); for (int i = 0; i < 4; i++) { Pos box_pos = BoxPos((Direction)i, room.grid, current_node.pos); Pos push_pos = PushPos((Direction)i, room.grid, current_node.pos); if (box_pos != null && push_pos != null && !IsCorner(push_pos, room)) { FindPath path = new FindPath(room.grid, Elements.box); if (path.IsPath(current_node.player_pos, push_pos)) { Node new_node = new Node { pos = box_pos, depth = current_node.depth + 1, player_pos = push_pos }; bool contains = false; foreach (Node node in open_list) { if (node.pos.x == new_node.pos.x && node.pos.y == new_node.pos.y) { contains = true; break; } } if (!contains) { foreach (Node node in closed_list) { if (node.pos.x == new_node.pos.x && node.pos.y == new_node.pos.y) { contains = true; break; } } } if (!contains) { open_list.Add(new_node); } } } } open_list = open_list.OrderByDescending(w => w.depth).ToList(); } Node deepest_node = null; int node_depth = 0; foreach (Node node in closed_list) { if (node.depth > node_depth) { node_depth = node.depth; deepest_node = node; } } return(deepest_node); }