Advertisement

Pls help with shanghi/mahjongg theories

Started by February 09, 2000 11:46 PM
0 comments, last by Cygor 24 years, 11 months ago
Hello there.. Im working on a shanghi style game...(some people call it mahjongg) Basically you have a pyramid of tiles and you can take 2 matching tiles away at a time. Ok.. so if you know what im talking about.. here''s the problems. #1) I want to be able to guarentee the game is ''able to be won'' if they make the correct moves. This means I can''t just randomly place the tile, but I to semi-randomly place the tiles so it''s a differnt game every time you play. #2) I need to come up with a quick way for the computer to tell you how many ''possible'' moves there are left. It''s a 3-d array for the tiles in x/y/z. Im open for any suggestions..because im pretty stumped. Thanks in advance. Cygor (this msg also posted in the programming discussion group)
the first problem (possibility) is quite easy to solve. It's the way you generate the game. You have simply choose randomly the 2 corresponding tiles, and then put them at plan (randomly) in a way they could be taken out, if a player would be on turn. Repeat this, until you drop all tiles. (it's simple reversing of puzzle solution)
There is a small problem, if you want the tiles to get some shape at the end of generation (pyramid, or something...). Because puting tiles randomly may cause you to block a free space for tile ... so while choosing random positions for the tiles you may need to check, if some free space wouldn't be blocked ...

The second thing is kinda worser. I'm not sure, what you mean with "quick"... But, ok, I got some idea.
the game starts -> game plan is generated.
now do run trough full array and for each type of tile (1 dimensional array) store the number of free tyles (i.e. ready to get out) of such type.
i.e.:
"VI" tiles is 1 free
"autumn/winter" is 0 free
"3balls" are 3 free
etc... this is time consuming, but does have to be done just at start.
if you could afford enough memory (and you ver likely could afford it, because it is not really too much), you may either hold pointers type->amount_of_free and either sorted linked list _most_free(type) -> 2nd_most_free(type) -> ...

now number of possible moves is:

Sum of (for all types of tiles) {
while ( num >= 2 ) {
num--; // use temporary variable, not the one from array of course
totalmoves += num;
}
/* (i.e. 2 free tiles makes 1 move possible
3 free tiles makes 2+1 moves possible
4 free tiles makes 3+2+1 ...
) */
/* if you have the sorted linked list, use it NOW
i.e.
at the beginning of sum take the "most_of_free" tile type
after this while take the next one
do until you encounter tile type with 1 or less free tiles, than break
(and you have total number of possible moves)
*/
}

you see, that counting possible moves with this "free tiles" array is quite easy, but the computation of this array is damn expensive, and it changes after each move...
that's true, but not that much.

free_tiles_number (type = the type the player has taken) -= 2; // decrease number of free tiles for this type

and examine closest neighbourhood of taken tiles ... if some tile has been released, increment the free counter for
it. This is quite much faster, than scanning through the full array. (make sure to not recognize "before turn" free tile as "free by turn")
And resort the sorted linked list of course.
This is very likely the fastest possible solution.

send me mail at hellco@upjs.sk, if you got some questions, I do check this board rarely ... (lack of time, sorry)
I hope I got you some ideas... happy coding...

---------------------------------------------------
Ped - Peter Helcmanovsky - 7 Gods demo group
http://7gods.rulez.sk
First Sight Entertainment - http://members.xoom.com/fseteam
---------------------------------------------------


Edited by - Ped on 2/22/00 5:29:25 AM
---------------------------------------------------Ped - Peter Helcmanovsky - 7 Gods demo grouphttp://7gods.rulez.skFirst Sight Entertainment - http://members.xoom.com/fseteam---------------------------------------------------

This topic is closed to new replies.

Advertisement