Generating random path with grids

Get help using Construct 2

Post » Mon Apr 15, 2013 9:52 pm

Hi everyone,

I am not sure if this is asking too much (if it is, sorry) but my question is this,

I have a 6*8 grid and i want to generate a simple random path which connects two corners of it (or any two grid-squares as start and finish points other than corners). Here is an exemple (red is the path):




And i also want to have control over this path's complexity, (more complex paths for further levels) like this exemple below:


I gave each grid (they're sprites) two instance variables as coordinates (like this [gridX=0, gridY=3] etc), and i am trying to change their frame (to red) but i am stuck at this point, i can't use these variables to select the right squares :/

Didn't upload the capx because there is nothing in it.

Thanks a lot in advance.ebrar2013-04-17 11:31:47
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Tue Apr 16, 2013 1:17 am

I would look at some of the threads on random level generation and bitwise method for level generation. These may point you in the right direction as this is really a subset of that type of operation.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Tue Apr 16, 2013 8:27 am

Thanks @bluePhaze, I'll check them out.
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Tue Apr 16, 2013 11:31 am

I tried to use pathfinding behaviour to draw these paths. But there are some problems:

1 - How can I control the lenght of the path?
My solution to this is generating random obstacles for paths' complexity. You think that'll do the job? Or is there a smarter way?

2 - I need my path drawer to move inside the grids. How can i do that? I disabled the diagonal option but it seems to go diagonal at corners.

3 - Finding the shortest path is also a problem. I need random paths but shortest way causes repetitive paths. Maybe that's solution is related to first one.

and here is my capx

Thanks in advance.ebrar2013-04-16 11:33:31
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Wed Apr 17, 2013 10:24 am

Pathfinding behaviour was a bad idea. Couldn't make it. It seems there must be a more convenient way.
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Wed Apr 17, 2013 2:33 pm

here is one possible way
pathLister.capx

listing all possible path, then it's just a matter of choosing amongst them.
Unfortunately it's a pretty expensive calculation. As you can see for a 6x4 grid you already have more than 5000 thousand possible path.
Which means a lot more calculations.

However you can easily get a complexity score for each path using lenth and/or how many turn they have.
Last edited by Yann on Sun Sep 14, 2014 7:22 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Apr 17, 2013 10:18 pm

Thanks a LOT Yann :)

I'll try this and give feedback soon.

Maybe I should consider using a 4*6 grid like yours to keep calculations at a reasonable amount.ebrar2013-04-17 22:22:55
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Wed Apr 17, 2013 10:54 pm

@Yann,

Is it possible to use a pre made list of paths; calculating them once (even in somewhere else) getting the info and storing it in game for further use? Or must I calculate them in game?

If this is possible, using a 6*8 grid won't crash browsers.ebrar2013-04-17 22:55:51
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Thu Apr 18, 2013 1:41 am

@ebrar
That's indeed an interesting idea. To avoid crashing the browser you should either generate them in another language (raw javascript, python, C, etc) and create a JSON file with the list of path that can be loaded in an Array (you should save one to see how it looks)
or distribute the calculation on many ticks. It would still take a while to calculate, but at least chrome wouldn't hang and still find a way to save the result (you have an action to download the JSON file from an array)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Apr 19, 2013 1:38 pm

Thanks again @Yann. I hope this works.

edit: :/ free version limits exceeded.ebrar2013-04-19 14:07:06
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Next

Return to How do I....?

Who is online

Users browsing this forum: GUN and 20 guests