11 Replies - 932 Views - Last Post: 15 November 2012 - 08:35 PM Rate Topic: -----

#1 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 93
  • Joined: 15-April 10

What to know before starting a randomly generated level?

Posted 14 November 2012 - 09:05 AM

Hi,

I want to create a very simple platformer-type game in flash with a small, randomly generated level. To start off, I want it to be as simple as having a few platforms randomly placed on the screen, but with certain rules so as to make the game playable and challenging.

What do I need to learn first before trying to do this? I know how to assign randomly generated x and y values to the platform objects, but how should I control this randomness to create playable patterns? For example,

http://img.photobuck...tar_xe/lvl1.jpg
http://img.photobuck...r_xe/lvl2-1.jpg
http://img.photobuck...tar_xe/lvl3.jpg

lvl 1 and 2 are examples of something that could be playable. The user can jump from platform to platform starting from the bottom to reach the top. These two examples are something I'd like to see when randomly creating a level.

Level 3, though, is what could happen if I simply assigned random numbers to the x and y values of the objects. It can end up with a level where the platforms are placed in such a way that the user has no way of reaching the top.

I would appreciate it if somebody could point me in the right direction as to how to produce randomly generated levels that are playable.

This post has been edited by KBoogle: 14 November 2012 - 09:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: What to know before starting a randomly generated level?

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: What to know before starting a randomly generated level?

Posted 14 November 2012 - 11:29 AM

The reason why it isn't working for you is because your level generation algorithm is 'entirely random', ignoring rules that make the game playable.

What should be happening is that the randomness occurs within the constraints that permit playability. How could we approach that problem? Well there are several approaches that come to mind:

1. Randomly generate a level and 'parse' it to see if it is playable. If not, generate another one and check. This is not a good approach, as it is possible you may never come across a solution and your game hangs.

2. Predetermine a number, or more appropriately, a list of levels that are clearly playable and randomly select the next level from that list. This is the recommended solution for obvious reasons including not having to run an expensive random generator potentially thousands of times per iteration of creating a new level.
Was This Post Helpful? 2
  • +
  • -

#3 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 93
  • Joined: 15-April 10

Re: What to know before starting a randomly generated level?

Posted 14 November 2012 - 12:50 PM

Yes, I have been thinking about logical ways to approach this. Creating a number of levels and selecting one of them randomly is certainly an option, but that wouldn't be a randomly generated level. In other words I could create a 100 levels manually and then randomly select from them, but I'd still have "only" 100 levels.

A method I've been thinking of was to restrict the randomness to certain spaces. For example, a platform could be placed randomly, but only within a certain space. Likewise, I could generate platforms one by one, placing them at random distances apart, but only within possible jumping distance from the previous platform.

I could then vary the general design of the level by creating certain patterns - for example one pattern might have platforms with a high restriction on height differences, creating a rather flat level, while another might have a much lower restriction allowing a more "cliffy" kind of platform placement.

I'm just wondering if there are some general good practices or tips on this, or maybe some other methods that I could consider.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: What to know before starting a randomly generated level?

Posted 14 November 2012 - 05:29 PM

You're not getting my point, whatever you do will never be entirely random. Even if you restrict things to certain spaces you will still have a finite set of possible maps, and to claim that anything will be entirely random is absurd.

Remember that this is a game and it is only necessary to create the illusion of a randomly generated environment. If you want to go with the random tiles approach that I think you are suggesting, then go ahead. Just know that you are increasing complexity in developing your game, as well as less control over the quality of gameplay.
Was This Post Helpful? 0
  • +
  • -

#5 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 93
  • Joined: 15-April 10

Re: What to know before starting a randomly generated level?

Posted 14 November 2012 - 08:43 PM

This isn't for a game that anyone's going to play. This is an experiment for me to learn techniques for randomly generated content.
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 08:12 AM

Either way, what you're proposing isn't going to work. You are better off putting your efforts into actually finishing the game.
Was This Post Helpful? 0
  • +
  • -

#7 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 93
  • Joined: 15-April 10

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 10:18 AM

I thank you for your advice, but I do not agree with you. There are hundreds of games that utilize procedurally generated content. Some are AAA games made by big companies, like Diablo 2 for example. Others are small indie games made by one person, like Spelunky.

