Hi, Paul, Can you explain what you mean by a "clear path". For example, when I look at this example below:
> 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 I don't see the "clear path" between 1 - 1. Seems like it jumps from one square to another. So is a clear path just a straight or diagonal line between the next number in the sequence that is unobstructed by a non-used pair, or what? -jonathan On Wed, Mar 11, 2009 at 12:59 PM, Paul Steven <[email protected]>wrote: > Thanks Anthony > > Perhaps I am overcomplicating things but I am under the impression I need > to > ensure there is a clear path between each pair as I add them. > > My current algorithm is as follows: > > Step 1. Choose a random tile position (Random Row, Random Column) > > Step 2. Create an array of all possible tiles that this random tile can be > paired with. To create this array, I use a path finding function to check > there is a clear path between the 2 tiles > > Step 3. Choose one of the possible tiles from the array (currently I am > just > choosing a random one) and update grid data to reflect the 2 paired tiles > are not on the grid. > > Repeat from Step 1 again.... > > This works fine until around 26 pairs have been placed then it gets stuck > as > it cannot find any more tiles that have a clear path. > > I have even added code to ensure that no isolated empty tiles are created > as > a result of creating a pairing. > > I have tried putting several timed break points in my code to restart the > entire process if it fails to complete the entire grid. However it just > doesn't seem to ever be able to generate an entire grid. > > Perhaps this process is really time consuming and I need to leave it for > hours to generate a grid but I wouldn't have thought so. > > Any advice much appreciated! > > Thanks > > Paul > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Anthony > Pace > Sent: 11 March 2009 16:31 > To: Flash Coders List > Subject: Re: [Flashcoders] Advice on creating random grid of pairs for a > game > > 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 > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- -jonathan howe _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

