feat: show Power as the complement of miss chance
Displayed Power is 1 − missChance / 0.60, as a percentage, in both the JS and PHP displayValues used by the planet picker, the HUD and the lobby. 0% miss shows as 100% Power. Gameplay power() and missChance() are unchanged (60% miss at 0, 5% at 1), so Cinder displays 92% and Terra 44%. Tests and Playwright strings follow.
@@ -75,10 +75,20 @@ final class Planets
75
75
return ($gravity + $air + $mass) / 3;
76
76
}
77
77
78
/** Miss chance: 0.60 at power 0, 0.05 at power 1. */
78
/** Maximum miss chance; displayed Power is 1 − miss / MAX_MISS_CHANCE. */
79
public const MAX_MISS_CHANCE = 0.60;
80
public const MIN_MISS_CHANCE = 0.05;
81
82
/** Miss chance: 0.60 at power 0, 0.05 at power 1. Unchanged gameplay formula. */
79
83
public static function missChance(array $planet): float
80
84
{
81
return 0.60 - 0.55 * self::power($planet);
85
return self::MAX_MISS_CHANCE - (self::MAX_MISS_CHANCE - self::MIN_MISS_CHANCE) * self::power($planet);
86
}
87
88
/** Displayed Power 0–100: 0% miss → 100% Power, 60% miss → 0% Power. */
89
public static function displayPower(array $planet): int
90
{
91
return (int) round((1 - self::missChance($planet) / self::MAX_MISS_CHANCE) * 100);
82
92
}
83
93
84
94
public static function missChanceForId(string $id): float
@@ -96,13 +106,12 @@ final class Planets
96
106
$j = self::clamp((float) ($planet['jumpsToClear'] ?? 2), 1, 4);
97
107
$f = self::clamp((float) ($planet['fallTime'] ?? 3), 1, 5);
98
108
$r = self::clamp((float) ($planet['riseTime'] ?? 1.5), 0.5, 3);
99
$power = self::power($planet);
100
109
return [
101
110
'gravity' => 9.81 * $j / 2,
102
111
'density' => 0.25 + ((5 - $f) / 4) * 1.60,
103
112
'newtons' => 40 + (($r - 0.5) / 2.5) * 160,
104
'power' => (int) round($power * 100),
105
'missChance' => 0.60 - 0.55 * $power,
113
'power' => self::displayPower($planet),
114
'missChance' => self::missChance($planet),
106
115
];
107
116
}
108
117
@@ -75,10 +75,20 @@ final class Planets75
return ($gravity + $air + $mass) / 3;75
return ($gravity + $air + $mass) / 3;76
}76
}77
77
78
/** Miss chance: 0.60 at power 0, 0.05 at power 1. */78
/** Maximum miss chance; displayed Power is 1 − miss / MAX_MISS_CHANCE. */79
public const MAX_MISS_CHANCE = 0.60;80
public const MIN_MISS_CHANCE = 0.05;81
82
/** Miss chance: 0.60 at power 0, 0.05 at power 1. Unchanged gameplay formula. */79
public static function missChance(array $planet): float83
public static function missChance(array $planet): float80
{84
{81
return 0.60 - 0.55 * self::power($planet);85
return self::MAX_MISS_CHANCE - (self::MAX_MISS_CHANCE - self::MIN_MISS_CHANCE) * self::power($planet);86
}87
88
/** Displayed Power 0–100: 0% miss → 100% Power, 60% miss → 0% Power. */89
public static function displayPower(array $planet): int90
{91
return (int) round((1 - self::missChance($planet) / self::MAX_MISS_CHANCE) * 100);82
}92
}83
93
84
public static function missChanceForId(string $id): float94
public static function missChanceForId(string $id): float@@ -96,13 +106,12 @@ final class Planets96
$j = self::clamp((float) ($planet['jumpsToClear'] ?? 2), 1, 4);106
$j = self::clamp((float) ($planet['jumpsToClear'] ?? 2), 1, 4);97
$f = self::clamp((float) ($planet['fallTime'] ?? 3), 1, 5);107
$f = self::clamp((float) ($planet['fallTime'] ?? 3), 1, 5);98
$r = self::clamp((float) ($planet['riseTime'] ?? 1.5), 0.5, 3);108
$r = self::clamp((float) ($planet['riseTime'] ?? 1.5), 0.5, 3);99
$power = self::power($planet);100
return [109
return [101
'gravity' => 9.81 * $j / 2,110
'gravity' => 9.81 * $j / 2,102
'density' => 0.25 + ((5 - $f) / 4) * 1.60,111
'density' => 0.25 + ((5 - $f) / 4) * 1.60,103
'newtons' => 40 + (($r - 0.5) / 2.5) * 160,112
'newtons' => 40 + (($r - 0.5) / 2.5) * 160,104
'power' => (int) round($power * 100),113
'power' => self::displayPower($planet),105
'missChance' => 0.60 - 0.55 * $power,114
'missChance' => self::missChance($planet),106
];115
];107
}116
}108
117
@@ -187,7 +187,10 @@ expect(almostEqual(Planets::missChance(Planets::byId('aurel')), 0.60), 'Aurel mi
187
187
expect(almostEqual(Planets::power(Planets::byId('cinder')), 1.0), 'Cinder power 1');
188
188
expect(almostEqual(Planets::missChance(Planets::byId('cinder')), 0.05), 'Cinder miss 5%');
189
189
$td = Planets::displayValues(Planets::byId('terra'));
190
expect(almostEqual($td['gravity'], 9.81) && almostEqual($td['density'], 1.05) && (int) round($td['newtons']) === 104 && $td['power'] === 48, 'Terra display g/d/F/Power');
190
expect(almostEqual($td['gravity'], 9.81) && almostEqual($td['density'], 1.05) && (int) round($td['newtons']) === 104 && $td['power'] === 44, 'Terra display g/d/F/Power');
191
expect(Planets::displayPower(Planets::byId('aurel')) === 0, 'Aurel displayed Power 0');
192
expect(Planets::displayPower(Planets::byId('cinder')) === 92, 'Cinder displayed Power 92 (5% miss)');
193
expect(Planets::displayValues(Planets::byId('cinder'))['power'] === 92, 'Cinder displayValues Power 92');
191
194
192
195
$store->leaveLobby('local:test_user_1');
193
196
$store->leaveLobby('local:test_user_2');
@@ -187,7 +187,10 @@ expect(almostEqual(Planets::missChance(Planets::byId('aurel')), 0.60), 'Aurel mi187
expect(almostEqual(Planets::power(Planets::byId('cinder')), 1.0), 'Cinder power 1');187
expect(almostEqual(Planets::power(Planets::byId('cinder')), 1.0), 'Cinder power 1');188
expect(almostEqual(Planets::missChance(Planets::byId('cinder')), 0.05), 'Cinder miss 5%');188
expect(almostEqual(Planets::missChance(Planets::byId('cinder')), 0.05), 'Cinder miss 5%');189
$td = Planets::displayValues(Planets::byId('terra'));189
$td = Planets::displayValues(Planets::byId('terra'));190
expect(almostEqual($td['gravity'], 9.81) && almostEqual($td['density'], 1.05) && (int) round($td['newtons']) === 104 && $td['power'] === 48, 'Terra display g/d/F/Power');190
expect(almostEqual($td['gravity'], 9.81) && almostEqual($td['density'], 1.05) && (int) round($td['newtons']) === 104 && $td['power'] === 44, 'Terra display g/d/F/Power');191
expect(Planets::displayPower(Planets::byId('aurel')) === 0, 'Aurel displayed Power 0');192
expect(Planets::displayPower(Planets::byId('cinder')) === 92, 'Cinder displayed Power 92 (5% miss)');193
expect(Planets::displayValues(Planets::byId('cinder'))['power'] === 92, 'Cinder displayValues Power 92');191
194
192
$store->leaveLobby('local:test_user_1');195
$store->leaveLobby('local:test_user_1');193
$store->leaveLobby('local:test_user_2');196
$store->leaveLobby('local:test_user_2');@@ -190,16 +190,30 @@ function power (planet)
190
190
return (gravity + air + mass) / 3;
191
191
}
192
192
193
/** Maximum miss chance, used by the gameplay formula and the displayed Power. */
194
var MAX_MISS_CHANCE = 0.60;
195
var MIN_MISS_CHANCE = 0.05;
196
193
197
/** Stage-2 miss chance, 0.60 at power 0 down to 0.05 at power 1. */
194
198
function missChance (planet)
195
199
{
196
return 0.60 - 0.55 * power(planet);
200
return MAX_MISS_CHANCE - (MAX_MISS_CHANCE - MIN_MISS_CHANCE) * power(planet);
201
}
202
203
/**
204
* Displayed Power, as a 0–100 percentage. This is the complement of the
205
* miss chance against the maximum (60%): 0% miss → 100% Power, 60% miss
206
* → 0% Power. The gameplay power() and missChance() formulas are unchanged.
207
*/
208
function displayPower (planet)
209
{
210
return Math.round((1 - missChance(planet) / MAX_MISS_CHANCE) * 100);
197
211
}
198
212
199
213
/**
200
214
* Numeric HUD values: a gravity-like constant (m/s²), air density (kg/m³),
201
* launch force (N), and power as a percentage. The numbers do not have to
202
* explain themselves.
215
* launch force (N), and displayed Power as a percentage. The numbers do
216
* not have to explain themselves.
203
217
*/
204
218
function displayValues (planet)
205
219
{
@@ -210,7 +224,7 @@ function displayValues (planet)
210
224
gravity: gravity,
211
225
density: density,
212
226
newtons: newtons,
213
power: Math.round(power(planet) * 100),
227
power: displayPower(planet),
214
228
missChance: missChance(planet)
215
229
};
216
230
}
@@ -234,8 +248,11 @@ var Planet = {
234
248
jumpHeight: jumpHeight,
235
249
launchVelocity: launchVelocity,
236
250
launchDeceleration: launchDeceleration,
251
MAX_MISS_CHANCE: MAX_MISS_CHANCE,
252
MIN_MISS_CHANCE: MIN_MISS_CHANCE,
237
253
power: power,
238
254
missChance: missChance,
255
displayPower: displayPower,
239
256
displayValues: displayValues
240
257
};
241
258
@@ -190,16 +190,30 @@ function power (planet)190
return (gravity + air + mass) / 3;190
return (gravity + air + mass) / 3;191
}191
}192
192
193
/** Maximum miss chance, used by the gameplay formula and the displayed Power. */194
var MAX_MISS_CHANCE = 0.60;195
var MIN_MISS_CHANCE = 0.05;196
193
/** Stage-2 miss chance, 0.60 at power 0 down to 0.05 at power 1. */197
/** Stage-2 miss chance, 0.60 at power 0 down to 0.05 at power 1. */194
function missChance (planet)198
function missChance (planet)195
{199
{196
return 0.60 - 0.55 * power(planet);200
return MAX_MISS_CHANCE - (MAX_MISS_CHANCE - MIN_MISS_CHANCE) * power(planet);201
}202
203
/**204
* Displayed Power, as a 0–100 percentage. This is the complement of the205
* miss chance against the maximum (60%): 0% miss → 100% Power, 60% miss206
* → 0% Power. The gameplay power() and missChance() formulas are unchanged.207
*/208
function displayPower (planet)209
{210
return Math.round((1 - missChance(planet) / MAX_MISS_CHANCE) * 100);197
}211
}198
212
199
/**213
/**200
* Numeric HUD values: a gravity-like constant (m/s²), air density (kg/m³),214
* Numeric HUD values: a gravity-like constant (m/s²), air density (kg/m³),201
* launch force (N), and power as a percentage. The numbers do not have to215
* launch force (N), and displayed Power as a percentage. The numbers do202
* explain themselves.216
* not have to explain themselves.203
*/217
*/204
function displayValues (planet)218
function displayValues (planet)205
{219
{@@ -210,7 +224,7 @@ function displayValues (planet)210
gravity: gravity,224
gravity: gravity,211
density: density,225
density: density,212
newtons: newtons,226
newtons: newtons,213
power: Math.round(power(planet) * 100),227
power: displayPower(planet),214
missChance: missChance(planet)228
missChance: missChance(planet)215
};229
};216
}230
}@@ -234,8 +248,11 @@ var Planet = {234
jumpHeight: jumpHeight,248
jumpHeight: jumpHeight,235
launchVelocity: launchVelocity,249
launchVelocity: launchVelocity,236
launchDeceleration: launchDeceleration,250
launchDeceleration: launchDeceleration,251
MAX_MISS_CHANCE: MAX_MISS_CHANCE,252
MIN_MISS_CHANCE: MIN_MISS_CHANCE,237
power: power,253
power: power,238
missChance: missChance,254
missChance: missChance,255
displayPower: displayPower,239
displayValues: displayValues256
displayValues: displayValues240
};257
};241
258
@@ -96,11 +96,11 @@ def run_desktop(browser):
96
96
# Numeric stats, no long explanation — Terra mid values.
97
97
terra = next(t for t in texts if t.startswith("Terra"))
98
98
check("Terrans" in terra, "Terra people name")
99
check("g 9.81" in terra and "d 1.05" in terra and "F 104 N" in terra and "Power 48%" in terra,
99
check("g 9.81" in terra and "d 1.05" in terra and "F 104 N" in terra and "Power 44%" in terra,
100
100
"Terra numeric stats on the card")
101
101
cinder = next(t for t in texts if t.startswith("Cinder"))
102
check("Cindari" in cinder and "Power 100%" in cinder and "g 19.62" in cinder,
103
"Cinder is the hardest (Power 100%)")
102
check("Cindari" in cinder and "Power 92%" in cinder and "g 19.62" in cinder,
103
"Cinder is the hardest (Power 92%)")
104
104
aurel = next(t for t in texts if t.startswith("Aurel"))
105
105
check("Aurelians" in aurel and "Power 0%" in aurel, "Aurel is the easiest (Power 0%)")
106
106
# Each card has 5 unique placeholder images.
@@ -125,7 +125,7 @@ def run_desktop(browser):
125
125
print("HUD", hud)
126
126
check(hud["id"] == "cinder" and "Cinder" in hud["name"] and "Cindari" in hud["name"],
127
127
"HUD shows Cinder · Cindari")
128
check("Power 100%" in hud["stats"] and "g 19.62" in hud["stats"], "HUD shows Cinder numbers")
128
check("Power 92%" in hud["stats"] and "g 19.62" in hud["stats"], "HUD shows Cinder numbers")
129
129
check(abs(hud["miss"] - 0.05) < 1e-9, "GameCore missChance is Cinder's 5%")
130
130
shot(page, "stage3-play-cinder-desktop.png")
131
131
ctx.close()
@@ -96,11 +96,11 @@ def run_desktop(browser):96
# Numeric stats, no long explanation — Terra mid values.96
# Numeric stats, no long explanation — Terra mid values.97
terra = next(t for t in texts if t.startswith("Terra"))97
terra = next(t for t in texts if t.startswith("Terra"))98
check("Terrans" in terra, "Terra people name")98
check("Terrans" in terra, "Terra people name")99
check("g 9.81" in terra and "d 1.05" in terra and "F 104 N" in terra and "Power 48%" in terra,99
check("g 9.81" in terra and "d 1.05" in terra and "F 104 N" in terra and "Power 44%" in terra,100
"Terra numeric stats on the card")100
"Terra numeric stats on the card")101
cinder = next(t for t in texts if t.startswith("Cinder"))101
cinder = next(t for t in texts if t.startswith("Cinder"))102
check("Cindari" in cinder and "Power 100%" in cinder and "g 19.62" in cinder,102
check("Cindari" in cinder and "Power 92%" in cinder and "g 19.62" in cinder,103
"Cinder is the hardest (Power 100%)")103
"Cinder is the hardest (Power 92%)")104
aurel = next(t for t in texts if t.startswith("Aurel"))104
aurel = next(t for t in texts if t.startswith("Aurel"))105
check("Aurelians" in aurel and "Power 0%" in aurel, "Aurel is the easiest (Power 0%)")105
check("Aurelians" in aurel and "Power 0%" in aurel, "Aurel is the easiest (Power 0%)")106
# Each card has 5 unique placeholder images.106
# Each card has 5 unique placeholder images.@@ -125,7 +125,7 @@ def run_desktop(browser):125
print("HUD", hud)125
print("HUD", hud)126
check(hud["id"] == "cinder" and "Cinder" in hud["name"] and "Cindari" in hud["name"],126
check(hud["id"] == "cinder" and "Cinder" in hud["name"] and "Cindari" in hud["name"],127
"HUD shows Cinder · Cindari")127
"HUD shows Cinder · Cindari")128
check("Power 100%" in hud["stats"] and "g 19.62" in hud["stats"], "HUD shows Cinder numbers")128
check("Power 92%" in hud["stats"] and "g 19.62" in hud["stats"], "HUD shows Cinder numbers")129
check(abs(hud["miss"] - 0.05) < 1e-9, "GameCore missChance is Cinder's 5%")129
check(abs(hud["miss"] - 0.05) < 1e-9, "GameCore missChance is Cinder's 5%")130
shot(page, "stage3-play-cinder-desktop.png")130
shot(page, "stage3-play-cinder-desktop.png")131
ctx.close()131
ctx.close()@@ -156,6 +156,29 @@ describe('Power and display values', () =>
156
156
// Mid-range Terra (jumps=2) shows Earth-like 9.81
157
157
assert.ok(Math.abs(d.gravity - 9.81) < 1e-9);
158
158
});
159
160
it('displayed Power is 1 − missChance / 0.60, so 0% miss shows as 100% Power', () =>
161
{
162
const easy = Planet.createPlanet({ jumpsToClear: 1, fallTime: 5, riseTime: 3 });
163
const hard = Planet.createPlanet({ jumpsToClear: 4, fallTime: 1, riseTime: 0.5 });
164
const terra = Planet.defaultPlanet();
165
// 60% miss → 0% Power; 5% miss → 92% (not 100 — the floor is 5%, not 0).
166
assert.equal(Planet.displayPower(easy), 0);
167
assert.equal(Planet.displayValues(easy).power, 0);
168
assert.equal(Planet.displayPower(hard), Math.round((1 - 0.05 / 0.60) * 100));
169
assert.equal(Planet.displayPower(hard), 92);
170
const terraMiss = Planet.missChance(terra);
171
assert.equal(Planet.displayPower(terra), Math.round((1 - terraMiss / 0.60) * 100));
172
assert.equal(Planet.displayValues(terra).power, 44);
173
// Gameplay power() and missChance() are unchanged.
174
assert.equal(Planet.power(easy), 0);
175
assert.ok(Math.abs(Planet.power(hard) - 1) < 1e-12);
176
assert.equal(Planet.missChance(easy), 0.60);
177
assert.ok(Math.abs(Planet.missChance(hard) - 0.05) < 1e-12);
178
// Monotonic: a lower miss chance means a higher displayed Power.
179
assert.ok(Planet.displayPower(hard) > Planet.displayPower(terra));
180
assert.ok(Planet.displayPower(terra) > Planet.displayPower(easy));
181
});
159
182
});
160
183
161
184
describe('Planet catalog', () =>
@@ -189,7 +212,7 @@ describe('Planet catalog', () =>
189
212
assert.equal(Planet.planetById('cinder').name, 'Cinder');
190
213
});
191
214
192
it('Aurel is the easiest (Power 0, 60% miss) and Cinder the hardest (Power 1, 5% miss)', () =>
215
it('Aurel is the easiest (gameplay Power 0, 60% miss, shown as 0%) and Cinder the hardest (gameplay Power 1, 5% miss, shown as 92%)', () =>
193
216
{
194
217
const aurel = Planet.planetById('aurel');
195
218
const cinder = Planet.planetById('cinder');
@@ -198,6 +221,6 @@ describe('Planet catalog', () =>
198
221
assert.ok(Math.abs(Planet.power(cinder) - 1) < 1e-12);
199
222
assert.ok(Math.abs(Planet.missChance(cinder) - 0.05) < 1e-12);
200
223
assert.equal(Planet.displayValues(aurel).power, 0);
201
assert.equal(Planet.displayValues(cinder).power, 100);
224
assert.equal(Planet.displayValues(cinder).power, 92);
202
225
});
203
226
});
@@ -156,6 +156,29 @@ describe('Power and display values', () =>156
// Mid-range Terra (jumps=2) shows Earth-like 9.81156
// Mid-range Terra (jumps=2) shows Earth-like 9.81157
assert.ok(Math.abs(d.gravity - 9.81) < 1e-9);157
assert.ok(Math.abs(d.gravity - 9.81) < 1e-9);158
});158
});159
160
it('displayed Power is 1 − missChance / 0.60, so 0% miss shows as 100% Power', () =>161
{162
const easy = Planet.createPlanet({ jumpsToClear: 1, fallTime: 5, riseTime: 3 });163
const hard = Planet.createPlanet({ jumpsToClear: 4, fallTime: 1, riseTime: 0.5 });164
const terra = Planet.defaultPlanet();165
// 60% miss → 0% Power; 5% miss → 92% (not 100 — the floor is 5%, not 0).166
assert.equal(Planet.displayPower(easy), 0);167
assert.equal(Planet.displayValues(easy).power, 0);168
assert.equal(Planet.displayPower(hard), Math.round((1 - 0.05 / 0.60) * 100));169
assert.equal(Planet.displayPower(hard), 92);170
const terraMiss = Planet.missChance(terra);171
assert.equal(Planet.displayPower(terra), Math.round((1 - terraMiss / 0.60) * 100));172
assert.equal(Planet.displayValues(terra).power, 44);173
// Gameplay power() and missChance() are unchanged.174
assert.equal(Planet.power(easy), 0);175
assert.ok(Math.abs(Planet.power(hard) - 1) < 1e-12);176
assert.equal(Planet.missChance(easy), 0.60);177
assert.ok(Math.abs(Planet.missChance(hard) - 0.05) < 1e-12);178
// Monotonic: a lower miss chance means a higher displayed Power.179
assert.ok(Planet.displayPower(hard) > Planet.displayPower(terra));180
assert.ok(Planet.displayPower(terra) > Planet.displayPower(easy));181
});159
});182
});160
183
161
describe('Planet catalog', () =>184
describe('Planet catalog', () =>@@ -189,7 +212,7 @@ describe('Planet catalog', () =>189
assert.equal(Planet.planetById('cinder').name, 'Cinder');212
assert.equal(Planet.planetById('cinder').name, 'Cinder');190
});213
});191
214
192
it('Aurel is the easiest (Power 0, 60% miss) and Cinder the hardest (Power 1, 5% miss)', () =>215
it('Aurel is the easiest (gameplay Power 0, 60% miss, shown as 0%) and Cinder the hardest (gameplay Power 1, 5% miss, shown as 92%)', () =>193
{216
{194
const aurel = Planet.planetById('aurel');217
const aurel = Planet.planetById('aurel');195
const cinder = Planet.planetById('cinder');218
const cinder = Planet.planetById('cinder');@@ -198,6 +221,6 @@ describe('Planet catalog', () =>198
assert.ok(Math.abs(Planet.power(cinder) - 1) < 1e-12);221
assert.ok(Math.abs(Planet.power(cinder) - 1) < 1e-12);199
assert.ok(Math.abs(Planet.missChance(cinder) - 0.05) < 1e-12);222
assert.ok(Math.abs(Planet.missChance(cinder) - 0.05) < 1e-12);200
assert.equal(Planet.displayValues(aurel).power, 0);223
assert.equal(Planet.displayValues(aurel).power, 0);201
assert.equal(Planet.displayValues(cinder).power, 100);224
assert.equal(Planet.displayValues(cinder).power, 92);202
});225
});203
});226
});