Page 2 of 2

Re: question about complicated compatibility checking

Posted: Mon Jan 21, 2019 6:26 pm
by Mijikai
Heres a example of a tile array where every entry is linked to 4 neighbor tiles (left,top,right,bottom).
Every entry knows how many neighbors it has and holds the neighbors tile ids in a combined identifier.

Code:

Code: Select all

EnableExplicit

Structure CODE_STRUCT
  StructureUnion
    ltrb.u[4]
    id.i
  EndStructureUnion
EndStructure

Structure FIELD_STRUCT
  tile.u
  links.u
  area.CODE_STRUCT
  *left.FIELD_STRUCT
  *top.FIELD_STRUCT
  *right.FIELD_STRUCT
  *bottom.FIELD_STRUCT
EndStructure

Structure WORLD_STRUCT
  Array tiles.FIELD_STRUCT(32,32)
EndStructure

Global world.WORLD_STRUCT

Procedure.i Init();INIT - LINK TILE ARRAY!
  Protected w.i
  Protected h.i
  Protected i.i
  i = ArraySize(world\tiles()) - 1
  For w = 0 To i
    For h = 0 To i
      If w < i
        world\tiles(w,h)\right = @world\tiles(w + 1,h)
        world\tiles(w,h)\links + 1
      EndIf 
      If w > 0
        world\tiles(w,h)\left = @world\tiles(w - 1,h)
        world\tiles(w,h)\links + 1
      EndIf 
      If h < i
        world\tiles(w,h)\top = @world\tiles(w,h + 1)
        world\tiles(w,h)\links + 1
      EndIf
      If h > 0
        world\tiles(w,h)\bottom = @world\tiles(w,h - 1)
        world\tiles(w,h)\links + 1
      EndIf
      world\tiles(w,h)\tile = #Null
      world\tiles(w,h)\area\id = #Null
    Next
  Next
EndProcedure

Procedure.i LoadTiles();LOAD DUMMY TILES -> 0 - 360!
  Protected w.i
  Protected h.i
  Protected i.i
  i = ArraySize(world\tiles()) - 1
  For w = 0 To i
    For h = 0 To i
      world\tiles(w,h)\tile = Random(360)
    Next
  Next
EndProcedure

Procedure.i UpdateCodes();GENERATE IDENTIFIER CODE!
  Protected w.i
  Protected h.i
  Protected i.i
  i = ArraySize(world\tiles()) - 1
  For w = 0 To i
    For h = 0 To i
      If world\tiles(w,h)\left
        world\tiles(w,h)\area\ltrb[0] = world\tiles(w,h)\left\tile
      EndIf
      If world\tiles(w,h)\top
        world\tiles(w,h)\area\ltrb[1] = world\tiles(w,h)\top\tile
      EndIf
      If world\tiles(w,h)\right
        world\tiles(w,h)\area\ltrb[2] = world\tiles(w,h)\right\tile
      EndIf
      If world\tiles(w,h)\bottom
        world\tiles(w,h)\area\ltrb[3] = world\tiles(w,h)\bottom\tile
      EndIf
    Next
  Next
EndProcedure

Procedure.i DebugTiles();JUST FOR DEBUG
  Protected w.i
  Protected h.i
  Protected i.i
  i = ArraySize(world\tiles()) - 1
  For w = 0 To i
    For h = 0 To i
      Debug "------------"
      Debug "W: " + Str(w) + " -  H: " + Str(h)
      Debug "TILE: " + Str(world\tiles(w,h)\tile)
      Debug "LINKS: " + Str(world\tiles(w,h)\links)
      Debug "CODE: " + Str(world\tiles(w,h)\area\id)
    Next
  Next
EndProcedure

Procedure.i Links(w.i,h.i);GET - HOW MANY NEIGHBORS TILES?
  ProcedureReturn world\tiles(w,h)\links
EndProcedure

Procedure.i Code(w.i,h.i);GET - IDENTIFIER CODE!
  ProcedureReturn world\tiles(w,h)\area\id
EndProcedure

Procedure.i Tile(w.i,h.i);GET TILE!
  ProcedureReturn world\tiles(w,h)\tile
EndProcedure

Init()
LoadTiles()
UpdateCodes()
DebugTiles()

Debug Tile(6,5)

End

Re: question about complicated compatibility checking

Posted: Mon Jan 21, 2019 7:51 pm
by SeregaZ
i will remake this system. i think it need to make some list of wrong crosses and a few variants of fixing for each case, where can be changed all cross data - all 5 tiles, not only 1 - center tile - right now it happen.

Re: question about complicated compatibility checking

Posted: Wed Jan 23, 2019 1:52 am
by SeregaZ
final result... ops... not final :) it is still in a progress, but main idea probably start work fine. just need to add more matrix "search and replace".

turn off sound - becouse it is not english. this is a little boring video about how square mechanical earth will remake into more natural.

https://www.youtube.com/watch?v=ZluyhTYeDcs