## Procedural greneration

Discuss all aspects of programming here. From 8-bit through to modern architectures.
sydney
Posts: 2036
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne
Contact:

### Procedural greneration

I'm playing around with the possibility of writing a 'Roguelike' and the procedural generation of the levels.
I'm starting with a seed value of two bytes and use the first byte to set a variable then add the two bytes, replace the first byte with the second and store the sum in the second byte's space as follows:

Code: Select all

`.increment_seed   lda temp_seed   sta temp   lda temp_seed+1   sta temp_seed   clc   adc temp   sta temp_seed+1rts`

This will give me a repeatable sequence of values to set the attributes of the rooms, paths, monsters etc
Each level has 9 spaces for rooms and I'd like there to be a 75% chance of a room being present so one of the attributes is 'exists'. What is a good way of deciding how to implement this? At first I was simply going to use values over 64 means the room exists and below means it does not but was worried that two low (0 and 1) could create a lot of non-existant rooms.
If I were to AND the seed with 00000011 would this give me 0 25% of the time? I think it would but I've had the kids running round screaming all day and my brain seems to have stopped functioning properly.

tricky
Posts: 2108
Joined: Tue Jun 21, 2011 8:25 am
Contact:

### Re: Procedural greneration

And %00000011 would be zero 25%, non-zero 75%.
You would have to be slightly careful about your seeds, e.g. 0,0 would be a little dull.

I posted a similar routine on RS for "random" numbers, it actually just generates a sequence of 256 numbers before repeating.

For rough random chances, I usually AND with something, where each bit set halves the chance of getting 0; I try to avoid the bits that I am using for something related. e.g. n = rand; if (n & %00000011) PRINT TAB(n, rand) as it will only print in every fourth column.

Rich Talbot-Watkins
Posts: 1171
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

### Re: Procedural greneration

And there are some more random number generators on this page if you need a larger seed size, or you're just finding your results to be not random enough!

http://codebase64.org/doku.php?id=base:6502_6510_maths

sydney
Posts: 2036
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne
Contact:

### Re: Procedural greneration

Thanks guys.
I'm going to try to tire the kids out tomorrow morning so I can get some peace and quiet in the afternoon and get some coding done.

### Who is online

Users browsing this forum: No registered users and 2 guests