Question: I have this code for creating a room builder that I want to have outbound connections created for each room. I am also confused on
I have this code for creating a room builder that I want to have outbound connections created for each room. I am also confused on how to randomly generate the rooms as well as creating separate files for each room - as per the requirements of the specifications. I was given this pseudocode below for adding random connections and connecting 2 rooms together to follow as a guideline for creating the outbound connections, but I am unsure of what direction to take.



1/ Create all connections in graph while (IsGraphFull() == false) AddRandomConnection(); // Returns true if all rooms have 3 to 6 outbound connections, false otherwise bool IsGraphFull() // Adds a random, valid outbound connection from a Room to another Room void AddRandomConnection() Room A; // Maybe a struct, maybe global arrays of ints Room B; while(true) A = GetRandomRoom(); if (CanAddConnectionFrom(A) == true) break; do B = GetRandomRoom(); while(CanAddConnectionFrom(B) == false || IsSameRoom(A, B) == true || ConnectionAlreadyExists(A, B) == true); ConnectRoom(A, B); ConnectRoom(B,A); // TODO: Add this connection to the real variables, // because this A and B will be destroyed when this function terminates // Returns a random Room, does NOT validate if connection can be added Room GetRandomRoom) // Returns true if a connection can be added from Room x (.rooms.". Next, it must generate 7 different room files, which will contain one room per file, in the directory just created. You may use any filenames you want for these 7 room files, and these names should be hard-coded into your program. For example, if John Smith was writing the program, he might see this directory and filenames. Note that 19903 was the PID of the rooms program at the time it was executed, and was not hard-coded: $ ls smithj.rooms. 19903 Crowther_room Dungeon_room PLUGH_room PLOVER_room twisty_room XYZZY_room Zork_room The elements that make up an actual room defined inside a room file are listed below, along with some additional specifications: A Room Name O A room name cannot be assigned to more than one room. o Each name can be at max 8 characters long, with only uppercase and lowercase letters allowed (thus, no numbers, special characters, or spaces). This restriction is not extended to the room file's filename. You must hard code a list of ten different Room Names into your rooms program and have your rooms program randomly assign one of these to each room generated. Thus, for a given run of your rooms program, 7 of the 10 hard-coded room names will be used. A Room Type o The possible room type entries are:START_ROOM, END_ROOM, and MID_ROOM. o The assignment of which room gets which type should be randomly generated each time the rooms program is run. o Naturally, only one room should be assigned the START_ROOM type, and only one room should be assigned the END_ROOM type. The rest of the rooms will receive the MID ROOM type. Outbound connections to other rooms o There must be at least 3 outbound connections and at most 6 outbound connections from this room to other rooms. o The oubound connections from one room to other rooms should be assigned randomly each time the rooms program is run. o Outbound connections must have matching connections coming back: if room A connects to room B, then room B must have a connection back to room A. Because of all of these specs, there will always be at least one path through. o A room cannot have an outbound connection that points to itself. o Aroom cannot have more than one outbound connection to the same room. Each file that stores a room must have exactly this format, where the... is additional outbound room connections, as randomly generated: ROOM NAME: CONNECTION 1: ROOM TYPE: 1/ Create all connections in graph while (IsGraphFull() == false) AddRandomConnection(); // Returns true if all rooms have 3 to 6 outbound connections, false otherwise bool IsGraphFull() // Adds a random, valid outbound connection from a Room to another Room void AddRandomConnection() Room A; // Maybe a struct, maybe global arrays of ints Room B; while(true) A = GetRandomRoom(); if (CanAddConnectionFrom(A) == true) break; do B = GetRandomRoom(); while(CanAddConnectionFrom(B) == false || IsSameRoom(A, B) == true || ConnectionAlreadyExists(A, B) == true); ConnectRoom(A, B); ConnectRoom(B,A); // TODO: Add this connection to the real variables, // because this A and B will be destroyed when this function terminates // Returns a random Room, does NOT validate if connection can be added Room GetRandomRoom) // Returns true if a connection can be added from Room x (.rooms.". Next, it must generate 7 different room files, which will contain one room per file, in the directory just created. You may use any filenames you want for these 7 room files, and these names should be hard-coded into your program. For example, if John Smith was writing the program, he might see this directory and filenames. Note that 19903 was the PID of the rooms program at the time it was executed, and was not hard-coded: $ ls smithj.rooms. 19903 Crowther_room Dungeon_room PLUGH_room PLOVER_room twisty_room XYZZY_room Zork_room The elements that make up an actual room defined inside a room file are listed below, along with some additional specifications: A Room Name O A room name cannot be assigned to more than one room. o Each name can be at max 8 characters long, with only uppercase and lowercase letters allowed (thus, no numbers, special characters, or spaces). This restriction is not extended to the room file's filename. You must hard code a list of ten different Room Names into your rooms program and have your rooms program randomly assign one of these to each room generated. Thus, for a given run of your rooms program, 7 of the 10 hard-coded room names will be used. A Room Type o The possible room type entries are:START_ROOM, END_ROOM, and MID_ROOM. o The assignment of which room gets which type should be randomly generated each time the rooms program is run. o Naturally, only one room should be assigned the START_ROOM type, and only one room should be assigned the END_ROOM type. The rest of the rooms will receive the MID ROOM type. Outbound connections to other rooms o There must be at least 3 outbound connections and at most 6 outbound connections from this room to other rooms. o The oubound connections from one room to other rooms should be assigned randomly each time the rooms program is run. o Outbound connections must have matching connections coming back: if room A connects to room B, then room B must have a connection back to room A. Because of all of these specs, there will always be at least one path through. o A room cannot have an outbound connection that points to itself. o Aroom cannot have more than one outbound connection to the same room. Each file that stores a room must have exactly this format, where the... is additional outbound room connections, as randomly generated: ROOM NAME: CONNECTION 1: ROOM TYPE: