[Flashcoders] Fast color-transformation over MovieClip with cacheAsBitmap
Hey! I have a very complex vector symbol on the Stage - background_mc . I have set background_mc.cacheAsBitmap = true. This turns background to bitmap and makes Stage repaint fast. Every frame the background light changes. I use the following code to alter the light. (new Color(background_mc)).setTransform(light); And here is the problem. The code works very slow. I guess because the light is applied to the contents of the background_mc. And then a new cached bitmap is rasterized once again. The same code over BitmapData of the same size works much faster! Is there a way to tell Flash to apply color-transformation to the cached bitmap, instead of underlying vector symbols? Note, that background_mc is scaled when Stage is resized. This is not so fast, but it's good, because the picture quality preserved. If I convert background_mc to BitmapData, bitmap would be scaled. Pavel ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] removing dynamically created movie clips
sure Matt, I'm using as3...:) also can I use stage.removeChildAt(0); since the newly created movieclip instance appears always on 0 or at least I think based on the link Glen pike send me about. Gustavo On Jun 2, 2009, at 2:02 PM, Matt Gitchell wrote: The container would be the stage in that instance, yes. I used it because Stage extends DisplayObjectContainer, and you could use that chunk of code for any DisplayObjectContainer (MovieClip, Sprite) as well. I should also mention that we're talking AS3. --Matt On Tue, Jun 2, 2009 at 10:38 AM, Gustavo Duenas LRS < gdue...@leftandrightsolutions.com> wrote: in this case what is container? is stage.? like this if(stage.contains(contactWindow)){ stage.removeChild(contactWindow); } is like this, if not please explain me what this container is about. Gustavo On Jun 2, 2009, at 12:07 PM, Matt Gitchell wrote: if (container.contains(itemToRemove)){ container.removeChild(itemToRemove); }; On Tue, Jun 2, 2009 at 8:45 AM, Gustavo Duenas LRS < gdue...@leftandrightsolutions.com> wrote: Hi I have movie clips, that are created one I click a button, I'd like to know how could I remove then, something to put in the buttons, problem is when I try to remove the movieclip from the stage(I put the orders en every single button I have there), it says that is not created yet, there is a way to know when the movie clip is on there and if this is there just remove it. Like if(stage.movieclipName=true){ removeChild(movieClipName); } there is a way like this or something else around. Regards, Gustavo Duenas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] removing dynamically created movie clips
The container would be the stage in that instance, yes. I used it because Stage extends DisplayObjectContainer, and you could use that chunk of code for any DisplayObjectContainer (MovieClip, Sprite) as well. I should also mention that we're talking AS3. --Matt On Tue, Jun 2, 2009 at 10:38 AM, Gustavo Duenas LRS < gdue...@leftandrightsolutions.com> wrote: > in this case what is container? is stage.? > > > like this > > if(stage.contains(contactWindow)){ > stage.removeChild(contactWindow); > } > > is like this, if not please explain me what this container is about. > > Gustavo > > > > On Jun 2, 2009, at 12:07 PM, Matt Gitchell wrote: > > if (container.contains(itemToRemove)){ >> container.removeChild(itemToRemove); >> }; >> >> On Tue, Jun 2, 2009 at 8:45 AM, Gustavo Duenas LRS < >> gdue...@leftandrightsolutions.com> wrote: >> >> Hi I have movie clips, that are created one I click a button, I'd like to >>> know how could >>> I remove then, something to put in the buttons, problem is when I try to >>> remove >>> the movieclip from the stage(I put the orders en every single button I >>> have >>> there), it says that is not created yet, there is a way to know when the >>> movie clip is on there and if this is there >>> just remove it. >>> >>> Like if(stage.movieclipName=true){ >>> removeChild(movieClipName); >>> } >>> >>> there is a way like this or something else around. >>> >>> >>> Regards, >>> >>> >>> Gustavo Duenas >>> >>> >>> >>> ___ >>> Flashcoders mailing list >>> Flashcoders@chattyfig.figleaf.com >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >>> >>> ___ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] removing dynamically created movie clips
Hi Glen, thanks do you think can I use: stage.removeChildAt(0); gustavo On Jun 2, 2009, at 12:08 PM, Glen Pike wrote: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ display/DisplayObjectContainer.html#getChildByName() Gustavo Duenas LRS wrote: Hi I have movie clips, that are created one I click a button, I'd like to know how could I remove then, something to put in the buttons, problem is when I try to remove the movieclip from the stage(I put the orders en every single button I have there), it says that is not created yet, there is a way to know when the movie clip is on there and if this is there just remove it. Like if(stage.movieclipName=true){ removeChild(movieClipName); } there is a way like this or something else around. Regards, Gustavo Duenas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] removing dynamically created movie clips
in this case what is container? is stage.? like this if(stage.contains(contactWindow)){ stage.removeChild(contactWindow); } is like this, if not please explain me what this container is about. Gustavo On Jun 2, 2009, at 12:07 PM, Matt Gitchell wrote: if (container.contains(itemToRemove)){ container.removeChild(itemToRemove); }; On Tue, Jun 2, 2009 at 8:45 AM, Gustavo Duenas LRS < gdue...@leftandrightsolutions.com> wrote: Hi I have movie clips, that are created one I click a button, I'd like to know how could I remove then, something to put in the buttons, problem is when I try to remove the movieclip from the stage(I put the orders en every single button I have there), it says that is not created yet, there is a way to know when the movie clip is on there and if this is there just remove it. Like if(stage.movieclipName=true){ removeChild(movieClipName); } there is a way like this or something else around. Regards, Gustavo Duenas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] removing dynamically created movie clips
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#getChildByName() Gustavo Duenas LRS wrote: Hi I have movie clips, that are created one I click a button, I'd like to know how could I remove then, something to put in the buttons, problem is when I try to remove the movieclip from the stage(I put the orders en every single button I have there), it says that is not created yet, there is a way to know when the movie clip is on there and if this is there just remove it. Like if(stage.movieclipName=true){ removeChild(movieClipName); } there is a way like this or something else around. Regards, Gustavo Duenas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] removing dynamically created movie clips
if (container.contains(itemToRemove)){ container.removeChild(itemToRemove); }; On Tue, Jun 2, 2009 at 8:45 AM, Gustavo Duenas LRS < gdue...@leftandrightsolutions.com> wrote: > Hi I have movie clips, that are created one I click a button, I'd like to > know how could > I remove then, something to put in the buttons, problem is when I try to > remove > the movieclip from the stage(I put the orders en every single button I have > there), it says that is not created yet, there is a way to know when the > movie clip is on there and if this is there > just remove it. > > Like if(stage.movieclipName=true){ > removeChild(movieClipName); > } > > there is a way like this or something else around. > > > Regards, > > > Gustavo Duenas > > > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] removing dynamically created movie clips
Hi I have movie clips, that are created one I click a button, I'd like to know how could I remove then, something to put in the buttons, problem is when I try to remove the movieclip from the stage(I put the orders en every single button I have there), it says that is not created yet, there is a way to know when the movie clip is on there and if this is there just remove it. Like if(stage.movieclipName=true){ removeChild(movieClipName); } there is a way like this or something else around. Regards, Gustavo Duenas ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Crossword generator advice
You may want to also set something to read how many of those letters are in the word that match the letter your using in the one your placing. This may give you a few more options on placement. Karl On Jun 2, 2009, at 6:34 AM, Paul Andrews wrote: Off the top of my head.. For a horizontal overlap of a word, the new word can only be placed in a very few places - no further left than the leftmost position of the wordlaready placed and no further right than the new word can be placed without going off the grid, or not overlapping the rightmost position of the placed word. Similarly for vertical positions. This drastically reduces your placement options. for a connected only crossword, the overlap must be as above and for every placed word where an overlap occurs, characters must match with the new word where they overlap. Essentially we have: For each already placed word if new word can overlap try placement for valid positions of new world for each placement compare overlap charaters for equality. Maybe this should now be off-list - it has nothing to do with flash! Paul Paul Steven wrote: Thanks Paul for your reply. You may be right about my placement checker. What I currently do is as follows: Starting with first char of word I want to place, loop through the characters of each word that is already on the puzzle and see if a match can be found. If a match is found then I calculate where the new word would appear on the grid based on crossing the existing word where they characters match. I then check if there are any words in the way or the new word goes off the grid. I also check that the new word is not adjacent to another word My code does not allow words to be added unless they cross another word so perhaps allowing disconnected placement would speed things up. I will give it a try. Thanks again for your help on this. Paul ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Crossword generator advice
Off the top of my head.. For a horizontal overlap of a word, the new word can only be placed in a very few places - no further left than the leftmost position of the wordlaready placed and no further right than the new word can be placed without going off the grid, or not overlapping the rightmost position of the placed word. Similarly for vertical positions. This drastically reduces your placement options. for a connected only crossword, the overlap must be as above and for every placed word where an overlap occurs, characters must match with the new word where they overlap. Essentially we have: For each already placed word if new word can overlap try placement for valid positions of new world for each placement compare overlap charaters for equality. Maybe this should now be off-list - it has nothing to do with flash! Paul Paul Steven wrote: Thanks Paul for your reply. You may be right about my placement checker. What I currently do is as follows: Starting with first char of word I want to place, loop through the characters of each word that is already on the puzzle and see if a match can be found. If a match is found then I calculate where the new word would appear on the grid based on crossing the existing word where they characters match. I then check if there are any words in the way or the new word goes off the grid. I also check that the new word is not adjacent to another word My code does not allow words to be added unless they cross another word so perhaps allowing disconnected placement would speed things up. I will give it a try. Thanks again for your help on this. Paul ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Crossword generator advice
Thanks Paul for your reply. You may be right about my placement checker. What I currently do is as follows: Starting with first char of word I want to place, loop through the characters of each word that is already on the puzzle and see if a match can be found. If a match is found then I calculate where the new word would appear on the grid based on crossing the existing word where they characters match. I then check if there are any words in the way or the new word goes off the grid. I also check that the new word is not adjacent to another word My code does not allow words to be added unless they cross another word so perhaps allowing disconnected placement would speed things up. I will give it a try. Thanks again for your help on this. Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: 02 June 2009 11:54 To: Flash Coders List Subject: Re: [Flashcoders] Crossword generator advice Paul Steven wrote: > Here is a link to the crossword generator in its current state. > > http://www.mediakitchen.co.uk/crossword.html > > Cheers > > Paul > > -Original Message- > From: flashcoders-boun...@chattyfig.figleaf.com > [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven > Sent: 02 June 2009 10:27 > To: 'Flash Coders List' > Subject: RE: [Flashcoders] Crossword generator advice > > Sorry to drag this one out but I have one last question. > > I implemented the recursive solution as Paul Andrews and Charles suggested > however I find that it can take up to 8 minutes to generate a solution > (which incidentally is pretty much the same amount of time my non recursive > implementation takes) > I think there's a problem in the algorithm again or you have a very inefficient placement checker. A definite improvement to my suggestion would be to have a two stage placement algorithm - first of all only laying out words if they overlap another word, then if no solution is found by laying out the word as an overlap, it would then attempt a disconnected placement. I think that would improve things. It's difficullt to know why it takes so long without seeing the code. Paul > If I order my words from largest to smallest first this actually seems to > result in a longer time. I am thinking this is perhaps because one of the > longest words (tarragon) is at the bottom of the solution: > http://www.mediakitchen.co.uk/solution.gif > > Anyway I do not mind it taking so long as a new crossword will only be > generated once a week. However I am curious as to whether this sounds like a > flaw in my code or if it is just the result of having to try so many > combinations to find the unique solution? > > If I adjust my list of words into the order in which it looks like they > would be placed one at a time onto the grid, then the solution only takes > about 3 seconds to generate. > > Because I know there is the possibility that having the list ordered in a > particular way can result in a super fast puzzle creation time, I am > wondering if it is worth just randomising the list every 10 seconds if a > solution has not been found? > > Promise not to ask any more questions about this crossword generator after > this one:) > > Thanks > > Paul > > -Original Message- > From: flashcoders-boun...@chattyfig.figleaf.com > [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews > Sent: 01 June 2009 11:14 > To: Flash Coders List > Subject: Re: [Flashcoders] Crossword generator advice > > You should use recursion. > > At each stage you should loop through the available words, trying to lay > them onto the crossword area. > > Paul > > It goes a bit like this: > > var wordList = ["word1","word2","word3", .. ]; > var xwordSolution:XwordSolution; > var currentSolution= new XwordSolution(maxWidth, maxHeight); // emptyGrid > > xwordSolution = layoutXword(wordList, currentSolution); > > if (xwordSolution.isValid()) > trace("Solved!") > else > trace("no solution found"); > > function layoutXword(words:Array, > currentSolution:XwordSolution):XwordSolution > { > while (words.length > 0){ > currentWord = words.pop(); > > // horizontal > > newSolution = layoutHorizontalWord(currentWord, currentSolution); > if (newSolution.isValid()) > { > newSolution = layoutXword(words, newSolution ); > if (newSolution.isValid()) > return newSolution; // solved > } > // the horizontal layout wasn't possible, try vertical > newSolution = layoutVerticalWord(currentWord, currentSolution); > if (newSolution.isValid()) > { > newSolution = layoutXword(words, newSolution ); > if (newSolution.isValid()) > return newSolution; // solved > } > // couldn't layout this word, try the next > } > // Couldn't layout any of the words - solution failed. > return newSolution; // this will be failed > } > > > > > > > > > > > > > > > > > > > > - Original Message - >
Re: [Flashcoders] Crossword generator advice
Paul Steven wrote: Here is a link to the crossword generator in its current state. http://www.mediakitchen.co.uk/crossword.html Cheers Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven Sent: 02 June 2009 10:27 To: 'Flash Coders List' Subject: RE: [Flashcoders] Crossword generator advice Sorry to drag this one out but I have one last question. I implemented the recursive solution as Paul Andrews and Charles suggested however I find that it can take up to 8 minutes to generate a solution (which incidentally is pretty much the same amount of time my non recursive implementation takes) I think there's a problem in the algorithm again or you have a very inefficient placement checker. A definite improvement to my suggestion would be to have a two stage placement algorithm - first of all only laying out words if they overlap another word, then if no solution is found by laying out the word as an overlap, it would then attempt a disconnected placement. I think that would improve things. It's difficullt to know why it takes so long without seeing the code. Paul If I order my words from largest to smallest first this actually seems to result in a longer time. I am thinking this is perhaps because one of the longest words (tarragon) is at the bottom of the solution: http://www.mediakitchen.co.uk/solution.gif Anyway I do not mind it taking so long as a new crossword will only be generated once a week. However I am curious as to whether this sounds like a flaw in my code or if it is just the result of having to try so many combinations to find the unique solution? If I adjust my list of words into the order in which it looks like they would be placed one at a time onto the grid, then the solution only takes about 3 seconds to generate. Because I know there is the possibility that having the list ordered in a particular way can result in a super fast puzzle creation time, I am wondering if it is worth just randomising the list every 10 seconds if a solution has not been found? Promise not to ask any more questions about this crossword generator after this one:) Thanks Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: 01 June 2009 11:14 To: Flash Coders List Subject: Re: [Flashcoders] Crossword generator advice You should use recursion. At each stage you should loop through the available words, trying to lay them onto the crossword area. Paul It goes a bit like this: var wordList = ["word1","word2","word3", .. ]; var xwordSolution:XwordSolution; var currentSolution= new XwordSolution(maxWidth, maxHeight); // emptyGrid xwordSolution = layoutXword(wordList, currentSolution); if (xwordSolution.isValid()) trace("Solved!") else trace("no solution found"); function layoutXword(words:Array, currentSolution:XwordSolution):XwordSolution { while (words.length > 0){ currentWord = words.pop(); // horizontal newSolution = layoutHorizontalWord(currentWord, currentSolution); if (newSolution.isValid()) { newSolution = layoutXword(words, newSolution ); if (newSolution.isValid()) return newSolution; // solved } // the horizontal layout wasn't possible, try vertical newSolution = layoutVerticalWord(currentWord, currentSolution); if (newSolution.isValid()) { newSolution = layoutXword(words, newSolution ); if (newSolution.isValid()) return newSolution; // solved } // couldn't layout this word, try the next } // Couldn't layout any of the words - solution failed. return newSolution; // this will be failed } - Original Message - From: "Paul Steven" To: "'Flash Coders List'" Sent: Monday, June 01, 2009 10:33 AM Subject: RE: [Flashcoders] Crossword generator advice I am still struggling to find a solution to this crossword generator and could do with some advice on a possible solution I want to try. If I enter my list of 16 words in a particular order (an order based on what looks like the order the solution would place them), the generator creates the puzzle in a matter of seconds. However if I enter them in a different order, the generator always breaks out of the loop by my exit condition (number of loops > 5000). I am assuming this is either due to an error in my code or due to the fact there are so many combinations to try. I am therefore thinking a possible solution is to try every permutation (I think this is the right word) of the 16 words. If I am correct there would be 240 possible permutations. ((X - 1) * X) where X is the number of items in the list. I am not sure however how to create the 240 variations of the list. Any advice on how to create these 240 permutations of the list would be much appreciated. Thanks Paul ___ Flashcoders mailing
Re: [Flashcoders] Need beta testers!
No one is interested? That really breaks my heart ;) You dont have to check it out in SVN, just browse the source and give me feedback, code wise, structure wise, best way/different way to parse files, comments, suggestions etc I want to learn dammit ;) Greets Sid On May 27, 2009, at 9:55 AM, Sidney de Koning wrote: Hi List, I have created a very simple PLS parser (playlist file, used in Winamp and other programs) for AIR. And would like to invite people to use it and give me feedback, code wise, structure wise, best way/different way to parse files, comments, suggestions etc What can you do with this? You can listen to radio streams in AIR. So if there is somebody who would like to test this, check out the source at http://code.google.com/p/as3plsreader Hoping for some reactions, both bad and good, Sid Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Crossword generator advice
Here is a link to the crossword generator in its current state. http://www.mediakitchen.co.uk/crossword.html Cheers Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven Sent: 02 June 2009 10:27 To: 'Flash Coders List' Subject: RE: [Flashcoders] Crossword generator advice Sorry to drag this one out but I have one last question. I implemented the recursive solution as Paul Andrews and Charles suggested however I find that it can take up to 8 minutes to generate a solution (which incidentally is pretty much the same amount of time my non recursive implementation takes) If I order my words from largest to smallest first this actually seems to result in a longer time. I am thinking this is perhaps because one of the longest words (tarragon) is at the bottom of the solution: http://www.mediakitchen.co.uk/solution.gif Anyway I do not mind it taking so long as a new crossword will only be generated once a week. However I am curious as to whether this sounds like a flaw in my code or if it is just the result of having to try so many combinations to find the unique solution? If I adjust my list of words into the order in which it looks like they would be placed one at a time onto the grid, then the solution only takes about 3 seconds to generate. Because I know there is the possibility that having the list ordered in a particular way can result in a super fast puzzle creation time, I am wondering if it is worth just randomising the list every 10 seconds if a solution has not been found? Promise not to ask any more questions about this crossword generator after this one:) Thanks Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: 01 June 2009 11:14 To: Flash Coders List Subject: Re: [Flashcoders] Crossword generator advice You should use recursion. At each stage you should loop through the available words, trying to lay them onto the crossword area. Paul It goes a bit like this: var wordList = ["word1","word2","word3", .. ]; var xwordSolution:XwordSolution; var currentSolution= new XwordSolution(maxWidth, maxHeight); // emptyGrid xwordSolution = layoutXword(wordList, currentSolution); if (xwordSolution.isValid()) trace("Solved!") else trace("no solution found"); function layoutXword(words:Array, currentSolution:XwordSolution):XwordSolution { while (words.length > 0){ currentWord = words.pop(); // horizontal newSolution = layoutHorizontalWord(currentWord, currentSolution); if (newSolution.isValid()) { newSolution = layoutXword(words, newSolution ); if (newSolution.isValid()) return newSolution; // solved } // the horizontal layout wasn't possible, try vertical newSolution = layoutVerticalWord(currentWord, currentSolution); if (newSolution.isValid()) { newSolution = layoutXword(words, newSolution ); if (newSolution.isValid()) return newSolution; // solved } // couldn't layout this word, try the next } // Couldn't layout any of the words - solution failed. return newSolution; // this will be failed } - Original Message - From: "Paul Steven" To: "'Flash Coders List'" Sent: Monday, June 01, 2009 10:33 AM Subject: RE: [Flashcoders] Crossword generator advice >I am still struggling to find a solution to this crossword generator and > could do with some advice on a possible solution I want to try. > > If I enter my list of 16 words in a particular order (an order based on > what > looks like the order the solution would place them), the generator creates > the puzzle in a matter of seconds. > > However if I enter them in a different order, the generator always breaks > out of the loop by my exit condition (number of loops > 5000). I am > assuming > this is either due to an error in my code or due to the fact there are so > many combinations to try. > > I am therefore thinking a possible solution is to try every permutation (I > think this is the right word) of the 16 words. If I am correct there would > be 240 possible permutations. ((X - 1) * X) where X is the number of items > in the list. > > I am not sure however how to create the 240 variations of the list. > > Any advice on how to create these 240 permutations of the list would be > much > appreciated. > > Thanks > > Paul > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _
RE: [Flashcoders] Crossword generator advice
Sorry to drag this one out but I have one last question. I implemented the recursive solution as Paul Andrews and Charles suggested however I find that it can take up to 8 minutes to generate a solution (which incidentally is pretty much the same amount of time my non recursive implementation takes) If I order my words from largest to smallest first this actually seems to result in a longer time. I am thinking this is perhaps because one of the longest words (tarragon) is at the bottom of the solution: http://www.mediakitchen.co.uk/solution.gif Anyway I do not mind it taking so long as a new crossword will only be generated once a week. However I am curious as to whether this sounds like a flaw in my code or if it is just the result of having to try so many combinations to find the unique solution? If I adjust my list of words into the order in which it looks like they would be placed one at a time onto the grid, then the solution only takes about 3 seconds to generate. Because I know there is the possibility that having the list ordered in a particular way can result in a super fast puzzle creation time, I am wondering if it is worth just randomising the list every 10 seconds if a solution has not been found? Promise not to ask any more questions about this crossword generator after this one:) Thanks Paul -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: 01 June 2009 11:14 To: Flash Coders List Subject: Re: [Flashcoders] Crossword generator advice You should use recursion. At each stage you should loop through the available words, trying to lay them onto the crossword area. Paul It goes a bit like this: var wordList = ["word1","word2","word3", .. ]; var xwordSolution:XwordSolution; var currentSolution= new XwordSolution(maxWidth, maxHeight); // emptyGrid xwordSolution = layoutXword(wordList, currentSolution); if (xwordSolution.isValid()) trace("Solved!") else trace("no solution found"); function layoutXword(words:Array, currentSolution:XwordSolution):XwordSolution { while (words.length > 0){ currentWord = words.pop(); // horizontal newSolution = layoutHorizontalWord(currentWord, currentSolution); if (newSolution.isValid()) { newSolution = layoutXword(words, newSolution ); if (newSolution.isValid()) return newSolution; // solved } // the horizontal layout wasn't possible, try vertical newSolution = layoutVerticalWord(currentWord, currentSolution); if (newSolution.isValid()) { newSolution = layoutXword(words, newSolution ); if (newSolution.isValid()) return newSolution; // solved } // couldn't layout this word, try the next } // Couldn't layout any of the words - solution failed. return newSolution; // this will be failed } - Original Message - From: "Paul Steven" To: "'Flash Coders List'" Sent: Monday, June 01, 2009 10:33 AM Subject: RE: [Flashcoders] Crossword generator advice >I am still struggling to find a solution to this crossword generator and > could do with some advice on a possible solution I want to try. > > If I enter my list of 16 words in a particular order (an order based on > what > looks like the order the solution would place them), the generator creates > the puzzle in a matter of seconds. > > However if I enter them in a different order, the generator always breaks > out of the loop by my exit condition (number of loops > 5000). I am > assuming > this is either due to an error in my code or due to the fact there are so > many combinations to try. > > I am therefore thinking a possible solution is to try every permutation (I > think this is the right word) of the 16 words. If I am correct there would > be 240 possible permutations. ((X - 1) * X) where X is the number of items > in the list. > > I am not sure however how to create the 240 variations of the list. > > Any advice on how to create these 240 permutations of the list would be > much > appreciated. > > Thanks > > Paul > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders