123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|560|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Concept/Design -> Mathematic Grid Puzzle

Fri, 16 Mar 2018, 05:17
Jayenkai

Mathematic Grid Puzzle


OK, I have a grid of levels onscreen.. (GridW, GridH) (in this case, 9x9)

The spot in the middle of the grid should be level 1.
Around it are 2,3,4 and 5, then higher and higher, until the four corner points are 78,79,80 and 81

I need a quick and easy Level=LevelAt(x,y) function, ensuring every point is a unique value.

...Anyone!?!

-=-=-
''Load, Next List!''
Fri, 16 Mar 2018, 05:53
spinal
So something like this - http://jsfiddle.net/hitbyatruck/c4Kd6/ (stole from here - https://stackoverflow.com/questions/398299/looping-in-a-spiral)

basically just draw the spiral and count along while doing it?

-=-=-
Check out my excellent homepage!
Fri, 16 Mar 2018, 06:01
rskgames
int Level[9][9] =
{
{ 70,71,72,73,74,75,76,77,78 },
{ 69,41,42,43,44,45,46,47,79 },
{ 68,40,20,21,22,23,24,48,80 },
{ 67,39,19, 7, 8, 9,25,49,81 },
{ 66,38,18, 6, 1, 2,10,26,50 },
{ 65,37,17, 5, 4, 3,11,27,51 },
{ 64,36,16,15,14,13,12,28,52 },
{ 63,35,34,33,32,31,30,29,53 },
{ 62,61,60,59,58,57,56,55,54 }
};
Fri, 16 Mar 2018, 06:09
Jayenkai
Yeah, I'm starting to think that resorting to a pre-gen lookup is going to be easiest, but it also means I'm stuck to that size.

If I decide to bump things up to a 31x31 grid of levels, it's going to be a pain to redo it all.
I was hoping for maths to solve this.
I don't think it's doable.

-=-=-
''Load, Next List!''
Fri, 16 Mar 2018, 06:20
rskgames
I am trying to come up with the generator.
Fri, 16 Mar 2018, 08:44
Pakz
Is this map not like the floodfill method? Probably not though.
Fri, 16 Mar 2018, 10:09
Jayenkai
Took a break and baked a cake. cakeage

Back to coding, and managed this.


Uses the spiral path finding, and seems to run fast enough in BMax that I can use it in the menu for my game.
Also, it's lacking the "Four outer corners = highest values" that I'd've liked.

.. It'll do.. I suppose.

Bah, humbug!

-=-=-
''Load, Next List!''
Fri, 16 Mar 2018, 10:33
rockford
Mmmmmm... cake!
Sat, 17 Mar 2018, 06:54
rskgames
I have uploaded my generate spiral grid cpp code and executable GenerateSpiralGrid (.zip)
Below I have given usage and default output.

Usage:
GenerateSpiralGrid <number Of grids> <Direction> <SPIN> <Corner Special Case>
Where <number Of grids> -> Any odd Number
<Direction> -> can be 1-4. 1-EAST, 2-SOUTH, 3-WEST, 4-NORTH
<SPIN> -> can be 1-2. 1-Clockwise, 2-Anticlockwise
<Corner Special Case> -> can be 1-2. 1-Normal, 2-Corners will have max values.

Grid : 5x5
Direction : North
Spin : Clockwise
24 25 10 11 12
23 9 2 3 13
22 8 1 4 14
21 7 6 5 15
20 19 18 17 16
Sat, 17 Mar 2018, 08:05
TomToad
Here is a version in BlitzMax that will create a grid that you can then check against. It progresses outward and ends up with 78, 79, 80, and 81 in the corner.

The output for a 9x9 grid looks like this


Edit: Reading back, it looks like you are trying to implement this in BlitzBasic/Blitz3D. I need to get ready for work now. I'll try to adapt it later.
Sat, 17 Mar 2018, 08:28
Jayenkai
Actually, the final implementation is being done in the new C++ Framework. I tend to test things in Blitz/Max because.. well, it's just nice and quick, isn't it!!

For now, the Spiral method will do. But I've been thinking and planning all night, trying to come up with a more substantial way to do it, and I *think* I might have the idea somewhat working, involving layers and a little bit of trig!!
But I'm not coding it, today. Instead I'm focusing on getting the finishing touches added to the game.. SFX, Music, etc. It's a bit too quiet, at the minute!!

-=-=-
''Load, Next List!''
Sun, 18 Mar 2018, 08:05
shroom_monk
The solution that makes most sense will depend on how many times per frame you want to look these values up, and how much you care about efficiency. Pre-computing the results once, storing them in an array, and looking them up as needed at runtime is probably the most efficient solution.

However, I was intrigued by the puzzle of computing the value of a single position on the fly, so here is a C++ solution that produces a quick spiral with some relatively concise code (though I'm sure it could easily be shrunk down):




-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!