Background

So here we are at the end of month and what a crazy month it’s been. You may not be too surprised to hear that I’ve been trying to start this post for the last two weeks. It’s been quite crazy around here though so I never actually got around to doing it.

However, now that we are down to the wire I wanted to make sure at least I got a post up that covers a bit of what I wanted to have up today. We’ll have to wait a couple days until the demo programs up on itch.io.

This post is likely to be even shorter than our February post!


Cellular Automata

This time around I’ll be posting up some information on my knock-off rendition of using cellular automata to dig out caves.

I know this is suppose to be an SDL2 post but we aren’t going to make that leap until the second part. A very small scale version might look like the text below.

Hopefully this renders OK. 🤞

111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111000111111111100111
111111111111111111001110011111111111111000000011111110000011
111111111111111110000000001111111111110000000011111100000001
111111111111111100000000000111111111110000000011111100000001
111111111111110000000000000011111111110000000011111100000001
111111111111100000000000000001100001100000000001111100000001
111111111111100000000000000000000000000000000001111110000011
111111111111100000000000000000000000000000000001111111000011
111111111111000000000000000000000000000000000011111111100011
111111111110000000000000000000000000000000000011111111111111
111111111100000000000000000000000000000000000001110011111111
111111111000000000000000000000000000000000000000000001111111
111000000000000000000000000000000000000000000000000001111111
110000000000000000000000000000000000000000000000000000111111
110000000000000000000000000000000000000000000000000000000111
110000000000000000000000000000000000000000000000000000000011
110000000000000000000000000000000000000000000000000000000011
110000000000000000000000000000000000000000000000000000000011
110000000000000000000011000000000000000000000000000000000011
110000000000000000000111100000000000000000000000000000000011
111000000000000000000111100000000000000000000000000000000011
111000000000000000000111100000000000000000001110000000000011
111000000000000000000111000000000000000000011111000000000011
111000000000000000001111000000000000000000011111100000000011
111000000000000000001111100000000000000000011111110000000011
111000000000000000000111110000000000000000011111110000000011
111100000000000000000111111000000000000000111111110000000111
111110000001100110001111111111000111111111111111111001111111
111111111111111111111111111111111111111111111111111111111111

Cellular automata is broken up into several phases. First thing we are going to do is take a grid - which in our case above is I believe 30x60.

  for x := range l.Grid {
    for y := range l.Grid[x] {
      if rand.Intn(max-min)+min < RandFill || x == 0 || x == len(l.Grid)-1 || y == 0 || y == len(l.Grid[x])-1 {
        l.Grid[x][y] = 1
      } else {
        l.Grid[x][y] = 0
      }
    }
  }

Alright, so, here’s our first stop we’re going to take our slice Grid and randomly fill in 0 or 1. We loop all the way through (and may need to flip the x and y now that I’m looking at it) filling in each tile randomly. During this we are also checking to make sure that if we are on an edge that we fill in a 1 to wrap our “level” in walls so we don’t need to worry about wrapping around for now.

Maybe at some point we’ll extend this out so it is larger and have a wrapping world. But that’s beyond the scope of what I’d like to have accomplished by the end of the year.


Give It A Try

Instead of giving it a try now, we’re going to need to hang on a couple of days. This months project isn’t very exciting as it is more just setting the stage for our next steps. But I’ll be putting up the example executables within the next week or so. I am aiming to have a much more in depth post up around the 10th to cover the past months work as well as bridge what is coming next….

Anyway until next time!


Enjoy this post?
How about buying me a coffee?