diff --git a/viewer/docs/tutorials.md b/viewer/docs/tutorials.md index 007615f1..51af148d 100644 --- a/viewer/docs/tutorials.md +++ b/viewer/docs/tutorials.md @@ -7,7 +7,7 @@ alternate-viewer preference. The legacy viewer does not need a tutorial entry po The initial course has four sections: -- **The basics:** mines, terraforming/range, upgrades/research, power, free conversions, Gaiaforming and scoring. +- **The basics:** mines, terraforming/range, upgrades/research, power, free conversions, passing/boosters, Gaiaforming and scoring. - **Federations:** building value and satellites, the routing trap, green tokens, and advanced technology tiles. - **Faction differences:** Xenos, Ivits and Terrans. These are examples, not a catalogue of every faction. - **The Lost Fleet:** exploration, spaceship actions, artifacts and new planets. diff --git a/viewer/package.json b/viewer/package.json index eb671cfc..be71badb 100644 --- a/viewer/package.json +++ b/viewer/package.json @@ -1,6 +1,6 @@ { "name": "@gaia-project/viewer", - "version": "5.17.1", + "version": "5.18.0", "description": "Functions to visualize the map and boards for gaia project inside html canvas", "contributors": [ "coyotte508", diff --git a/viewer/scripts/tutorial-controls.mjs b/viewer/scripts/tutorial-controls.mjs index 21601efd..c0b10083 100644 --- a/viewer/scripts/tutorial-controls.mjs +++ b/viewer/scripts/tutorial-controls.mjs @@ -6,6 +6,8 @@ export async function playOnBoard(page, move, step) { const guideError = page.locator('.bgs-tutorial-body [role="alert"]'); const priorError = (await guideError.isVisible()) ? await guideError.innerText() : ""; for (let attempt = 0; attempt < 35; attempt++) { + // Move off the previous control so its hover tooltip cannot cover the next one. + await (page.mouse ?? page.page().mouse).move(0, 0); if (await page.evaluate((step) => progress.step !== step, step)) return; const confirmation = page.locator(".modal.show .modal-footer .btn-primary"); if (await confirmation.isVisible()) { diff --git a/viewer/scripts/tutorial-smoke.mjs b/viewer/scripts/tutorial-smoke.mjs index 89424169..8458b7fa 100644 --- a/viewer/scripts/tutorial-smoke.mjs +++ b/viewer/scripts/tutorial-smoke.mjs @@ -17,11 +17,21 @@ try { console.log(`START ${lesson.id} ${width}`); await page.goto(`http://127.0.0.1:${server.address().port}/?chapter=${lesson.id}`); await page.waitForFunction(() => window.progress?.step === 0); + if (lesson.id === "terraforming") { + const range = page.locator('[data-tutorial="player-range-0"]'); + assert.equal(await range.count(), 1, "the guide targets the learner’s range display"); + await page.getByRole("button", { name: "Show area", exact: true }).click(); + const box = await range.boundingBox(); + assert.ok(box && box.width > 0 && box.height > 0, "range highlight has a visible target"); + assert.equal(await range.evaluate((node) => getComputedStyle(node).outlineStyle), "solid"); + } let state = lesson.initialState(); for (let index = 0; index < lesson.steps.length; index++) { const step = lesson.steps[index]; const action = step.solution(state); console.log(` ${step.id}`); + if (["basic-range", "swap"].includes(step.id)) + await page.screenshot({ path: `/tmp/gaia-${lesson.id}-${step.id}-${width}.png`, fullPage: true }); if (action.kind === "answer") { const choice = step.choices(state).find((choice) => choice.action.answer === action.answer); await page.locator(".tutorial-choices").getByRole("button", { name: choice.label, exact: true }).click(); diff --git a/viewer/src/components/PlayerInfo.vue b/viewer/src/components/PlayerInfo.vue index f7adfa11..386c59ac 100644 --- a/viewer/src/components/PlayerInfo.vue +++ b/viewer/src/components/PlayerInfo.vue @@ -106,6 +106,7 @@ /> { expect(end.players[0].data.buildings[Building.Mine]).toBe(2); expect(end.players[0].income).not.toBe(start.players[0].income); }); + it("pays separately for terraforming and temporary range without changing basic range", () => { + const lesson = lessons.find((entry) => entry.id === "terraforming")!; + let state = lesson.initialState(); + for (const step of lesson.steps) { + const before = Engine.fromData(copy(state.game)).players[0].data; + state = lesson.move(state, step.solution!(state)) as typeof state; + const after = Engine.fromData(copy(state.game)).players[0].data; + if (step.id === "ice") { + expect(after.ores).toBe(before.ores - 4); + expect(after.qics).toBe(before.qics); + } + if (step.id === "qic-range") { + expect(after.qics).toBe(before.qics - 1); + expect(after.ores).toBe(before.ores - 1); + } + if (step.id === "booster-range") { + expect(after.qics).toBe(before.qics); + expect(after.ores).toBe(before.ores - 1); + expect(after.buildings[Building.Mine]).toBe(4); + } + expect(after.range).toBe(1); + expect(after.temporaryRange).toBe(0); + } + const end = Engine.fromData(copy(state.game)); + expect(end.map.getS("4x0").data.player).toBe(0); + expect( + end.findAvailableCommand(0, Command.Special)?.data.specialacts.map((action) => action.income) ?? [] + ).not.toContain("range+3"); + }); + it("waits for a held booster to become available, then scores and returns the old one", () => { + const lesson = lessons.find((entry) => entry.id === "passing")!; + let state = lesson.initialState(); + const start = Engine.fromData(copy(state.game)); + expect(start.players[0].data.tiles.booster).toBe(Booster.Booster6); + expect(start.players[1].data.tiles.booster).toBe(Booster.Booster5); + expect(start.findAvailableCommand(0, Command.Pass).data.boosters).not.toContain(Booster.Booster5); + for (const step of lesson.steps.slice(0, 2)) state = lesson.move(state, step.solution!(state)) as typeof state; + const before = Engine.fromData(copy(state.game)); + expect(before.passedPlayers).toEqual([1, 2]); + expect(before.findAvailableCommand(0, Command.Pass).data.boosters).toContain(Booster.Booster5); + expect(before.findAvailableCommand(0, Command.Pass).data.boosters).not.toContain(Booster.Booster6); + expect(before.players[0].data.buildings[Building.Mine]).toBe(2); + state = lesson.move(state, lesson.steps[2].solution!(state)) as typeof state; + const after = Engine.fromData(copy(state.game)); + expect(after.players[0].data.victoryPoints).toBe(before.players[0].data.victoryPoints + 2); + expect(after.players[0].data.tiles.booster).toBe(Booster.Booster5); + expect(after.tiles.boosters[Booster.Booster6]).toBe(true); + expect(after.round).toBe(before.round + 1); + expect(after.passedPlayers[0]).toBe(1); + expect(after.players[0].data.ores).toBe( + before.players[0].data.ores + before.players[0].resourceIncome(Resource.Ore) + ); + expect(after.players[0].resourceIncome(Resource.Ore)).toBe(before.players[0].resourceIncome(Resource.Ore)); + }); it("the shorter federation forces in the station and leaves the lower mine out", () => { const start = federationPosition(true); const info = start.players[0].federationInfo(start.players[0].hexesForFederationLocation(detour, start.map)); diff --git a/viewer/src/tutorial/lessons.ts b/viewer/src/tutorial/lessons.ts index 728c2405..08d6b942 100644 --- a/viewer/src/tutorial/lessons.ts +++ b/viewer/src/tutorial/lessons.ts @@ -2,6 +2,7 @@ import type { TutorialOptions, TutorialStep } from "@boardgamers/protocol/tutori import Engine, { AdvTechTile, AdvTechTilePos, + Booster, Building, Command, Faction, @@ -27,6 +28,7 @@ import { position, prepareBoosters, serialise, + setBoosters, } from "./position"; export type Action = @@ -296,13 +298,30 @@ export const lessons: Lesson[] = [ "terraforming", "basics", "Terraforming and range", - "Separate the cost of changing a planet from the cost of reaching it.", + "Read your range, reach farther with Q.I.C. or a booster, and pay for terraforming.", () => { const e = home(); planet(e, "-1x0", Planet.Ice); + planet(e, "4x0", Planet.Terra); + setBoosters( + e, + [Booster.Booster5, Booster.Booster6, Booster.Booster3], + [Booster.Booster1, Booster.Booster2, Booster.Booster4] + ); return e; }, [ + { + ...question( + "basic-range", + "Find your range", + "Your current range is shown beside the range arrow at the top right of your faction board. Count hexes from your nearest building to the destination. A range of 1 reaches an adjacent hex. What is your range now?", + ["1", "2", "3"], + "1", + "Your basic range is 1, so more distant planets need a range boost." + ), + target: "player-range-0", + }, question( "cost", "A different planet type", @@ -319,16 +338,33 @@ export const lessons: Lesson[] = [ 1, "Terraform ice and build" ), + play( + "qic-range", + "Reach farther with Q.I.C.", + "The blue planet beyond your new mine is 2 hexes away. Each Q.I.C. spent adds 2 range for this action only. Build there: the game charges 1 Q.I.C. for range, plus the mine’s 1 ore and 2 credits. Its blue planet needs no terraforming.", + "terrans build m -3x0.", + 2, + "Build the distant blue-planet mine with 1 Q.I.C." + ), question( - "range", - "Q.I.C. extends one action’s range", - "Navigation sets your basic range. Each Q.I.C. spent on range adds 2 for that action. It does not reduce the ore needed to terraform the destination. What does spending Q.I.C. on range change?", - ["Q.I.C. reduces terraforming cost", "Q.I.C. extends range"], - "Q.I.C. extends range", - "Range and terraforming are separate costs. A distant planet can require both." + "navigation", + "Improve your basic range", + "Navigation research increases basic range to 2 at level 2, to 3 at level 4 and to 4 at level 5. These increases last for the rest of the game. The Q.I.C. you just spent helped only that build. What is your basic range still?", + ["1", "2", "3"], + "1", + "Your basic range remains 1. A later lesson lets you research Navigation to increase it." + ), + play( + "booster-range", + "Use the +3 range booster", + "Your round booster has a +3 range special action, usable once this round. Choose Special Action, then +3 range, and build on the blue planet 4 hexes to the right of your central mine. Basic range 1 + 3 reaches it without Q.I.C. You still pay 1 ore and 2 credits for the mine. This action can also send a Gaiaformer, which we will cover later.", + "terrans special range+3. build m 4x0.", + 3, + "Use the booster’s special action, then build the mine" ), ], - "Check range, planet type and mine cost separately. Research can reduce future terraforming costs or improve your normal range." + "Check range, terraforming and mine cost separately. Navigation improves your basic range; Q.I.C. adds 2 for one action; the booster’s special action adds 3 once per round.", + 2 ), lesson( "upgrades", @@ -474,6 +510,59 @@ export const lessons: Lesson[] = [ ], "You burned and converted before building, all in one turn. Burning permanently loses tokens; spending power sends them back to bowl I. Other basic conversions are 1 Q.I.C. → 1 ore, 1 ore or 1 knowledge → 1 credit, and 1 ore → 1 new power token in bowl I." ), + lesson( + "passing", + "basics", + "Passing and choosing a booster", + "Trade your remaining actions for next round’s booster, or wait for another player to return one.", + () => { + const e = home(); + setBoosters( + e, + [Booster.Booster6, Booster.Booster5, Booster.Booster3], + [Booster.Booster1, Booster.Booster2, Booster.Booster4] + ); + return e; + }, + [ + question( + "held-booster", + "Which boosters can you take?", + "Passing ends your actions for this round. Choose one of the three available boosters, then return your old one. Ada currently holds the +3 range booster you want for next round. Can you take it while she still holds it?", + ["Yes", "No"], + "No", + "Only available boosters can be chosen. You must wait for Ada to pass and return hers." + ), + play( + "wait", + "Build while you wait", + "You still have a useful action: build the adjacent blue-planet mine for 1 ore and 2 credits, then end your turn. In this example, Ada will then pass and return her +3 range booster; Leo will pass too. Waiting means taking another action, not skipping your turn.", + "terrans build m 1x0.", + 1, + "Build the mine and let Ada return her booster" + ), + play( + "swap", + "Take the returned booster", + "Ada’s +3 range booster is now available. Choose Pass, select that booster, then confirm. Your old booster gives 1 VP per mine when you pass, so your two mines earn 2 VP before you return it. You cannot keep the same booster for consecutive rounds. Everyone has now passed, so the next round begins and you collect income.", + "terrans pass booster5", + 2, + "Pass and choose the +3 range booster" + ), + question( + "timing", + "Pass early or wait?", + "Waiting let you take Ada’s returned booster. But if a booster you want is already available, someone else may take it first. Passing early secures it, at the cost of your remaining actions this round. The first player to pass also starts the next round. When should you consider passing early?", + [ + "When securing an available booster is worth giving up further actions", + "Always, because passing gives an extra turn", + ], + "When securing an available booster is worth giving up further actions", + "Weigh this round’s useful actions against the booster you want for next round." + ), + ], + "Choose an available booster, then return yours and score any passing reward on it. Passing early can secure a tile; waiting can make a returned tile available. In round 6, return your booster without taking a new one." + ), lesson( "gaiaforming", "basics", diff --git a/viewer/src/tutorial/position.ts b/viewer/src/tutorial/position.ts index 7890e1b2..834d06b1 100644 --- a/viewer/src/tutorial/position.ts +++ b/viewer/src/tutorial/position.ts @@ -117,3 +117,16 @@ export function prepareBoosters(engine: Engine) { player.getRoundBooster(booster); } } + +export function setBoosters(engine: Engine, held: Booster[], available: Booster[]) { + engine.tiles.boosters = {} as Engine["tiles"]["boosters"]; + for (const booster of available) engine.tiles.boosters[booster] = true; + engine.players.forEach((player, index) => { + player.removeRoundBoosterEvents(); + player.removeRoundBoosterEvents(Operator.Income); + engine.tiles.boosters[held[index]] = false; + player.getRoundBooster(held[index]); + // These lessons start after income; only the next booster pays next round. + player.removeRoundBoosterEvents(Operator.Income); + }); +} diff --git a/viewer/src/tutorial/tutorial.css b/viewer/src/tutorial/tutorial.css index fbc59558..2efb167b 100644 --- a/viewer/src/tutorial/tutorial.css +++ b/viewer/src/tutorial/tutorial.css @@ -219,6 +219,10 @@ outline: 3px solid #5194ce; outline-offset: 2px; } +.gaia-tutorial .bgs-tutorial-highlight { + outline: 2px solid #c17820; + outline-offset: 3px; +} .gaia-tutorial .tutorial-resource { display: inline; white-space: nowrap;