curiousaboutcsharp
New member
- Joined
- Dec 27, 2024
- Messages
- 2
- Programming Experience
- 5-10
I'm making a game in Unity
I have a building with a bunch of rooms, and rooms are connected to each other by doors
Obviously if there are rooms A, B, C and D then the graph is just a simple graph linking nodes representing each room
So an edge is technically a door between two rooms. I want to give the edge an attribute. bool isOpen. When isOpen == false, then traversal over that edge is not allowed
If I have a Room A and Room B, my graph would be A <--> B
How do I store the information that the edge between A and B is closed aka isOpen == false
I want a fast time complexity solution. I have one solution below but I don't know if it's the most efficient
Have a Dictionary doors that will represent the doors between two rooms, and their open / close status. The key is a tuple (Room1, Room2) and the value is true or false
So if my graph traversal algorithm is on Room A and the next room is Room B, then it will go to Room B if doors( (RoomA, RoomB)) == true
I don't know if this is an issue, but the space taken has to be double the number of doors because the algorithm has to be allowed to access the dictionary no matter the order of the rooms in the key tuple
So the time complexity is that of a hashtable, the space complexity is O(2N) N = number of doors
I'm wondering if there is a more efficient way of doing this. Maybe I have opened myself up to a common bug, or a way to do it with less space taken etc
Thank you!!
I have a building with a bunch of rooms, and rooms are connected to each other by doors
Obviously if there are rooms A, B, C and D then the graph is just a simple graph linking nodes representing each room
So an edge is technically a door between two rooms. I want to give the edge an attribute. bool isOpen. When isOpen == false, then traversal over that edge is not allowed
If I have a Room A and Room B, my graph would be A <--> B
How do I store the information that the edge between A and B is closed aka isOpen == false
I want a fast time complexity solution. I have one solution below but I don't know if it's the most efficient
Have a Dictionary doors that will represent the doors between two rooms, and their open / close status. The key is a tuple (Room1, Room2) and the value is true or false
So if my graph traversal algorithm is on Room A and the next room is Room B, then it will go to Room B if doors( (RoomA, RoomB)) == true
I don't know if this is an issue, but the space taken has to be double the number of doors because the algorithm has to be allowed to access the dictionary no matter the order of the rooms in the key tuple
So the time complexity is that of a hashtable, the space complexity is O(2N) N = number of doors
I'm wondering if there is a more efficient way of doing this. Maybe I have opened myself up to a common bug, or a way to do it with less space taken etc
Thank you!!