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
- puzzle in place [02] must fit its west edge to puzzle [01] east
edge; - 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 .
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.