Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for an algorithm to help me navigate between 'open' tiles in a Mahjong solitaire game. The game is to be played on a limited device with only left-right-up-down buttons and I want to speed up the time it takes to reach the appropriate tile. Toward this goal, I have made the movement work between 'open' tiles (tiles that you could move).

For example, pressing down will find the closest open tile below the one you are on, etc... The problem is that some tiles are really tough to get to. I am sure there are some known algos for this soft of things, but I can't find anything online since searching for 'Mahjong' returns 10 pages of free flash games.

Anyone has any idea?

share|improve this question
up vote 2 down vote accepted

Branching sucks. Every time the user has to look at the screen, comprehend it, and then make a decision, you're slowing the game down. With your somewhat-chaotic "move between open tiles" algorithm, nobody but an expert is going to be able to play the game without constant look-comprehend-act-look-comprehend-act cycles.

Here's how I'd do it. Make a horizontal bar on the screen. That bar can be moved up and down by the up and down buttons. No branching - you hold up, it moves up, you hold down, it moves down. Then the user can hit left and right to toggle between available tiles. There's branching here, but very little, since Mahjong is a mostly-vertical game. Most of the time it'll either be "I'm on the right tile" or "I'm on the wrong tile, but the other one is right".

share|improve this answer
When I said the platform was very limiting, I was not kidding: there is a 1-2 sec refresh rate. If it were a little bit better, I'd do as you suggested, however for now, the navigation will be along the axis pressed to the first open tile, with a slant to the pressed direction versus perpendicular to it. – ADB Aug 19 '10 at 11:14

I would experiment with exploiting the fact that Mahjong has two sides. Left/Right to control which side you are on. Up/Down moves to the next tile up or down the same side by row/height.

e.g. When pressing Down: if there is a tile at a lower height than the current selection, move to that one. If not, move to the highest free tile in the next row down. Pressing up can move up in elevation or up to the next row.

share|improve this answer

You could search in both directions - from the current tile to the nearest neighbour, but also looking to see if another tile has the current one as nearest in the opposite direction. Move to the closest of those two if different.

share|improve this answer

I'd suggest implementing all suggestions given, and a few more you could come up with and have people try it without explanation. That alone will tell you what works, and might give you suggestions for what might work better.
It's hard to beat feedback from real users.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.