Make Sokko TCG's Current Race fairer and explain each race afterwards
Players kept finishing third or fourth: opponents were played better than their owners would (always the best runner, half of them with perfect boosts and no reaction time), and the Watchers recruited knowing the day's circuit, which players never see. - A player who already ran today now comes back as a ghost with their real race; other teams play like an attentive player (best runner, each teammate given in a zone of its best stat after a reaction delay). The Watchers recruit blind; only the strong one plays attentively. The administration counts the ghosts. - The rule that a boost keeps the value of the zone where it was given is now stated before and during the race. - A boosting teammate is greyed at once with "Élan donné", a 1.5 s bar and its locked value; the others dim while the player has to wait. - The result shows the place as a medal, the finish as lanes (with a gold silhouette at the best boosts), the three times, each boost placed on the circuit (dashed in the teammate's best stat when it was worth more elsewhere), a sentence per boost to place better and, when clearly faster, another runner. The best boosts are searched in the browser. - A development-only "Recourir (dev)" button erases the race and keeps the team. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8253f74c90
commit
52df57f781
16 changed files with 603 additions and 102 deletions
|
|
@ -8,7 +8,8 @@ import { createCardsApiHandler } from "../services/cards/api.js";
|
|||
import { buildPublishedCatalog, prepareVersionedCatalog } from "../services/cards/catalog.js";
|
||||
import { CardsDatabase } from "../services/cards/database.js";
|
||||
import { STAT_IDS } from "../services/cards/expedition-rules.js";
|
||||
import { applyBoost, autoRun, bestRunner, boostsError, canBoost, drawZones, MAX_RACE_MS, placeOf, RACE_STATS, replayRun, startRun, stepRun, ZONE_COUNT } from "../services/cards/race-rules.js";
|
||||
import { applyBoost, autoRun, bestBoosts, bestRunner, boostsError, canBoost, drawZones, MAX_RACE_MS, placeOf, RACE_STATS, replayRun, startRun, stepRun, ZONE_COUNT } from "../services/cards/race-rules.js";
|
||||
import { raceReview } from "../website/src/features/cards/raceRun.js";
|
||||
import { CardsService } from "../services/cards/service.js";
|
||||
import { canRevealStar, chooseCharacter, companionStats, DEFAULT_TEAM_SETTINGS, drawOffer, hiddenStars, inventTeam, keepCompanion, lentCharacters, MIN_SPECIALISTS, OFFER_SIZE, profileKey, recruitmentFinished, rerollOffer, revealStar, specialtiesOf, startRecruitment, TEAM_SIZE, teamCharacters, teamDay, teamSettingsError, visibleSky, WATCHER_TEAM_LEVELS } from "../services/cards/team-rules.js";
|
||||
import { DEFAULT_DAILY_TEAM_SETTINGS, dailyTeamSettingsError, readDailyTeamSettings } from "../services/cards/team-settings.js";
|
||||
|
|
@ -211,26 +212,54 @@ test("a replayed race is deterministic and ignores impossible boosts", () => {
|
|||
const teamStats = (team) => team.map(({ cardId, power }) => companionStats(byId.get(cardId).profile, power));
|
||||
const entrant = (stats, zones, index = bestRunner(stats, zones)) => ({ runner: stats[index], helpers: stats.filter((_, other) => other !== index) });
|
||||
|
||||
test("simulated races reward a good team, a good runner and good boosts", () => {
|
||||
// Les adversaires sont des joueurs qui recrutent sans connaître le circuit et jouent leurs élans avec attention, sans plus.
|
||||
test("simulated races reward a good runner and good boosts, against attentive players", () => {
|
||||
const random = seeded(7);
|
||||
const races = 250;
|
||||
const wins = { random: 0, runner: 0, boosts: 0 };
|
||||
let last = 0;
|
||||
const places = { random: [0, 0, 0, 0], runner: [0, 0, 0, 0], fair: [0, 0, 0, 0], skilled: [0, 0, 0, 0] };
|
||||
const blindTeam = () => teamStats(inventTeam(characters, drawZones(random), WATCHER_TEAM_LEVELS.medium, random));
|
||||
for (let race = 0; race < races; race += 1) {
|
||||
const zones = drawZones(random);
|
||||
const others = Array.from({ length: 3 }, () => autoRun(entrant(teamStats(inventTeam(characters, drawZones(random), WATCHER_TEAM_LEVELS.strong, random)), zones), zones, random(2) === 0, random).finishedAt);
|
||||
const stats = teamStats(inventTeam(characters, zones, WATCHER_TEAM_LEVELS.strong, random));
|
||||
const place = (index, skilled) => placeOf(autoRun(entrant(stats, zones, index), zones, skilled, random).finishedAt, others);
|
||||
const randomPlace = place(random(TEAM_SIZE), false);
|
||||
wins.random += randomPlace === 1 ? 1 : 0;
|
||||
last += randomPlace === 4 ? 1 : 0;
|
||||
wins.runner += place(undefined, false) === 1 ? 1 : 0;
|
||||
wins.boosts += place(undefined, true) === 1 ? 1 : 0;
|
||||
const others = Array.from({ length: 3 }, () => autoRun(entrant(blindTeam(), zones), zones, "fair", random).finishedAt);
|
||||
const stats = blindTeam();
|
||||
const place = (index, play) => placeOf(autoRun(entrant(stats, zones, index), zones, play, random).finishedAt, others);
|
||||
places.random[place(random(TEAM_SIZE), "random") - 1] += 1;
|
||||
places.runner[place(undefined, "random") - 1] += 1;
|
||||
places.fair[place(undefined, "fair") - 1] += 1;
|
||||
places.skilled[place(undefined, "skilled") - 1] += 1;
|
||||
}
|
||||
assert.ok(wins.random < races * 0.2, `coureur et élans au hasard : ${wins.random} victoires`);
|
||||
assert.ok(last > races * 0.4, `coureur et élans au hasard : ${last} dernières places`);
|
||||
assert.ok(wins.runner > wins.random, `bon coureur : ${wins.runner}`);
|
||||
assert.ok(wins.boosts > wins.runner * 2 && wins.boosts > races * 0.3 && wins.boosts < races * 0.7, `bons élans : ${wins.boosts} victoires`);
|
||||
const average = (counts) => counts.reduce((sum, count, index) => sum + count * (index + 1), 0) / races;
|
||||
const report = JSON.stringify(places);
|
||||
// Un joueur attentif est au milieu du plateau ; le hasard finit surtout dernier ; bien jouer rapporte plus.
|
||||
assert.ok(average(places.fair) > 2.2 && average(places.fair) < 2.8, report);
|
||||
assert.ok(places.random[3] > races * 0.4 && places.random[0] < races * 0.15, report);
|
||||
assert.ok(average(places.random) > average(places.runner) && average(places.runner) > average(places.fair) && average(places.fair) > average(places.skilled), report);
|
||||
});
|
||||
|
||||
// Les meilleurs élans trouvés ne sont pas cherchés à chaque pas : ils peuvent manquer de peu (moins d’un dixième de seconde).
|
||||
test("the best boosts found beat the automatic ones, and the review of a race explains it", () => {
|
||||
const random = seeded(12);
|
||||
for (let round = 0; round < 40; round += 1) {
|
||||
const zones = drawZones(random);
|
||||
const runners = entrant(teamStats(inventTeam(characters, zones, WATCHER_TEAM_LEVELS.medium, random)), zones);
|
||||
const best = replayRun({ ...runners, boosts: bestBoosts(runners, zones) }, zones).finishedAt;
|
||||
for (const play of ["random", "fair", "skilled"]) assert.ok(best <= autoRun(runners, zones, play, random).finishedAt + 100, `${play} ${round}`);
|
||||
}
|
||||
const zones = ["endurance", "orientation", "bravoure", "endurance", "orientation", "endurance", "fortune", "bravoure"];
|
||||
const card = (cardId, bravoure, endurance, fortune, orientation) => ({ cardId, stats: profile(bravoure, endurance, fortune, orientation) });
|
||||
const race = {
|
||||
zones, place: 3, runner: card("r", 23, 15, 7, 5),
|
||||
helpers: [card("a", 8, 12, 10, 20), card("b", 5, 23, 15, 7), card("c", 13, 12, 10, 15), card("d", 10, 10, 20, 10)],
|
||||
boosts: [{ at: 280, helper: 1 }, { at: 5_740, helper: 2 }, { at: 7_660, helper: 0 }],
|
||||
opponents: [{ finishedAt: 13_697 }, { finishedAt: 11_741 }, { finishedAt: 17_408 }]
|
||||
};
|
||||
const review = raceReview(race);
|
||||
assert.ok(review.best < review.mine && review.mine < review.plain, JSON.stringify(review));
|
||||
assert.equal(review.bestPlace, 2);
|
||||
assert.deepEqual(review.boosts.map(({ stat, value, bestStat, bestValue }) => [stat, value, bestStat, bestValue]),
|
||||
[["orientation", 20, "orientation", 20], ["endurance", 23, "endurance", 23], ["bravoure", 13, "orientation", 15], [null, 0, "fortune", 20]]);
|
||||
assert.equal(review.fasterRunner, null);
|
||||
assert.equal(raceReview({ ...race, runner: race.helpers[0], helpers: [race.runner, ...race.helpers.slice(1)] }).fasterRunner, "r");
|
||||
});
|
||||
|
||||
test("the watchers' teams go from weak to strong", () => {
|
||||
|
|
@ -239,7 +268,7 @@ test("the watchers' teams go from weak to strong", () => {
|
|||
let total = 0;
|
||||
for (let round = 0; round < 250; round += 1) {
|
||||
const zones = drawZones(random);
|
||||
total += autoRun(entrant(teamStats(inventTeam(characters, zones, skill, random)), zones), zones, skill > 50, random).finishedAt;
|
||||
total += autoRun(entrant(teamStats(inventTeam(characters, drawZones(random), skill, random)), zones), zones, skill > 75 ? "fair" : "random", random).finishedAt;
|
||||
}
|
||||
return [level, total / 250];
|
||||
}));
|
||||
|
|
@ -434,7 +463,7 @@ test("the course of the day is the same for everyone and changes with the day",
|
|||
test("the team API requires a session", async (t) => {
|
||||
const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, random: () => 0 });
|
||||
t.after(() => handler.close?.());
|
||||
for (const [method, path] of [["GET", ""], ["POST", "/recruit"], ["POST", "/reroll"], ["POST", "/choose"], ["POST", "/stars"], ["POST", "/heal"], ["POST", "/keep"], ["POST", "/race"], ["POST", "/race/boosts"], ["POST", "/race/finish"]]) {
|
||||
for (const [method, path] of [["GET", ""], ["POST", "/recruit"], ["POST", "/reroll"], ["POST", "/choose"], ["POST", "/stars"], ["POST", "/heal"], ["POST", "/keep"], ["POST", "/race"], ["POST", "/race/boosts"], ["POST", "/race/finish"], ["POST", "/race/reset"]]) {
|
||||
const req = Readable.from(method === "POST" ? [Buffer.from("{}")] : []);
|
||||
Object.assign(req, { method, url: `/api/cards/team${path}`, headers: { host: "localhost", origin: "http://localhost", "content-type": "application/json" }, socket: { remoteAddress: "127.0.0.1" } });
|
||||
let status = 0;
|
||||
|
|
@ -504,7 +533,7 @@ test("the race opens and closes on its own, with its watchers' skill and a daily
|
|||
assert.deepEqual(summary.zones, race.zones);
|
||||
assert.deepEqual([summary.started, summary.finished, summary.stardust], [1, 1, finished.reward]);
|
||||
assert.equal(summary.places[finished.place - 1], 1);
|
||||
assert.deepEqual(summary.opponents, { players: 0, watchers: 3 });
|
||||
assert.deepEqual(summary.opponents, { players: 0, ghosts: 0, watchers: 3 });
|
||||
// L'Équipe du jour fermée ferme aussi la Course aux joueurs.
|
||||
team.updateSettings(admin.id, { ...team.settings, enabled: false });
|
||||
assert.equal(team.summary(player.id).raceEnabled, false);
|
||||
|
|
@ -555,6 +584,7 @@ test("opponents are other players' usable teams, completed by the watchers, and
|
|||
const { race } = team.startRace(player.id, { day: DAY, cardId: companions[0].cardId }).team;
|
||||
assert.deepEqual(race.opponents.map((opponent) => opponent.name).filter(Boolean).sort(), ["Ana", "Bob"]);
|
||||
assert.equal(race.opponents.filter((opponent) => opponent.watchers).length, 1);
|
||||
assert.ok(race.opponents.every((opponent) => !opponent.ghost));
|
||||
service.deleteAccount(others[0].id);
|
||||
assert.deepEqual(team.view(player.id).race.opponents.map((opponent) => opponent.name).filter(Boolean), ["Bob"]);
|
||||
team.finishRace(player.id, {});
|
||||
|
|
@ -566,6 +596,26 @@ test("opponents are other players' usable teams, completed by the watchers, and
|
|||
assert.equal(context.db.prepare("SELECT COUNT(*) AS count FROM team_races WHERE player_id = ?").get(player.id).count, 0);
|
||||
});
|
||||
|
||||
test("a player who already ran today comes back with the real race, before the others", (t) => {
|
||||
const context = game(t);
|
||||
const { team, player, service } = context;
|
||||
const others = [["10", "Ana"], ["11", "Bob"], ["13", "Cid"], ["14", "Dan"]].map(([id, name]) => join(service, id, name));
|
||||
for (const other of others) readyTeam(context, other);
|
||||
const [ana] = others;
|
||||
const anaTeam = team.view(ana.id).companions;
|
||||
const boosts = [{ at: 1_000, helper: 2 }];
|
||||
team.startRace(ana.id, { day: DAY, cardId: anaTeam[1].cardId });
|
||||
const anaRace = team.finishRace(ana.id, { boosts }).team.race;
|
||||
const { companions } = readyTeam(context);
|
||||
const { race } = team.startRace(player.id, { day: DAY, cardId: companions[0].cardId }).team;
|
||||
const ghost = race.opponents.find((opponent) => opponent.ghost);
|
||||
assert.equal(race.opponents.filter((opponent) => opponent.ghost).length, 1);
|
||||
assert.equal(ghost.name, "Ana");
|
||||
assert.deepEqual([ghost.runner.cardId, ghost.boosts, ghost.finishedAt], [anaTeam[1].cardId, boosts, anaRace.finishedAt]);
|
||||
assert.equal(race.opponents.filter((opponent) => opponent.name).length, 3);
|
||||
assert.equal(team.adminSettings().race.opponents.ghosts, 1);
|
||||
});
|
||||
|
||||
function winDaily({ service, player, db, team }) {
|
||||
service.getDaily(player.id);
|
||||
const { card_id: cardId } = db.prepare("SELECT card_id FROM daily_attempts WHERE player_id = ? AND day = ?").get(player.id, team.today);
|
||||
|
|
@ -634,6 +684,19 @@ test("only the development server resets a team and its races", (t) => {
|
|||
assert.deepEqual([reset.devReset, reset.status, reset.race, reset.canRecruit], [true, "none", null, true]);
|
||||
});
|
||||
|
||||
test("only the development server erases the race and keeps the team, to run again", (t) => {
|
||||
const context = game(t);
|
||||
const { team, player, service } = context;
|
||||
const { companions } = readyTeam(context);
|
||||
team.startRace(player.id, { day: DAY, cardId: companions[0].cardId });
|
||||
team.finishRace(player.id, { boosts: [] });
|
||||
refuses("NOT_FOUND", () => team.resetRaceForTests(player.id));
|
||||
service.devPerks = true;
|
||||
const reset = team.resetRaceForTests(player.id).team;
|
||||
assert.deepEqual([reset.status, reset.race, reset.companions.length], ["ready", null, TEAM_SIZE]);
|
||||
assert.equal(team.startRace(player.id, { day: DAY, cardId: companions[1].cardId }).team.race.runner.cardId, companions[1].cardId);
|
||||
});
|
||||
|
||||
test("a balm brings a weakened companion back to its starting power, once and at once", (t) => {
|
||||
const { team, player, db, service } = game(t);
|
||||
team.startRecruitment(player.id, { day: DAY });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue