Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Random Hallways

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
djfenix




Joined: 12 Mar 2003
Posts: 359

PostPosted: Sat Feb 02, 2008 3:58 am    Post subject: Random Hallways Reply with quote

I got inspired by Camdog's roguelike recently, but i didnt like the randomness to the traditional roguelike, so I'm started to play around with his script and tried to do something different

What I'm trying to do here is make a bunch of random connecting hallways.

The script starts by clearing the map and placing a 2x2 tile starting position. From there, it randomly picks one of the 4 tiles to continue building from, building a horizontal hallway at a random length. Then it'll pick another random position that has already been built and build a vertical hallway, then horizontal, then vertical again, continuing until it's finished building the set amount of hallways.

The problem with the script is that it doesn't build any hallways. It manages to build the starting point, but that's about it. So this is the portion of script that doesn't work:

Code:
 while (number_of_halls <> 0) do(
  hallplace := 0 #checks to see if the current hall is built

  for (x, 0, map width, 1) do(
   for (y, 0, map height, 1) do(
    if ((readmapblock (x,y)) == 1) then( #looks for a floor tile to work on
     if (hallplace <> 1) then ( #if the hall hasn't been built
      if (random (1, 100) <= 1) then(
       hallplace := 1
       hall_length := random (5, 15) #randomly makes length for each hall
        if (curdir == 1) then( #1 by default.  1 is horizontal, 2 vertical
         for (roomx, x, x + (hall_length*2), 2) do(
          for (roomy, y, y+1, 1) do(
           write map block (roomx, roomy, 1) #laying the floor
           write pass block (roomx, roomy, 0) #the whole map is a wall, so this makes floors walkable
          )
         )
         curdir := 2
        else(

         for (roomx, x, x + 1, 1) do(
          for (roomy, y, y + (hall_length*2), 2) do(
           write map block (roomx, roomy, 1) #ditto but for vertical
           write pass block (roomx, roomy, 0) #ditto
          )
         )
         curdir := 1
        )
       )
      )
     )
    )
   )
  )
 number_of_halls := number_of_halls -- 1 #after current hall is done
 )


It's probably some really stupid mistake. I got it to actually build the hall before, just that it didn't connect. At all.
Back to top
View user's profile Send private message
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Sat Feb 02, 2008 6:37 am    Post subject: Reply with quote

My first thought is the line

Code:
if(random(1,100)<=1),then


This will almost never happen. You're giving the thing a 1% chance to build every time it tries a new place.

Also, I'm almost certian you're using the hallplace variable wrong. Right now, the while loop resets it to zero every time, and when you start laying a floor it gets set to 1 every time, and the one if check that uses it will never be false because it got reset to zero by the while loop. I'm not sure what the purpose of this variable actually is.
_________________
My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161

This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com
Back to top
View user's profile Send private message Visit poster's website
djfenix




Joined: 12 Mar 2003
Posts: 359

PostPosted: Sat Feb 02, 2008 12:21 pm    Post subject: Reply with quote

lol... mentioning that actually helped me solve it.

The point of the hallplace variable is to make sure that the random line keeps trying until it actually picks a place. While there's only a 1% chance of picking that any tile, it'll keep trying until that 1% is picked. And once it's picked, it'll the hallplace variable will be set to 1, thus ensuring that it stops building that current hall, then moves on to the next hall by setting it back to 0.

Now, the problem with the script is

Code:
if (hallplace <> 1) then (


That should be a "while" to make sure it keeps trying to build the hall.

Heh, now all i gotta do is fix the actual drawing of the hall.
Back to top
View user's profile Send private message
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Sat Feb 02, 2008 2:01 pm    Post subject: Reply with quote

Maybe I'm still missing something, but I'm pretty sure that you're script is still out of order. As written, it seems that the hallplace while loop would just go over and over on the same tile, because the for loops are outside of the while loop. I think your general flow should look something like this:

[pseudocode]
Code:

set number_of_halls
while(number_of_halls <> 0),do
  begin
    hallplace:=0
    while (hallplace==0),do
      begin
        for(x and y from 0 to respective maxes),do
          begin
            if(random(1,100)==1),then
              begin
                #make the hall
                #set x and y to their maxes, so that the for loop ends
                #set hallplace to 1, so that this while ends
                #decrement number_of_halls
              end
          end
      end
  end
eat lunch

_________________
My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161

This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com
Back to top
View user's profile Send private message Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sat Feb 02, 2008 5:52 pm    Post subject: Reply with quote

Three more problems:
First, the right most tile of the map is mapwidth -- 1, and the bottommost is mapheight -- 1. This isn't deadly, but might lead to strange problems.

Second, your else() is inside your "if (curdir == 1) then(", you forgot the closing bracket to the then() (and have an extra one afterwards)

Also, in "for (roomx, x, x + (hall_length*2), 2) do(", why are you moving 2 tiles at a time? This would be the reason that your hallway doesn't connect.

It sounds to me that you don't need the hallplace variable, because the number_of_halls while loop does exactly the same thing. But maybe you were planning to have it do something later. Anyway, here's the simplified outline:

(pinched from msw)
Code:
set number_of_halls
while(number_of_halls) do(
  for(x and y from 0 to respective maxes) do(
    if(tile(x,y) is floor) then(
      if(random(1,100)==1) then(
        #make the hall
        #change curdir
        #decrement number_of_halls
        #quit the for loops
      )
    )
  )
)


BTW, to quit a for or while loop you can use break. To quit nested loops (2 for loops in this example), you can use break(2). (See 'plot:break') Not that it's much better or easier than setting x and y to their maximum, but if I don't tell anyone, they won't know.


Now, this algorithm (with a 1% chance) looks quite slow. If you start with only 4 floor tiles, then the expected number of whole-map iterations is 25 to put in the first corridor. I suggestion just picking a tile at random until you find a floor tile (on average, this should be 100 times faster).


As for random dungeon generation, you can find a LOT of articles all over the web. However, these articles normal focus on producing certain dungeon styles typical to RL's: Rogue-style rooms connected with corridors, mazes, natural caverns, and random twisty hallways. Here's couple of indices:
http://web.archive.org/web/20010405204554/www.skoardy.demon.co.uk/rlnews/devmain.html#topics (some pages might be dead)
http://roguebasin.roguelikedevelopment.org/index.php?title=Articles#Map
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group