Setting up mahjong game layouts

Blitz3D Forums/Blitz3D Beginners Area/Setting up mahjong game layouts

Hi,

I was just wondering if anyone had any experience programming a mahjong (tile matching version, not "real" mahjong) tile layout or any links on how to program something like this. I can handle the tile layouts, my concern is randomly placing the values to those tiles.

There must be some kind of guidelines for setting up a board so that there are enough matching tiles and that the game is solvable. Any tips would be appreciated. Thanks!

Greetings Puppies,

You have a number of tiles and a number of values that can be assigned to those tiles. It doesn't matter where those tiles are. As a skeleton how about something like(I'm in work and can't test right now):

Type TileType
  field id
  field x,y
  field tile_value
end type

global Tile.TileType
dim Tiles.TileType(NUM_TILES)

Type TileValuesType
  Field id
  Field value
End Type

global tilevalue.TileValuesType
dim TileValues.TileValuesType(NUM_TILES)

restore TileValueData
delete each TileValuesType
for i = 0 to NUM_TILES-1
  Read value
  TileValues(i) = new TileValuesType
  TileValue = TileValues(i)
  TileValue\id = i
  TileValue\value = value
Next

seedrnd(Millisecs())

delete each TileType
num_left = NUM_TILES

for i = 0 to NUM_TILES-1
  tiles(i) = New TileType
  tile = tiles(i)
  tile\id = i
  tile\x = rand(X_SIZE)
  tile\y = rand(Y_SIZE)
  
  randomtileno = rand(numleft)
  
  ; Not too sure about the syntax being used here, you'll have to check.
  TileValue = First TileValuesType
  for j = 0 to randomtileno
    TileValue = After TileValuesType
  next

  tile\value = TileValue\value
  delete tilevalue
  numleft = numleft -1
next


The basic concept is there and I'll correct it later this evening if necessary. This *should* randomly allocate a tile value to a tile. However, it won't ensure that the game is solvable.

Hope that helps some.

Peace,

Jes

Thanks, that does help. Now my only problem is making sure the puzzle is solveable. My girlfriend figures it's just a matter of having 2 pairs of each tile (4 in total) and that if you randomly locate them it will ultimately be solvable.

I guess it's time for me to do some prototyping.

Thanks again!