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

Posted : Friday, 16 March 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!?!

-=-=-
Posted : Friday, 16 March 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!
Posted : Friday, 16 March 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 }
};
Posted : Friday, 16 March 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.

-=-=-
Posted : Friday, 16 March 2018, 06:20
rskgames
I am trying to come up with the generator.
Posted : Friday, 16 March 2018, 08:44
Pakz
Is this map not like the floodfill method? Probably not though.
Posted : Friday, 16 March 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!

-=-=-
Posted : Friday, 16 March 2018, 10:33
rockford
Mmmmmm... cake!
Posted : Saturday, 17 March 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
Posted : Saturday, 17 March 2018, 08:05
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.
Posted : Saturday, 17 March 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!!

-=-=-