PDA

Click to See Complete Forum and Search --> : Honeycomb Algorithm


Merrissey
Apr 28th, 2004, 11:13 AM
Since this pertains to both VB and maths, I'll post it here too, I might even get a better response :P

http://bloody-cherry.com/tiles.gif

Here's three screenshots from a program I'm making, n=1, n=2 and n=3. You can see where it's going. With n=1 only one tile is selected, n=2 all the surrounding tiles, n=3 all the surround tiles of those tiles.

At the moment it's I just typed in a big mofo 'If' statement for the purposes of showing what it's supposed to do. What I need to do is work out some kind of algorithm that can do this automatically.

If anybody can help me out with this I'd greatly appreciate it.

VB source code can be found at http://bloody-cherry.com/math.zip

Acidic
Apr 28th, 2004, 12:37 PM
OK, this is not a full algorithm, but at least a good start.

when n=0, don't do anything, when n=1, then fill in the tile.

when n=2 then:
origTile = tile that was previously filled in
also fill in:
origTile+9 'one below
origTile-9 'one above
origTile-5 'top left
origTile-4 'top right
origTile-5 'bottom left
origTile-4 'bottom right
obviously check those tiles exist first.

when n=3, insert all the previous tiles (from when n=2) into the same function. This is actually quite innefficient though as lots of points are being filled in lots of times. also you'll have to see that the colouring in of the tiles doesn't go from one side to other, eg if h=13 and n=2 then 8 and 26 shouldn't be filled in. Not quite sure how to do that.

alkatran
Apr 29th, 2004, 02:09 PM
Does this picture make it clearer? Select the 2 next columns in the the rows above and below, and the same column in the rows 2 above and 2 below.

wossname
Apr 30th, 2004, 08:05 AM
or a simpler way generate the tile numbers on the fly...


'this array generated as per width of grid
Dim directions(5) As Integer = {LEFTUP, LEFTDOWN, DOWN, RIGHTDOWN, RIGHTUP, UP}
'this array deals with the spiralling effect
dim modifier(5) as integer = {-1, 0, 0, 0, 0, 0)

'this sub assumes that each tile object has a flag marking it as either lit up or not.
Sub FlagTiles(ByVal h As Integer)
Dim k, i, j, count As Integer

count = h + UP
highlight(count) 'always move 1 square up to start with and then continue spiral
For k = 0 To n 'how big your group of tiles will be
For i = 0 To 5 'the 6 sides of the hexagon group
For j = 1 To (k + modifier(i)) 'how many tiles on a particular side
count += directions(i) 'jump to next square
tile(count).litUp = True 'light it up!
Next j
Next i
Next k

End Sub


It should work when h is in the middle of the board but not at the edge. You'll have to modify it to detect the edge of the board.

I haven't tested this code but it should set you off in the right direction. It seems pretty close to me.

Please let me know how you get on.

wossname
May 5th, 2004, 10:26 AM
Any luck yet?