### Post by falconious on May 7, 2021 21:26:15 GMT -5

There are the various random map generators mentioned in other threads. I have been looking more at a topology, inspired by "You sank my BattleDungeon". I wrote a program (below) that will create rooms with enough one-way links to ensure you can get to and from every room.

I am somewhat flummoxed on how to populate the room. My base idea is that e.g. room seven might always have treasure of some description, while room two always has a trap, although there is not much generated variety there. I am thinking of assigning a random number to each room that can look on a more specific list.

The generator code is as follows, and has been tested in GNU Octave. A new dungeon can be generator by changing dungeon_num. To read the map, a "1" in row i, column j means you can go from room i to room j, while a zero means you cannot.

`clear`

dungeon_num = 42; % The seed

rand("seed", dungeon_num);

num_rooms = 10; # How many rooms to put in the dungeon

start_matrix = eye(num_rooms);

% Put an outgoing link in each row

for row_idx=1:num_rooms

found_empty = 0;

while (found_empty == 0)

rand_col = floor(rand(1)*num_rooms+1); # Choose a column

if (start_matrix(row_idx,rand_col) == 1)

continue

endif

start_matrix(row_idx,rand_col) = 1;

found_empty = 1;

endwhile

endfor;

% Put a new link in each column that doesn't have a new link

col_sums = sum(start_matrix,2); % Get a count links in each column

for col_idx=1:num_rooms

if (col_sums(col_idx) < 2) % Only one link

while (1==1)

rand_row = floor(rand(1)*num_rooms+1);

if (start_matrix(rand_row, col_idx) == 1)

continue

endif

start_matrix(rand_row, col_idx) = 1;

break

endwhile

endif

endfor

% Now we check to make sure we are fully connected

while (1==1) %

total_connection_matrix = start_matrix^(num_rooms+1); % Allows cycle through all rooms and back to start

from_start = sum(sign(total_connection_matrix),2)(1); % Make sure we can get to every room from start

to_start = sum(sign(total_connection_matrix),1)(1); % Make sure we can get to start from every room

% With the above satisfied, we can loop in the dungeon and know there are no dead ends

if ((from_start == num_rooms) & (to_start == num_rooms))

break; % We have a suitable matrix

endif

% If we are not complete, add in another connection

rand_row = floor(rand(1)*num_rooms+1);

rand_col = floor(rand(1)*num_rooms+1); % Don't bother with avoiding existing connections

start_matrix(rand_row,rand_col) = 1;

endwhile

disp(start_matrix)

Any suggestions would be appreciated.