What Scoring 100 Actually Means
The next post in the math sub-series, promised at the end of Z-up in a Y-down World. Less geometry this time. If you can take a weighted average and a percentage, you have everything this post needs. Every number below comes from the code or a unit test, and I checked the arithmetic before writing it down.
The number on the inspector
Open a tree’s inspector and it says something like Score: 66 / 100, with the criteria and their points underneath. A tree sells for twice its score in coins. The game never stores the score. It is worked out fresh from the tree every time, one of the prototype’s invariants (“scoring derived, never persisted”), so it is a pure function: tree in, number out. We can ask what it does.
The function is scoreTree in src/sim/scoring.ts. It is a straight port of score_tree in the GameMaker prototype’s scr_scoring.gml, with the same numbers.
Six criteria, each squeezed into 0 to 1
The score starts from six measurements in different units, so the first job is a common scale: every criterion becomes a number from 0 (bad) to 1 (ideal). Two helper shapes do almost all of that.
The band. scoreBand(value, lo, hi, falloff) is 1 anywhere inside [lo, hi], then falls in a straight line to 0 over falloff units on either side. Its graph is a flat-topped hill with sloping sides. The test pins it on the branch-count band: 2 branches score 0.75, 9 score 0.5, 11 score 0.
The bell. scoreGauss(value, target, sigma) is exp(-(value - target)² / (2 sigma²)). That is 1 exactly at the target and smaller everywhere else; one sigma away it is exp(-0.5), about 0.61. Its graph is a bell curve with a single peak and no flat top.
The six criteria, all at weight 1.0:
- Trunk taper: bell at 0.6, sigma 0.2.
- Trunk proportion:
heightCm × 10 / girthMm, a band from 6 to 10 with falloff 5. Height is in centimetres and girth in millimetres, so the× 10makes the units match. - Branch count: band from 3 to 7, falloff 4.
- Angular spread: put a unit arrow at each branch’s compass angle and average them. The length of the average arrow is 1 when every branch points the same way and 0 when they balance out. The criterion is
1 - length. - Vertical spread: the standard deviation of each branch’s height as a fraction of the trunk, under a bell at 0.3, sigma 0.15. With exactly one branch it is a flat 0.3, a consolation value rather than a measurement.
- Foliage: density in a band from 0.3 to 0.7, falloff 0.3.
The weighted average, and why the weights need not sum to 1
The criteria are combined as
base = (v1 w1 + v2 w2 + ... ) / (w1 + w2 + ...)
which is a weighted average. Because it divides by the sum of the weights, the weights do not have to add up to 1 or to 100. Only their ratios matter. With six criteria at weight 1.0 the sum is 6, and each criterion is worth one sixth of the score. Double every weight and nothing changes.
That also makes base a value between 0 and 1. An average of numbers in [0, 1] cannot leave [0, 1]. It is 1 exactly when every criterion is 1, and 0 exactly when every criterion with weight is 0.
Moving one weight moves every criterion’s share. A criterion with weight w among others summing to W gets w / (W + w) of the score. That is where the seventh criterion comes in.
Style as a plug-in
If the player sets a target style, the scorer looks it up and adds one more criterion at weight 1.5. Each style in src/sim/styles.ts is data: a key, a name, a description and a score(tree) function that returns its own 0 to 1 conformance. The scorer does not know what any style measures. It only asks for a number.
Windswept returns the length of the average branch arrow from criterion 4, given two or more branches; with fewer it returns a flat 0.5, the same kind of consolation value as vertical spread’s. Formal upright sorts the branches by height and rewards each neighbouring pair for pointing in opposite directions. Informal upright, slanting and broom multiply two factors, so either one at 0 sinks the lot.
With a style the weights sum to 6 + 1.5 = 7.5. The style’s share is 1.5 / 7.5, exactly 20 percent, and each base criterion drops from one sixth to 1 / 7.5, about 13.3 percent.
So choosing a style can lower the score. Adding a criterion with value v raises the average only if v is above the current average. The prototype’s comment says it plainly: a style is “a real commitment that can pull the score up or down”.
The vitality multiplier
Last comes health:
total = base × (vitality / 100) × 100
then Math.floor. Vitality runs from 0 to 100 (the daily tick in growth.ts clamps it there), so the multiplier runs from 0 to 1.
This is a multiplication, not an eighth term, and the difference shows at the extremes. If vitality were a seventh criterion at weight 1, a perfectly shaped tree at vitality 0 would still keep six sevenths of its score. As a multiplier, vitality 0 takes the score to 0, whatever the shape. At vitality 100 it changes nothing. In between it scales every criterion’s points by the same factor, so the breakdown keeps its proportions and only shrinks. The inspector shows it as a separate line, x 1.00, rather than as points.
A worked example: the fresh cutting
The unit test scores a fresh cutting at the hand-computed total uses a new juniper cutting from createTree: trunk 8 cm tall, 4 mm girth, taper 0.7; branches at 3 cm and 5 cm up, pointing at 45 and 225 degrees; foliage 0.25; vitality 100.
| Criterion | Input | Value | Points |
|---|---|---|---|
| Trunk taper | 0.7, target 0.6 | 0.8825 | 14.71 |
| Trunk proportion | 8 × 10 / 4 = 20 | 0 | 0.00 |
| Branch count | 2 | 0.75 | 12.50 |
| Angular spread | 45 and 225, opposite | 1 | 16.67 |
| Vertical spread | 3/8 and 5/8, sd 0.125 | 0.5063 | 8.44 |
| Foliage | 0.25, 0.05 below the band | 0.8333 | 13.89 |
The values sum to 3.9722. Divided by 6 that is 0.6620, so the total is 66.20 and the inspector shows 66. At vitality 50 the test expects 33: half of 66.20 is 33.10, floored.
Now give the same cutting a style. Its two branches point in opposite directions, so formal upright scores 1 and windswept scores 0:
formal upright: (3.9722 + 1.5) / 7.5 = 0.7296 -> 72
windswept: (3.9722 + 0) / 7.5 = 0.5296 -> 52
Same tree, same day, three scores: 52, 66 or 72, depending only on what the player says they are aiming for.
So what would 100 take?
A weighted average of numbers in [0, 1] equals 1 only when every one of them is 1. Times a vitality multiplier of exactly 1. And because of the floor, 99.99 still shows 99. So a 100 needs every criterion exactly perfect at once, and vitality exactly 100.
Most of that is reachable in principle. The bands have flat tops, so trunk proportion, branch count and foliage can sit at 1 with room to spare. Vitality recovers 0.3 a day while the water is between 10 and 90, up to 100.
The bells are harder. They are 1 only at a single point. Vertical spread would need a standard deviation of exactly 0.3, and branch heights are fixed in centimetres while the trunk keeps growing, so the fraction drifts every day. Even angular spread trips on arithmetic: I put three branches at 0, 120 and 240 degrees, which should balance perfectly, and the computer gave 0.9999999999999999. The rounding error in the cosines leaves a sliver.
Then there is the criterion that settles it. Trunk taper is 0.7 on every tree the game creates, and nothing in the simulation ever changes it. I searched src/sim: createTree sets it, the save importer reads it, the geometry draws it and the scorer scores it. No growth, wire, clip, prune or repot touches it. The prototype is the same, 0.7 in scr_bonsai_struct.gml and never written again. So taper is stuck at 0.8825 forever, and the best possible total is
no style: (5 + 0.8825) / 6 = 0.9804 -> 98
with style: (6.5 + 0.8825) / 7.5 = 0.9843 -> 98
So 100 is not an asymptote you creep towards. It is a point outside the reachable set. A grown tree tops out at 98, and with a style only if the other criteria together fall short of perfect by less than half a point (0.43). Without a style the margin is 0.04 points. Only a save edited to a taper of exactly 0.6 could do better. The one other taper in either codebase is the title screen’s hero tree, at 0.62, which is only there to be drawn.
Odd things I noticed
Two criteria fight. Windswept’s style value is the length of the average branch arrow. Angular spread is 1 minus that same length. For a windswept tree with two or more branches they always sum to 1, so the more windswept the tree, the worse its spread. With everything else perfect the best windswept tree reaches (0.8825 + 4 + 1.5) / 7.5 = 0.8510, so 85. The windswept player is fighting the rubric by design.
Proportion is a window in time. The daily tick adds 0.02 cm of height and 0.05 mm of girth for each unit of its growth multiplier, so the ratio height × 10 / girth drifts towards 0.2 / 0.05 = 4. A cutting starts at 20, passes through the 6 to 10 band once, and leaves it on the low side. Once the trunk reaches its species’ maximum (45 cm for a juniper), height stops and the ratio keeps falling. Proportion is a criterion you can only enjoy for a while.
A stale comment in the prototype. The GML says styles without a score function are skipped. By the end all six had one, so the port only skips an unknown style key. DESIGN.md says nothing about scoring, so the code and its tests are the only spec.
Coming next
When the loop disappears: the trunk needed a step-by-step walk and a branch got a closed form, and a look at why the same kind of curve asked for two different kinds of maths.