Rounding down calculations

I have 10 points to distribute between 0-6 players depending on how many of their pieces have been placed on certain locations in an area. Say 3 players have an equal number of pieces there, they get 3 points each. This calculation is done for about 20 different areas, with 4-8 locations in each area, so there are lot of possible outcomes.

Do I need to write ? : strings for each location, for each possible combination and outcome? Or is there a more concise way to write the calculation and round down?

Like, here’s a draft example I wrote to calculate just “r’s” score for area 1 with 4 locations, where I first calculated totals 1r, 1b etc. for how many pieces each player has in the area:

1r==0 ? 0 : 1r>0&&1b+1g+1y+1k+1e=0 ? 10 : 1r==(1b+1g+1y+1k+1e) ? 5 : 1r==1&&1b+1g+1y+1k+1e=2 ? 3 : 1r==1&&1b+1g+1y+1k+1e=3 ? 2 : 1r==2&&1b+1g+1y+1k+1e=1 ? 6 : 1r==3&&1b+1g+1y+1k+1e=1 ? 7

This gives me outcomes in rough order of likelihood: 0, 10, 5, 3, 2, 6, 7, and will work, but repeat 6 times for each of 20 locations, and it’s a chore to write out.

Any tips?

Unless I’m not fully understanding what you’re trying to do, Vassal automatically rounds down and throws out remainders unless you get sophisticated with it.

For example, if you have a formula that is x = y/3 than, x will return 3 if y is 9, 10 or 11. It won’t return 4 until y hits 12. In other words, it returns the whole number only and throws out the remainder.

Does that help?

It certainly does! So, as long as I calculate each set of 10 as a GP before adding them together, it should work.

OK, now I need to know how to “get sophisticated with it”.

I have the following for the point calculation:

((GetProperty("1r")==0) ? 0 : (10*(GetProperty("1r")/(GetProperty("1r")+GetProperty("1b")+GetProperty("1g")+GetProperty("1y")+GetProperty("1k")+GetProperty("1e")))))

So if 1r is 0 it returns 0.

If 1r is not zero, it is supposed to calculate 10 x the ratio of 1r to all 6 of the colours. In practice, it returns 10 when only 1r is positive, but 0 if any other colour is positive. I guess because the ratio is rounded down to 0 before being multiplied by 10? Seems odd. How can I do this the right way?

Are all of those properties guaranteed to have a numeric value? If any of them don’t, the whole thing will end up being treated as a string instead of a number…

Also, I’m not clear on why you’re even using GetProperty, rather than referencing the properties directly…

Yes, they can only be numeric values.

Neither am I. For some reason that’s what the expression builder does. Perhaps because the global properties start with a numeral?

It shouldn’t make any difference (according to the java order of operations), but have you tried an extra set of parentheses around the “10*1r” bit of the calculation?

Oops. Just looked closer at your formula, and it isn’t working because you already have an extra set of parentheses in there that don’t belong…you’re forcing the division to occur before the multiplication!

Thanks, obvious solution but I needed someone to point it out!