view update
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
'use strict';
|
||||
const path = require('path');
|
||||
const g = p => require(path.join(__dirname, '..', 'game', p));
|
||||
g('parts.js'); g('robot.js'); g('combat.js'); g('ai.js');
|
||||
g('parts.js'); g('robot.js'); g('combat.js'); g('ai.js'); g('progress.js'); g('tourney.js'); g('live.js'); g('ltourney.js');
|
||||
const RC = globalThis.RC;
|
||||
let fails = 0;
|
||||
const ok = (c, msg) => { if (!c) { fails++; console.log('FAIL', msg); } };
|
||||
@@ -13,7 +13,26 @@ ok(!RC.validate({ ...RC.STARTER, chassis: null }).ok, 'chassis required');
|
||||
ok(RC.validate({ chassis: 'scarab', motor: 'comet', wheels: 'tracks', battery: 'lipo', armour: 'hardox', weapon: 'spinner', tower: 'rockets' }).errors.includes('overweight'), 'overweight detected');
|
||||
ok(RC.validate({ chassis: 'crate', motor: 'comet', wheels: 'rubber', battery: 'lead', armour: null, weapon: 'spinner', tower: null }).errors.includes('no_power'), 'power detected');
|
||||
ok(RC.validate({ ...RC.STARTER, motor: 'lead' }).errors.includes('bad_motor'), 'wrong slot detected');
|
||||
for (const o of [...RC.LEAGUE, RC.DUMMY]) { const v = RC.validate(o.build); ok(v.ok, `league build ${o.id}: ${v.errors} (${v.weight} kg, ${v.power}/${v.supply})`); }
|
||||
// every weight class: all eight builds must fit the class limit and its own power budget
|
||||
for (const c of RC.CLASSES) {
|
||||
RC.setClass(c.id);
|
||||
for (const o of RC.LEAGUE) {
|
||||
const v = RC.validate(o.build);
|
||||
ok(v.ok, `${c.id} build ${o.id}: ${v.errors} (${v.weight} kg, ${v.power}/${v.supply})`);
|
||||
ok(v.weight <= c.max, `${c.id} build ${o.id} stays under ${c.max} kg (${v.weight})`);
|
||||
}
|
||||
const names = RC.LEAGUE.map(o => o.name);
|
||||
ok(new Set(names).size === names.length, `${c.id}: no duplicate names`);
|
||||
const rising = RC.LEAGUE.every((o, i) => i === 0 || o.prize > RC.LEAGUE[i - 1].prize);
|
||||
ok(rising, `${c.id}: prize money goes up through the league`);
|
||||
}
|
||||
RC.setClass('medium');
|
||||
ok(RC.WEIGHT_LIMIT === 100 && RC.LEAGUE === RC.LEAGUES.medium, 'setClass swaps limit and roster');
|
||||
RC.setClass('light');
|
||||
ok(RC.WEIGHT_LIMIT === 60, 'the light class really lowers the limit');
|
||||
ok(!RC.validate({ ...RC.STARTER, chassis: 'plough', armour: 'hardox' }).ok, 'a heavy build is refused in the light class');
|
||||
RC.setClass('medium');
|
||||
{ const v = RC.validate(RC.DUMMY.build); ok(v.ok, `dummy build: ${v.errors}`); }
|
||||
|
||||
// fights: every league robot vs every other, AI on both sides
|
||||
function fight(a, b, seed) {
|
||||
@@ -218,5 +237,152 @@ for (const id of ['crucible', 'colosseum', 'foundry', 'arena64']) {
|
||||
ok(h0 - a2.hp > 10, 'once the grace time is over your own mine gets you too');
|
||||
}
|
||||
|
||||
// ranks and achievements
|
||||
{
|
||||
const P = RC.Progress;
|
||||
ok(P.rankOf(0).key === P.RANKS[0].key, 'no fame = lowest rank');
|
||||
ok(P.rankOf(149).key === 'scrap' && P.rankOf(150).key === 'rookie', 'rank flips exactly at the threshold');
|
||||
ok(P.rankOf(1e9).next === null && P.rankOf(1e9).pct === 1, 'top rank has nothing above it');
|
||||
let last = -1, rising = true;
|
||||
for (const r of P.RANKS) { if (r.at <= last) rising = false; last = r.at; }
|
||||
ok(rising, 'rank thresholds go up');
|
||||
|
||||
const save = { money: 0, fame: 0, games: 0, owned: [], robots: [], paint: {}, ach: {} };
|
||||
let got = P.check(save, { won: true, reason: 'ko', hpPct: 0.5, dealt: 100, lost: 1 });
|
||||
const ids = got.map(a => a.id);
|
||||
ok(ids.includes('first_win') && ids.includes('ko'), 'winning by knockout earns both the first win and the KO');
|
||||
ok(!ids.includes('pit') && !ids.includes('flawless'), 'nothing is handed out that was not done');
|
||||
ok(got.every(a => a.reward > 0), 'every achievement pays something');
|
||||
got = P.check(save, { won: true, reason: 'ko', hpPct: 0.5, dealt: 100, lost: 1 });
|
||||
ok(got.length === 0, 'the same achievement is never earned twice');
|
||||
save.money = 5000;
|
||||
ok(P.check(save, {}).map(a => a.id).includes('rich'), 'save-only achievements work without a fight');
|
||||
ok(P.earned(save) === 3 && P.total === P.ACHIEVEMENTS.length, 'the counter matches what was earned');
|
||||
const dup = P.ACHIEVEMENTS.map(a => a.id).filter((v, i, arr) => arr.indexOf(v) !== i);
|
||||
ok(dup.length === 0, 'achievement ids are unique');
|
||||
}
|
||||
|
||||
// knockout tournament
|
||||
{
|
||||
const T = RC.Tourney;
|
||||
const me = () => ({ name: 'Me', build: RC.STARTER, paint: { body: 1, accent: 2 } });
|
||||
let st = T.create({ me: me(), seed: 42 });
|
||||
ok(st.field.length === T.SIZE, 'the bracket starts with eight robots');
|
||||
ok(st.field.filter(e => e.player).length === 1, 'you are in it exactly once');
|
||||
const names = st.field.map(e => e.name);
|
||||
ok(new Set(names).size === names.length, 'no robot appears twice');
|
||||
const p = T.pair(st);
|
||||
ok(p && p[0].player && p[1] && !p[1].player, 'your first match is you against someone else');
|
||||
|
||||
// losing ends the run straight away
|
||||
let lost = T.create({ me: me(), seed: 7 });
|
||||
T.simOthers(lost);
|
||||
T.advance(lost, false);
|
||||
ok(lost.done && lost.out && !lost.won, 'a defeat knocks you out');
|
||||
|
||||
// winning everything takes three rounds and halves the field each time
|
||||
st = T.create({ me: me(), seed: 42 });
|
||||
const sizes = [];
|
||||
let guard = 0;
|
||||
while (!st.done && guard++ < 6) {
|
||||
sizes.push(st.field.length);
|
||||
T.simOthers(st);
|
||||
T.advance(st, true);
|
||||
}
|
||||
ok(st.won && st.round === 3, 'three wins take the trophy');
|
||||
ok(sizes.join() === '8,4,2', 'the field halves every round');
|
||||
ok(st.prize === T.ROUND_PRIZE.reduce((a, b) => a + b, 0), 'every round prize is paid');
|
||||
ok(st.log.filter(l => l.mine).length === 3, 'your three matches are in the log');
|
||||
ok(st.log.filter(l => !l.mine).length === 4, 'the other matches were fought out too');
|
||||
}
|
||||
|
||||
// live settings from the backend
|
||||
{
|
||||
const L = RC.Live, NOW = 1000000;
|
||||
const ev = { id: 'e1', type: 'prize', prizeMul: 2, from: NOW - 100, to: NOW + 100 };
|
||||
|
||||
let r = L.parse(null, NOW, '20261115.1200');
|
||||
ok(r.event === null && !r.onlineOff && !r.needsReload, 'no config = nothing special running');
|
||||
ok(!r.locked('parts', 'wedge'), 'without a config every part stays available');
|
||||
|
||||
r = L.parse({ event: ev }, NOW, '');
|
||||
ok(r.event && r.event.prizeMul === 2, 'an event inside its window is live');
|
||||
ok(L.parse({ event: ev }, NOW + 500, '').event === null, 'after its end it is over');
|
||||
ok(L.parse({ event: ev }, NOW - 500, '').event === null, 'before it starts it is not on yet');
|
||||
ok(L.parse({ event: { id: 'x' } }, NOW, '').event !== null, 'an event without times runs all the time');
|
||||
ok(L.parse({ event: { id: 'x', prizeMul: 99 } }, NOW, '').event.prizeMul === 5, 'a silly prize factor is capped');
|
||||
|
||||
r = L.parse({ unlock: { parts: ['wedge', 'saw'] } }, NOW, '');
|
||||
ok(!r.locked('parts', 'wedge') && r.locked('parts', 'spinner'), 'only released parts are available');
|
||||
ok(!r.locked('arenas', 'foundry'), 'a list that was not set locks nothing');
|
||||
ok(!L.parse({ unlock: { parts: [] } }, NOW, '').locked('parts', 'spinner'), 'an empty list means everything is free');
|
||||
|
||||
ok(L.parse({ flags: { onlineOff: true } }, NOW, '').onlineOff, 'the kill switch comes through');
|
||||
ok(L.parse({ flags: { tournament: true } }, NOW, '').tournament, 'the tournament switch opens the tournament');
|
||||
ok(!L.parse({}, NOW, '').tournament, 'without the switch the tournament stays closed');
|
||||
ok(L.parse({ event: { id: 't', tournament: true } }, NOW, '').tournament, 'an event can open the tournament too');
|
||||
ok(L.parse({ build: { min: '20261115.1800' } }, NOW, '20261115.1200').needsReload, 'an older copy is asked to reload');
|
||||
ok(!L.parse({ build: { min: '20261115.1800' } }, NOW, '20261115.1900').needsReload, 'a newer copy is left alone');
|
||||
ok(!L.parse({ build: { min: '20261115.1800' } }, NOW, '').needsReload, 'without a build stamp we never nag');
|
||||
|
||||
for (const junk of ['nonsense', 42, [], { event: 'no object' }, { unlock: 5 }]) {
|
||||
const p = L.parse(junk, NOW, '');
|
||||
ok(p && p.event === null && typeof p.locked === 'function', 'broken config does not break the game: ' + JSON.stringify(junk));
|
||||
}
|
||||
}
|
||||
|
||||
// live multiplayer bracket
|
||||
{
|
||||
const LT = RC.LTourney;
|
||||
ok(LT.order(['a','b'], 1).length === 2, '2 players = bracket of 2');
|
||||
ok(LT.order(['a','b','c'], 1).length === 4, '3 players pad to 4 (one bye)');
|
||||
ok(LT.order(['a','b','c','d','e'], 1).length === 8, '5 players pad to 8');
|
||||
ok(LT.order(['a','b','c'], 1).filter(x => x === null).length === 1, 'exactly one bye for 3 players');
|
||||
|
||||
const o = LT.order(['bob','amy'], 1); // sorted-ish; host = lower uid
|
||||
const m = LT.myMatch(o, {}, 'amy');
|
||||
ok(m && m.round === 0 && m.opp === 'bob', 'first match is against the other player');
|
||||
ok(LT.myMatch(o, {}, 'amy').host === ('amy' < 'bob'), 'lower uid hosts');
|
||||
|
||||
// a bye advances on its own, no match to play
|
||||
const ob = LT.order(['x','y','z'], 2);
|
||||
const bye = ob.indexOf(null) === 1 ? ob[0] : null; // the player paired with the null
|
||||
|
||||
// winner reported -> loser is out, winner is champion (2-player)
|
||||
const win = o[0];
|
||||
ok(LT.myMatch(o, { 0: { 0: win } }, win).done === true, 'the reported winner is done (champion)');
|
||||
ok(LT.myMatch(o, { 0: { 0: win } }, o[1]) === null, 'the loser drops out');
|
||||
|
||||
// full 8: play it through, there is always one champion
|
||||
const u = ['u0','u1','u2','u3','u4','u5','u6','u7'], O = LT.order(u, 9);
|
||||
const R = {};
|
||||
for (let r = 0; r < 3; r++) { const rows = LT.rounds(O, R)[r]; R[r] = {}; for (let i = 0; i < rows.length; i += 2) R[r][i/2] = rows[i] || rows[i+1]; }
|
||||
const champ = LT.myMatch(O, R, O[0]);
|
||||
ok(RC.LTourney.rounds(O, R).length === 4, 'an 8-player bracket has four columns');
|
||||
ok(u.indexOf(champ.champion) >= 0, 'the champion is one of the players');
|
||||
}
|
||||
|
||||
// body proportions designer
|
||||
{
|
||||
const base = { ...RC.STARTER };
|
||||
const big = { ...base, body: { hx: 1.6, wx: 1.4, lx: 1.3 } };
|
||||
const small = { ...base, body: { hx: 0.7, wx: 0.8, lx: 0.8 } };
|
||||
const s0 = RC.stats(base), sb = RC.stats(big), ss = RC.stats(small);
|
||||
ok(sb.h > s0.h && sb.len > s0.len && sb.wid > s0.wid, 'bigger body = bigger dimensions');
|
||||
ok(ss.h < s0.h && ss.len < s0.len, 'smaller body = smaller dimensions');
|
||||
ok(RC.validate(big).weight > RC.validate(base).weight, 'bigger body weighs more');
|
||||
ok(sb.hp > s0.hp && ss.hp < s0.hp, 'size changes hit points');
|
||||
ok(sb.top < s0.top, 'a heavy big build is slower');
|
||||
ok(sb.topHeavy > 1 && RC.stats({ ...base, body: { hx: 0.8, wx: 1.4, lx: 1.3 } }).topHeavy < 1, 'tall = top-heavy, flat = stable');
|
||||
ok(RC.bodyOf({ body: { hx: 9, wx: 9, lx: 9 } }).hx === 1.6, 'absurd values are clamped');
|
||||
ok([sb.hp, sb.len, sb.mass, sb.top].every(Number.isFinite), 'no NaN at the extreme');
|
||||
// a big heavy build can bust the class limit
|
||||
RC.setClass('light');
|
||||
ok(RC.validate({ ...RC.STARTER, body: { hx: 1.6, wx: 1.4, lx: 1.3 } }).weight > RC.validate(RC.STARTER).weight, 'body weight counts toward the limit');
|
||||
RC.setClass('medium');
|
||||
// builds without a body are unchanged
|
||||
ok(RC.validate(RC.STARTER).weight === RC.validate({ ...RC.STARTER, body: { hx: 1, wx: 1, lx: 1 } }).weight, 'default body = no change');
|
||||
}
|
||||
|
||||
console.log(fails ? `${fails} failure(s)` : 'all ok');
|
||||
process.exit(fails ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user