Both of those are very complex and far beyond what I could do right now, but I have to start somewhere, and a very simple project to create a randomly generated, simple, small, bare bones level is a good way to start, in my opinion.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9199
  • View blog
  • Posts: 34,560
  • Joined: 12-June 08

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 11:11 AM

There's the problem. 'Procedurally generated levels' and 'random level' are two different beasts.

Think of it as a math equation... something like:
4n + y = 5

Assuming n and y are just integers there are a number of ways to make this work as there are number of ways this won't. We have constraints on your problem. Procedurally generated levels are like the constraints. 'n' has a bit of play on what values it can be as well as y.. and the output (5) is a nebulous 'fun level'.

You - the game maker - should know what a 'fun level' is. We all hate the games where the platforms are too damn far apart, or the enemies spawners too close, or the terrain not passable, or the health packs are too few... etc.

These define things that contribute making the game fun.. that means have a path from the start to the finish of the level... things distributed nicely, etc. See those are constraints and there is a only a subset of "everything possible" that can achieve this.

With pure randomness you toss out any constraints and lord knows what you get out - most likely crap.

So yes, while there are AA games that utilize procedurally generated code do not mistake that for an instance of being a "purely random level". If you can get from the start to the end without the terrain getting in your way that is not an accident. That was baked into the procedures.
Was This Post Helpful? 2
  • +
  • -

#9 shintetsu_80  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 105
  • Joined: 01-July 08

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 11:20 AM

I think you could probably accomplish what you want with a very complex algorithm, but you might be wasting a lot of time if your goal is to make a simple game with random levels. I would take a mix of @ButchDean's 2 aforementioned approaches. I made a pong game that was similar to this and could easily be adapted to this approach. I'll describe that and explain how to extrapolate that out.

So in my pong game I used txt files to describe the layout of the blocks that would appear. I already had a max width and height for where the blocks would go. So it was very simple a 1 ment add a block a 0 ment no block. So I just parsed the file adding blocks as needed until I reached the end of my playable (blocks) area or the file.

In my case I was more strick and I just manually created a number of txt files that had the 1's and 0's where I wanted them, but look how easy this could be extrapolated out. Just simple use a random number generator to get a 1 or 0 and there you go. As many pseudorandom levels as you want. I say pseudorandom because random number generators are not truly random but who's gonna play that many levels? This would even have the added benefit of not parsing any files.

Ok now if you want to take that even farther. Lets consider a 2D tile game like Zelda. Again you have a fixed width and height. So using a similar approach you could add impassible and passible objects. Uh-oh! See the problem? And this is what @ButchDean was talking about what if you places to many impassible objects? How are you going to walk around. Ok, beef up your placement algorithm. For this case, assuming the objects are square, you could probably get away with something like, an impassible object can have no more than two impassible objects touching it. So you get two sides of passage. I just made this up so who knows if that would actually work but it would surely not be any fun to play. I know that's not your point.

So there's a start. As you can see this is going to get very complex very fast, but if your only goal is to create a randomly generated level with enough code you can get there.
Was This Post Helpful? 0
  • +
  • -

#10 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 08:06 PM

View Postmodi123_1, on 15 November 2012 - 06:11 PM, said:

There's the problem. 'Procedurally generated levels' and 'random level' are two different beasts.

Exactly. With 'procedurally generated levels' you are randomizing the form of the terrain - yes objects may be spawned in the world randomly, but even so the level of random placement will be restricted to certain areas. An example being that let's say a number of objects are placed in front of an exit from a level, you are looking at a game that cannot be completed since the gamer can encounter a situation where they cannot complete the game.
Was This Post Helpful? 1
  • +
  • -

#11 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 08:12 PM

View Postshintetsu_80, on 15 November 2012 - 06:20 PM, said:

So there's a start. As you can see this is going to get very complex very fast, but if your only goal is to create a randomly generated level with enough code you can get there.

I like this level of optimism, but you also have to be aware that in trying to account for every case somewhere along the line you will break another one, resulting in an algorithm that simply doesn't work.

This is one of the big reasons why in game development you keep things simple.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9199
  • View blog
  • Posts: 34,560
  • Joined: 12-June 08

Re: What to know before starting a randomly generated level?

Posted 15 November 2012 - 08:35 PM

Here's a good article from the man Notch himself about how minecraft does the procedural generation.

http://notch.tumblr....neration-part-1

http://pcg.wikidot.c...games:minecraft
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1