fix(viewer): clarify Automa passing and show earned VP
This commit is contained in:
parent
41032f9274
commit
217bbc8456
8 changed files with 248 additions and 56 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/old-ui",
|
||||
"version": "1.2.8",
|
||||
"version": "1.2.9",
|
||||
"scripts": {
|
||||
"serve": "vite --port 5193",
|
||||
"build": "vite build",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/viewer",
|
||||
"version": "5.22.8",
|
||||
"version": "5.22.9",
|
||||
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
|
||||
"contributors": [
|
||||
"coyotte508",
|
||||
|
|
|
|||
|
|
@ -1,58 +1,103 @@
|
|||
<template>
|
||||
<g
|
||||
class="automa-action-card"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-label="label"
|
||||
:title="label"
|
||||
v-b-tooltip.hover.nofade
|
||||
@click.stop="$emit('details')"
|
||||
@keydown.enter.prevent="$emit('details')"
|
||||
@keydown.space.prevent="$emit('details')"
|
||||
>
|
||||
<g class="automa-action-card" role="group" :aria-label="card ? `Action card ${card.id}` : 'Automa action'">
|
||||
<rect class="card-face" width="60" height="130" rx="5" />
|
||||
<g class="card-icons" aria-hidden="true">
|
||||
<rect x="2" y="2" width="56" height="20" rx="3" fill="#f1e5c9" />
|
||||
<path d="M19 5l-9 9h6l-2 7 9-10h-6Z" fill="#555" />
|
||||
<text v-if="card" x="43" y="16" class="card-number">#{{ card.id }}</text>
|
||||
<path v-if="passed" d="M15 72l9 9 20-22" fill="none" stroke="#333" stroke-width="3" />
|
||||
<template v-else-if="card">
|
||||
<g v-if="card.action === 'faction'" class="faction-action-reference">
|
||||
<g
|
||||
class="action-heading"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-label="label"
|
||||
:title="label"
|
||||
@click.stop="$emit('details')"
|
||||
@keydown.enter.prevent="$emit('details')"
|
||||
@keydown.space.prevent="$emit('details')"
|
||||
>
|
||||
<path d="M0 22V5Q0 0 5 0H55Q60 0 60 5V22Z" fill="#f1e5c9" />
|
||||
<g class="symbol-art" aria-hidden="true">
|
||||
<path d="M19 5l-9 9h6l-2 7 9-10h-6Z" fill="#555" />
|
||||
<text v-if="card" x="43" y="16" class="card-number">#{{ card.id }}</text>
|
||||
</g>
|
||||
</g>
|
||||
<template v-if="card">
|
||||
<g
|
||||
:class="['decision-symbol', 'card-action-symbol', { inactive: passed }]"
|
||||
role="img"
|
||||
tabindex="0"
|
||||
:aria-label="actionLabel"
|
||||
:title="actionLabel"
|
||||
v-b-tooltip.nofade="tooltipConfig"
|
||||
@click.stop
|
||||
>
|
||||
<rect
|
||||
class="symbol-hit-area"
|
||||
y="22"
|
||||
width="60"
|
||||
:height="card.action === 'faction' ? 108 : card.pass ? 47 : 63"
|
||||
/>
|
||||
<g v-if="card.action === 'faction'" class="symbol-art faction-action-reference" aria-hidden="true">
|
||||
<MobileActionIcon kind="special-actions" x="2" y="42" width="56" height="48" />
|
||||
<path d="M37 97l-14 14m0-9v9h9" fill="none" stroke="#555" stroke-width="2" />
|
||||
</g>
|
||||
<template v-else>
|
||||
<g v-else class="symbol-art" aria-hidden="true" :transform="`translate(30, ${card.pass ? 47 : 57})`">
|
||||
<Building
|
||||
v-if="card.action === 'build-mine'"
|
||||
building="m"
|
||||
:faction="player.faction"
|
||||
:flat="flat"
|
||||
:transform="`translate(30, 57) scale(${flat ? 4 : 2.5})`"
|
||||
/>
|
||||
<AutomaActionIcon
|
||||
v-else
|
||||
:icon="actionIcon"
|
||||
:faction="player.faction"
|
||||
:flat="flat"
|
||||
transform="translate(30, 57)"
|
||||
:transform="`scale(${flat ? 4 : 2.5})`"
|
||||
/>
|
||||
<AutomaActionIcon v-else :icon="actionIcon" :faction="player.faction" :flat="flat" />
|
||||
<g
|
||||
v-if="card.action === 'research-area-highest'"
|
||||
transform="translate(49, 48)"
|
||||
transform="translate(19, -9)"
|
||||
fill="none"
|
||||
stroke="#333"
|
||||
stroke-width="1.5"
|
||||
>
|
||||
<path d="M-3 2l3-3 3 3M-3-2l3-3 3 3" />
|
||||
</g>
|
||||
<Resource kind="vp" :count="card.victoryPoints" transform="translate(30, 105) scale(1.65)" />
|
||||
</template>
|
||||
</template>
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
v-if="card.action !== 'faction'"
|
||||
:class="['decision-symbol', 'card-vp-symbol', { inactive: passed }]"
|
||||
role="img"
|
||||
tabindex="0"
|
||||
:aria-label="pointsLabel"
|
||||
:title="pointsLabel"
|
||||
v-b-tooltip.nofade="tooltipConfig"
|
||||
@click.stop
|
||||
>
|
||||
<rect class="symbol-hit-area" :y="card.pass ? 69 : 85" width="60" :height="card.pass ? 33 : 45" />
|
||||
<g class="symbol-art" aria-hidden="true">
|
||||
<Resource
|
||||
kind="vp"
|
||||
:count="card.victoryPoints"
|
||||
:transform="`translate(30, ${card.pass ? 84 : 105}) scale(1.65)`"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
v-if="card.pass"
|
||||
:class="['decision-symbol', 'automa-pass-symbol', { active: passActive, inactive: !passActive }]"
|
||||
role="img"
|
||||
tabindex="0"
|
||||
:aria-label="passLabel"
|
||||
:title="passLabel"
|
||||
v-b-tooltip.nofade="tooltipConfig"
|
||||
@click.stop
|
||||
>
|
||||
<path class="symbol-hit-area pass-background" d="M0 102H60V125Q60 130 55 130H5Q0 130 0 125Z" />
|
||||
<path class="symbol-art" aria-hidden="true" d="M20 116l6 6 14-16" fill="none" stroke="#333" stroke-width="3" />
|
||||
</g>
|
||||
</template>
|
||||
<g v-else class="symbol-art" aria-hidden="true">
|
||||
<path v-if="passed" d="M15 72l9 9 20-22" fill="none" stroke="#333" stroke-width="3" />
|
||||
<g v-else transform="translate(18, 72)">
|
||||
<rect x="0" y="-13" width="19" height="26" rx="2" fill="#fff" stroke="#333" />
|
||||
<rect x="5" y="-10" width="19" height="26" rx="2" fill="#fff" stroke="#333" />
|
||||
</g>
|
||||
</g>
|
||||
<rect class="card-outline" width="60" height="130" rx="5" />
|
||||
</g>
|
||||
</template>
|
||||
|
||||
|
|
@ -63,6 +108,7 @@ import { cards } from "@gaia-project/engine/src/automa/cards";
|
|||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import type { AutomaIcon } from "../data/automa";
|
||||
import { automaFactionAction, describeAutomaAction } from "../data/automa";
|
||||
import { tooltipTriggerConfig } from "../logic/tooltip";
|
||||
import AutomaActionIcon from "./AutomaActionIcon.vue";
|
||||
import Building from "./Building.vue";
|
||||
import MobileActionIcon from "./MobileActionIcon.vue";
|
||||
|
|
@ -87,13 +133,16 @@ export default class AutomaDecisionCard extends Vue {
|
|||
kind: this.card.action === "upgrade" ? "upgrade" : this.card.action === "power-qic" ? "block" : "research",
|
||||
};
|
||||
}
|
||||
get label() {
|
||||
if (this.passed)
|
||||
return this.card
|
||||
? `Action card ${this.card.id}: Automa passed. This card's action and VP were not used. Show details`
|
||||
: "Automa passed after exhausting its deck. Show details";
|
||||
if (!this.card) return "Automa draws cards to choose its actions. Show details";
|
||||
const action = {
|
||||
get passActive() {
|
||||
return this.card?.pass && this.engine.automa.remaining < 3;
|
||||
}
|
||||
get passLabel() {
|
||||
return this.passActive
|
||||
? "This is one of the last three cards: Automa passes and scores the round tile. The support card chooses its next booster."
|
||||
: "Pass only when drawn among the last three cards. Drawn earlier, this card resolves its action and VP normally.";
|
||||
}
|
||||
get actionDescription() {
|
||||
return {
|
||||
"build-mine": "Build a mine",
|
||||
upgrade: "Upgrade a structure",
|
||||
"power-qic": "Block a power/Q.I.C. action",
|
||||
|
|
@ -101,33 +150,71 @@ export default class AutomaDecisionCard extends Vue {
|
|||
"research-area-random": "Advance a research track using numbered selection",
|
||||
faction: "Resolve the full faction action shown at the bottom left of the board",
|
||||
}[this.card.action];
|
||||
}
|
||||
get actionLabel() {
|
||||
return `${this.actionDescription}.${this.passed ? " Passing replaces this action." : ""}`;
|
||||
}
|
||||
get pointsLabel() {
|
||||
return this.passed
|
||||
? `${this.card.victoryPoints} VP for the card's action. Passing scores the round tile instead.`
|
||||
: `Gain ${this.card.victoryPoints} VP after this action, even if it cannot be completed.`;
|
||||
}
|
||||
get tooltipConfig() {
|
||||
return { trigger: `${tooltipTriggerConfig().trigger} focus`, html: false };
|
||||
}
|
||||
get label() {
|
||||
if (this.passed)
|
||||
return this.card
|
||||
? `Action card ${this.card.id}: Automa passed. Show details`
|
||||
: "Automa passed after exhausting its deck. Show details";
|
||||
if (!this.card) return "Automa draws cards to choose its actions. Show details";
|
||||
const vp =
|
||||
this.card.action === "faction"
|
||||
? this.factionAction.find((icon) => icon.kind === "vp").count
|
||||
: this.card.victoryPoints;
|
||||
const result = (this.engine.automa.lastActions ?? []).map(describeAutomaAction).join("; ");
|
||||
return `Action card ${this.card.id}: ${action}; ${vp} VP. Last turn: ${result || "no available action"}. Show details`;
|
||||
return `Action card ${this.card.id}: ${this.actionDescription}; ${vp} VP. Last turn: ${result || "no available action"}. Show details`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.automa-action-card {
|
||||
.action-heading {
|
||||
cursor: pointer;
|
||||
}
|
||||
.card-face {
|
||||
fill: #ffffffa0;
|
||||
}
|
||||
.card-outline {
|
||||
fill: none;
|
||||
stroke: #555;
|
||||
stroke-width: 1;
|
||||
pointer-events: none;
|
||||
}
|
||||
.automa-action-card:hover .card-face,
|
||||
.automa-action-card:focus-visible .card-face {
|
||||
.automa-action-card:hover .card-outline,
|
||||
.automa-action-card:focus-visible .card-outline {
|
||||
stroke: #2878aa;
|
||||
stroke-width: 2;
|
||||
}
|
||||
.card-icons {
|
||||
.symbol-art {
|
||||
pointer-events: none;
|
||||
}
|
||||
.decision-symbol {
|
||||
cursor: help;
|
||||
}
|
||||
.decision-symbol.inactive .symbol-art {
|
||||
opacity: 0.4;
|
||||
}
|
||||
.symbol-hit-area {
|
||||
fill: transparent;
|
||||
}
|
||||
.active .pass-background {
|
||||
fill: #e3eff6;
|
||||
}
|
||||
.decision-symbol:hover .symbol-hit-area,
|
||||
.decision-symbol:focus-visible .symbol-hit-area {
|
||||
stroke: #2878aa;
|
||||
}
|
||||
.card-number {
|
||||
text-anchor: middle;
|
||||
fill: #333;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
>
|
||||
<rect x="-5" y="-18" width="136" height="36" fill="transparent" />
|
||||
<g aria-hidden="true" class="status-icons">
|
||||
<g v-if="actions.length">
|
||||
<g v-if="hasLastTurn">
|
||||
<path
|
||||
d="M3 8a7 7 0 1 1 .5 6M3 3v5h5M10 6v4l3 2"
|
||||
transform="translate(-3, -10)"
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
<g v-for="(action, i) in actions" :key="i" :transform="`translate(${40 + i * 36}, 0)`">
|
||||
<g v-for="(action, i) in actions" :key="i" :transform="`translate(${40 + i * resultSpacing}, 0)`">
|
||||
<Building
|
||||
v-if="action[0] === 'build'"
|
||||
:building="action[1]"
|
||||
|
|
@ -57,6 +57,13 @@
|
|||
/>
|
||||
<path v-else-if="action[0] === 'pass'" d="M-9 1l6 6 14-16" fill="none" stroke="#333" stroke-width="3" />
|
||||
</g>
|
||||
<Resource
|
||||
v-if="victoryPoints"
|
||||
class="automa-last-vp"
|
||||
kind="vp"
|
||||
:count="victoryPoints"
|
||||
:transform="`translate(${40 + actions.length * resultSpacing}, 0) scale(1.4)`"
|
||||
/>
|
||||
</g>
|
||||
<g v-else>
|
||||
<rect x="2" y="-12" width="17" height="24" rx="2" fill="#fff" stroke="#333" />
|
||||
|
|
@ -93,7 +100,7 @@ import type Engine from "@gaia-project/engine";
|
|||
import type { Player } from "@gaia-project/engine";
|
||||
import { boardActions } from "@gaia-project/engine";
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import { describeAutomaAction } from "../data/automa";
|
||||
import { automaLastTurnPoints, describeAutomaAction } from "../data/automa";
|
||||
import { tooltipTriggerConfig } from "../logic/tooltip";
|
||||
import Building from "./Building.vue";
|
||||
import Condition from "./Condition.vue";
|
||||
|
|
@ -109,17 +116,26 @@ export default class AutomaStatus extends Vue {
|
|||
@Prop() engine: Engine;
|
||||
@Prop({ type: Boolean, default: false }) flat: boolean;
|
||||
|
||||
get hasLastTurn() {
|
||||
return !!this.engine.automa.action || (this.engine.passedPlayers ?? []).includes(this.player.player);
|
||||
}
|
||||
get actions() {
|
||||
const state = this.engine.automa;
|
||||
// A new round clears the action card, but still retains the previous round's lastActions.
|
||||
return state.action || (this.engine.passedPlayers ?? []).includes(this.player.player)
|
||||
? (state.lastActions ?? []).map((action) => action.split(" "))
|
||||
: [];
|
||||
return this.hasLastTurn ? (state.lastActions ?? []).map((action) => action.split(" ")) : [];
|
||||
}
|
||||
get victoryPoints() {
|
||||
return automaLastTurnPoints(this.engine, this.player);
|
||||
}
|
||||
get resultSpacing() {
|
||||
const count = this.actions.length + (this.victoryPoints ? 1 : 0);
|
||||
return Math.min(36, 72 / Math.max(1, count - 1));
|
||||
}
|
||||
get lastTurnLabel() {
|
||||
return this.actions.length
|
||||
? `Last Automa turn: ${this.actions.map((a) => describeAutomaAction(a.join(" "))).join("; ")}`
|
||||
: "Automa draws cards to choose its actions. It does not use normal resources.";
|
||||
if (!this.hasLastTurn) return "Automa draws cards to choose its actions. It does not use normal resources.";
|
||||
const results = this.actions.map((a) => describeAutomaAction(a.join(" ")));
|
||||
if (this.victoryPoints) results.push(`${this.victoryPoints} VP`);
|
||||
return `Last Automa turn: ${results.join("; ") || "no available action"}`;
|
||||
}
|
||||
get deckLabel() {
|
||||
return this.engine.round
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
@keydown.enter.prevent="$emit('details')"
|
||||
@keydown.space.prevent="$emit('details')"
|
||||
>
|
||||
<rect class="heading-hit-area" x="2" y="2" width="56" height="20" rx="3" />
|
||||
<path class="heading-hit-area" d="M0 22V5Q0 0 5 0H55Q60 0 60 5V22Z" />
|
||||
<g class="symbol-art" aria-hidden="true">
|
||||
<g class="robot-icon" transform="translate(17, 12)">
|
||||
<path d="M0-7v-3M-11-2v5M11-2v5" />
|
||||
|
|
@ -35,7 +35,8 @@
|
|||
v-b-tooltip.nofade="tooltipConfig"
|
||||
@click.stop
|
||||
>
|
||||
<rect class="symbol-highlight" x="-26" y="-12" width="52" height="25" rx="3" />
|
||||
<path v-if="symbol === 'numbered'" class="symbol-highlight" d="M-30-13H30V9Q30 14 25 14H-25Q-30 14-30 9Z" />
|
||||
<rect v-else class="symbol-highlight" x="-30" y="-13" width="60" height="26" />
|
||||
<g class="symbol-art" aria-hidden="true">
|
||||
<template v-if="symbol === 'scoring'">
|
||||
<rect
|
||||
|
|
@ -91,6 +92,7 @@
|
|||
</template>
|
||||
</g>
|
||||
</g>
|
||||
<rect class="card-outline" width="60" height="130" rx="5" />
|
||||
</g>
|
||||
</template>
|
||||
|
||||
|
|
@ -132,8 +134,12 @@ export default class AutomaSupportCard extends Vue {
|
|||
<style scoped>
|
||||
.card-face {
|
||||
fill: #fff;
|
||||
}
|
||||
.card-outline {
|
||||
fill: none;
|
||||
stroke: #555;
|
||||
stroke-width: 1.3;
|
||||
pointer-events: none;
|
||||
}
|
||||
.behavior-heading {
|
||||
cursor: pointer;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,9 @@ for (const component of [PlayerInfo, AlternatePlayerInfo]) {
|
|||
engine.tiles.scorings.final[1] = FinalTile.Sector;
|
||||
engine.automa.remaining = 5;
|
||||
engine.automa.lastActions = ["block power1", "block power3"];
|
||||
const move = engine.moveHistory.length;
|
||||
engine.moveHistory.push("itars automa 6,13 [block power1; block power3]");
|
||||
engine.advancedLog.push({ player: 1, move, changes: { itars: { vp: 4 } } });
|
||||
const store = makeStore();
|
||||
store.commit("receiveData", engine);
|
||||
const { container, getByRole } = render(component, { props: { player: engine.players[1] }, store });
|
||||
|
|
@ -87,6 +90,9 @@ for (const component of [PlayerInfo, AlternatePlayerInfo]) {
|
|||
expect(container.querySelector(".automa-details")).to.equal(null);
|
||||
expect(container.querySelector(".robot-icon")).not.to.equal(null);
|
||||
expect(container.querySelector(".automa-action-card .card-number").textContent).to.equal("#13");
|
||||
expect(container.querySelector(".automa-pass-symbol")).to.equal(null);
|
||||
expect(container.querySelector(".automa-last-vp").textContent.trim()).to.equal("4");
|
||||
expect(container.querySelector(".automa-last-turn").getAttribute("aria-label")).to.include("4 VP");
|
||||
expect(container.querySelectorAll(".automa-action-card .faction-action-reference .specialAction")).to.have.length(
|
||||
1
|
||||
);
|
||||
|
|
@ -115,10 +121,15 @@ for (const component of [PlayerInfo, AlternatePlayerInfo]) {
|
|||
expect(container.querySelector(".automa-details dl").textContent).to.include("Mining range");
|
||||
engine.automa.discard.push("13");
|
||||
engine.automa.action = "5";
|
||||
engine.automa.remaining = 3;
|
||||
store.commit("receiveData", Engine.fromData(JSON.parse(JSON.stringify(engine))));
|
||||
await Vue.nextTick();
|
||||
expect(action().classList.contains("recent")).to.equal(false);
|
||||
expect(action().classList.contains("disabled")).to.equal(false);
|
||||
expect(container.querySelector(".automa-pass-symbol.inactive")).not.to.equal(null);
|
||||
expect(container.querySelector(".card-action-symbol.inactive")).to.equal(null);
|
||||
expect(container.querySelector(".card-vp-symbol.inactive")).to.equal(null);
|
||||
expect(container.querySelector(".automa-pass-symbol").getAttribute("aria-label")).to.include("last three cards");
|
||||
engine.automa.action = "4";
|
||||
engine.automa.support = "8";
|
||||
engine.automa.lastActions = ["build m 1x1"];
|
||||
|
|
@ -129,12 +140,19 @@ for (const component of [PlayerInfo, AlternatePlayerInfo]) {
|
|||
).to.deep.equal(["scoring", "range", "direction"]);
|
||||
expect(container.querySelector('[data-support="range"]').textContent.trim()).to.equal("4");
|
||||
expect(container.querySelector(".automa-support-card").getAttribute("aria-label")).to.include("Support card 8");
|
||||
expect(container.querySelector(".automa-pass-symbol")).to.equal(null);
|
||||
engine.passedPlayers = [1];
|
||||
engine.automa.action = "8";
|
||||
engine.automa.remaining = 2;
|
||||
engine.automa.lastActions = ["pass booster4"];
|
||||
store.commit("receiveData", Engine.fromData(JSON.parse(JSON.stringify(engine))));
|
||||
await Vue.nextTick();
|
||||
expect(action().classList.contains("disabled")).to.equal(true);
|
||||
expect(container.querySelector('[data-support="booster"]')).not.to.equal(null);
|
||||
expect(container.querySelector(".automa-pass-symbol.active")).not.to.equal(null);
|
||||
expect(container.querySelector(".card-action-symbol.inactive")).not.to.equal(null);
|
||||
expect(container.querySelector(".card-vp-symbol.inactive").textContent.trim()).to.equal("3");
|
||||
expect(container.querySelector(".card-vp-symbol").getAttribute("aria-label")).to.include("round tile instead");
|
||||
engine.automa.support = engine.automa.action = undefined;
|
||||
store.commit("receiveData", Engine.fromData(JSON.parse(JSON.stringify(engine))));
|
||||
await Vue.nextTick();
|
||||
|
|
|
|||
41
viewer/src/data/automa.spec.ts
Normal file
41
viewer/src/data/automa.spec.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import Engine from "@gaia-project/engine";
|
||||
import { Phase } from "@gaia-project/engine/src/enums";
|
||||
import { expect } from "chai";
|
||||
import { automaLastTurnPoints } from "./automa";
|
||||
|
||||
const moves = [
|
||||
"init 1 solo-preview",
|
||||
"p1 faction terrans",
|
||||
"p2 faction itars",
|
||||
"p1 build m 6B3",
|
||||
"itars build m 5A4",
|
||||
"itars build m 4A3",
|
||||
"p1 build m 3A5",
|
||||
"itars booster booster-lostfleet-former",
|
||||
"p1 booster booster4",
|
||||
"terrans up eco (0 ⇒ 1).",
|
||||
"itars automa 3,7 [up int]",
|
||||
];
|
||||
|
||||
for (const [difficulty, points] of [
|
||||
["automa", 4],
|
||||
["alptrauma", 5],
|
||||
] as const) {
|
||||
it(`shows the actual Itars faction VP on ${difficulty} difficulty`, () => {
|
||||
const engine = new Engine(moves, { lostFleet: true, automaDifficulty: difficulty });
|
||||
const player = engine.players[1];
|
||||
expect(automaLastTurnPoints(engine, player)).to.equal(0);
|
||||
engine.move("terrans pass booster5");
|
||||
engine.move("itars automa 13");
|
||||
expect(engine.automa.lastActions).to.deep.equal(["block power4", "block power5"]);
|
||||
expect(automaLastTurnPoints(engine, player)).to.equal(points);
|
||||
// It stays attached to that turn, including after saving/loading, rather than
|
||||
// picking up unrelated later VP changes or the end-game totals.
|
||||
engine.advancedLog.push({ phase: Phase.EndGame });
|
||||
engine.advancedLog.push({ player: 1, changes: { itars: { vp: 20 } } });
|
||||
const loaded = Engine.fromData(JSON.parse(JSON.stringify(engine)));
|
||||
expect(automaLastTurnPoints(loaded, loaded.players[1])).to.equal(points);
|
||||
loaded.automa.action = undefined;
|
||||
expect(automaLastTurnPoints(loaded, loaded.players[1])).to.equal(0);
|
||||
});
|
||||
}
|
||||
|
|
@ -7,6 +7,30 @@ import { buildingData } from "./building";
|
|||
import { researchData } from "./research";
|
||||
import { spaceshipNames } from "./spaceships";
|
||||
|
||||
export function automaLastTurnPoints(engine: Engine, player: Player): number {
|
||||
if (!engine.automa?.action && !(engine.passedPlayers ?? []).includes(player.player)) return 0;
|
||||
let move = engine.moveHistory.length - 1;
|
||||
while (
|
||||
move >= 0 &&
|
||||
!engine.moveHistory[move].startsWith(`${player.faction} automa `) &&
|
||||
!engine.moveHistory[move].startsWith(`p${player.player + 1} automa `)
|
||||
)
|
||||
move--;
|
||||
if (move < 0) return 0;
|
||||
const start = engine.advancedLog.findIndex((entry) => entry.move === move);
|
||||
if (start < 0) return 0;
|
||||
let points = 0;
|
||||
for (const entry of engine.advancedLog.slice(start)) {
|
||||
// End-of-round income and final scoring are separate from the Automa turn.
|
||||
if (entry.phase !== undefined || entry.round !== undefined || (entry.move !== undefined && entry.move !== move))
|
||||
break;
|
||||
if (entry.player === player.player) {
|
||||
for (const change of Object.values(entry.changes ?? {})) points += change.vp ?? 0;
|
||||
}
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
const miningPreferences = {
|
||||
[FinalTile.Sector]: "a sector without an Automa planet",
|
||||
[FinalTile.PlanetType]: "a planet type Automa has not colonized",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue