Game Development Reference
In-Depth Information
sort value is the first dimension. In our case, the first dimension is the value of the move, so we
can use sortOn to put the moves in ascending order.
dieSets.sortOn("0",Array.NUMERIC);
Here is the traced output of dieSets array after it has been sorted (with labels added to each
value for illustration):
Sorted Moves: 18
Value:1 Row:1 Col:3
Value:1 Row:2 Col:1
Value:2 Row:4 Col:0
Value:3 Row:3 Col:0
Value:4 Row:2 Col:0
Value:4 Row:0 Col:3
Value:5 Row:0 Col:0
Value:5 Row:4 Col:1
Value:6 Row:1 Col:0
Value:6 Row:0 Col:2
Value:6 Row:4 Col:5
Value:6 Row:1 Col:4
Value:6 Row:0 Col:4
Value:8 Row:2 Col:3
Value:10 Row:3 Col:3
Value:20 Row:3 Col:2
Value:24 Row:4 Col:3
Value:24 Row:4 Col:4
Next, we strip out all the like values from the list of moves to makes our calculation even easier.
There is no reason why we need to choose from several moves that have the same value.
Performing this action is quite easy. We created a lastValue variable that we will set in a for loop
that loops through all the moves in order by value (remember we just sorted the array). If the
current value of the move is the same as lastValue , we splice it out of the array because we
don't need it.
var lastValue:Number = 0;
for (var ii:int = dieSets.length-1; ii >= 0; ii--) {
if (dieSets[ii][0] == lastValue) {
dieSets.splice(ii,1);
} else {
lastValue = dieSets[ii][0];
}
}
Here is the traced output of dieSets array after we have removed all the like values (with labels
added to each value for illustration):
No Like Values Moves:10
Value:1 Row:2 Col:1
Value:2 Row:4 Col:0
Value:3 Row:3 Col:0
Value:4 Row:0 Col:3
Value:5 Row:4 Col:1
Value:6 Row:0 Col:4
Value:8 Row:2 Col:3
Value:10 Row:3 Col:3
Search WWH ::




Custom Search