At 10:50 AM +0100 7/19/06, Danny Kodicek wrote:
> I get the impression it is a set number of turns. In that case,
you'll need
to be a bit canny, doing something like biasing the roll according to the
distance to the goal.
I enjoyed this problem way too much, so I've written an implementation (in
Lingo, I'm afraid - it's my first language. But it should be easy enough to
follow)
Danny,
Wow! Thanks. I ended up doing something much simpler, basically
because I don't really care too much about the apparent distribution.
Yours is way more elegant.
Here's what I did. In pseudo-code (mostly because I'm embarrassed
this is still AS1):
----
To move S squares in N turns
- Fill an array of length N with random numbers
- While the sum of array members' values does not equal S:
* Sort the array
* Calculate the difference between S and the sum
* If the difference is positive, increase the value of the
first array member by the difference or by 5, whichver is
smaller
* If the difference is negative, decrease the value of the
last array member by the difference or by 5, whichever is
smaller
- Sort the array
- If the last array member is smaller than the number of spaces
to move plus one minus the number of remaining turns, start over
- Remove the last array member and store in a variable
- Randomize the array order, then push the last member to the array
----
I'm not 100% sure this will work, especially the test near the end to
determine if the final roll is big enough to allow extra turns to be
added.
Thanks again.
-Jim
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com