-1

i am writing algorithm for puzzle game.I am putting puzzles in spiral in this manner:

[07][08][09][10]      
[06][01][02][11]
[05][04][03][12]
[16][15][14][13]

Example

  1. puzzle in place [02] must fit its west edge to puzzle [01] east edge;
  2. puzzle in place [06] must fit its east edge to puzzle [01] west edge; and its south edge must fit puzzle [05] north edge.

I will have unpredictible number of puzzles from whitch I will always try to form biggest square.
I ' ve created following class, and function

 class Tile
        {
            private int north;
            private int east;
            private int south;
            private int west;
        }

        bool checkFit(Tile t, Tile[] R, int pos)
        {
            if (pos == 0)
                return true;

            return false;
            }
    }

In checkfit I will check if i can put puzzle as next element of my array. It gets tile that i try to put, array filled with tiles up to current position that I want to fill, and first empty position (the last one won't be needed as i will check for first null element in array R, it is only skeleton of function now).

Problem is I can't figure out algorithm to check for n tile if it fits (n-1) tile edge (and which one?) and if there is another tile to check .

Security Hound
  • 2,577
  • 3
  • 25
  • 42
Zaphood
  • 2,509
  • 2
  • 22
  • 21
  • 1
    The simplest solution is to figure out each move for each element. You know the rules so you are able to do exactly that. Write everything on paper then come up with a formula that solves it. You still have a great deal more work to do before we can even begin to help you. – Security Hound Oct 19 '11 at 11:20
  • It actually isn't homework; Problem is I' ve wanted to figure it out on paper, just can't come up with solution. – Zaphood Oct 19 '11 at 11:34
  • 3
    Dupe1: http://stackoverflow.com/questions/1183013 dupe2:http://stackoverflow.com/questions/1174249 – Ahmet Kakıcı Oct 19 '11 at 11:54
  • 1
    What **exactly** are input and output of the algorithm? – Dialecticus Oct 19 '11 at 12:59
  • I don't understand this question, you need a method that will check what? – Salvatore Previti Oct 19 '11 at 13:46

1 Answers1

0

Problem is I can't figure out algorithm to check for n tile if it fits (n-1) tile edge (and which one?) and if there is another tile to check .

The reason you are having problems comming up with your a solution is your prototype will not solve the problem.

You need to keep track of the row and column of a tile that is all. I assume the variables are the adjcent tiles correct?

So tile 07 would be adjcent to 06 16 08 and 10 correct?

If that is the case then the algorithm is extremely easy. You need a jagged array for one thing.

Security Hound
  • 2,577
  • 3
  • 25
  • 42