Sounds like one of my old high-school projects,
I see several ways of doing what you want that make sense:
* -random population always of an array 81 units long (80 if you
want the last to always be blank)
o --you could create a function that loops 41(or 40 if last
always blank)times tracking the positions in a temp array
and then returning the completed array (if 41st loop
choosing unfilled position with a 0 for blank card/wild card)
o --there are other ways of doing this; yet, they use more
loops and if statements.
* -random population of an array 81 units long and then shuffling
the "deck" sort of
o --shuffling by swapping only positions that have not been
swapped (you could even isolate left and right sides to
simulate a card deck getting shuffled by hand)
o --shuffling by swapping from 1 to 81 to ensure all positions
get swapped
o --there are most definitely more ways of doing this
* -static population and then shuffling the "deck" same as above.
As well, although I think you may not need to be told this, when you
want to display the positions, you need to know and track which row
level of the grid you are on and what column position you are in, in
order to properly find the x and y values; thus, in your case testing if
the modulus of 9 equals 0 will be handy.
I hope the concepts help,
Anthony
Paul Steven wrote:
I am trying to write the code to populate a 9 by 9 grid of tiles with 40
pairs of matching tiles.
I have 4 different types of tiles and I want to create a grid that has 40
matching pairs and 1 blank tile.
I do not want the pairs all to be next to each other but there needs to be
at least one solution that enables a player to match each and every pair. To
match a pair there needs to be a clear path between each member of the pair.
1,2,1
2,0,3
4,4,3
In this simple example, a user could clear all tiles by matching in the
following order:
4 - 4
3 - 3
2 - 2
1 - 1
Note that until they have matched the pair of 2's they cannot match the 1's
as there would be no clear path between them.
All my attempts so far to create this grid is resulting in script errors due
to my code being unable to find a solution. My code basically gets about 60%
of the board created then finds it cannot any more clear paths to create the
remainder of the grid.
I would really appreciate any help cracking this function.
Thanks
Paul
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders