- there are n integers in the sequence
- the sum of the integers in the sequence is x
- the value of each integer in the sequence is between 1 and 6, inclusive
There are a couple of things that I'm not following.
1. Does the board have a static number of spaces?
2. Are there a set number of turns, or can it take as long as it takes?
3. Why do you need to know all of the rolls in advance, can't you just make
your "roll" function ensure that the last roll is always exactly the right
number of spaces?
The following function will generate a (semi-) random number from 1 to
6, and always cause the last roll to land exactly on the last game board
space:
function roll(current:Number):Number{
var iBoardSize:Number = 50; // 50 spaces on the board
current = (current==undefined)?0:current; // make sure current is set
var maxroll:Number = iBoardSize - current; // largest number you can
roll
var r:Number = Math.floor(Math.random()*5)+1; // generate random number
r = (r>maxroll)?maxroll:r; // if roll is larger than maxroll, substitute
maxroll
return(r);
}
Prior to the last 6 spaces, the roll can never be larger than maxroll,
because maxroll will be like 35 and the roll is only 1-6. But on the last 6
spaces, it is possible for the roll to be higher than the last space, so you
substitute maxroll. It gets more complicated if you need to know all the
roll sin advance, or if there are always a set number of turns, etc, but not
too much more complicated.
ryanm
_______________________________________________
[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