Support saved analyses of finished Container games
This commit is contained in:
parent
b8c88babf4
commit
30cdb46757
7 changed files with 71 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "container-engine",
|
||||
"version": "2.0.1",
|
||||
"version": "2.1.0",
|
||||
"description": "An engine for Container",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.ts",
|
||||
|
|
|
|||
|
|
@ -497,3 +497,26 @@ describe('wrapper (tentative turns)', () => {
|
|||
expect(platform.saved.currentPlayers).to.deep.equal([A]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saved analyses', () => {
|
||||
it('requires a finished source and reconstructs historical cash rather than final scores', () => {
|
||||
const source = setup(3, {}, 'analysis-cash');
|
||||
source.players[0].money = 999;
|
||||
expect(() => wrapper.createAnalysis(source, { to: 0, sourceEnded: false })).to.throw('finished');
|
||||
const copy = wrapper.createAnalysis(source, { to: 0, sourceEnded: true });
|
||||
expect(copy.players.map((p) => p.money)).to.deep.equal([20, 20, 20]);
|
||||
expect(source.players[0].money).to.equal(999);
|
||||
const view = wrapper.analysisView(copy, { player: 0 });
|
||||
expect(view.state.players[1].money).to.equal(20);
|
||||
expect(view.state.players[1].pointCard).not.to.equal(null);
|
||||
});
|
||||
it('can continue a historical position using each current player and the real costs', async () => {
|
||||
let copy = wrapper.createAnalysis(setup(3, {}, 'analysis-turns'), { to: 0, sourceEnded: true });
|
||||
const actor = copy.currentPlayers[0];
|
||||
copy = await wrapper.analysisMove(copy, pass, actor);
|
||||
expect(copy.currentPlayers[0]).not.to.equal(actor);
|
||||
const next = copy.currentPlayers[0];
|
||||
copy = await wrapper.analysisMove(copy, pass, next);
|
||||
expect(copy.currentPlayers[0]).not.to.equal(next);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -212,3 +212,31 @@ export function logSlice(G: GameState, options?: { player?: number; start?: numb
|
|||
.players.map((pl) => pl.availableMoves),
|
||||
};
|
||||
}
|
||||
|
||||
export const analysisPolicy = 'finished';
|
||||
|
||||
export function createAnalysis(G: GameState, options: { to: number; sourceEnded: boolean }): GameState {
|
||||
if (!options.sourceEnded) throw new Error('Analyses are available once this game has finished');
|
||||
if (options.to < 0 || options.to > G.log.length) throw new Error('Invalid history position');
|
||||
const copy = replay({ ...cloneDeep(G), log: G.log.slice(0, options.to), hiddenLog: [] });
|
||||
for (const player of copy.players) {
|
||||
player.isAI = false;
|
||||
player.isDropped = false;
|
||||
}
|
||||
copy.newTurn = true;
|
||||
return copy;
|
||||
}
|
||||
|
||||
export const analysisMove = move;
|
||||
|
||||
export function analysisView(G: GameState, options: { player: number; start?: number; end?: number }) {
|
||||
const state = cloneDeep(G);
|
||||
return {
|
||||
state,
|
||||
log: {
|
||||
state,
|
||||
log: state.log.slice(options.start, options.end),
|
||||
availableMoves: state.players.map((p) => p.availableMoves),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "container-viewer",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/boardgamers/container.git",
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@
|
|||
<template v-if="G">
|
||||
<template v-for="(p, i) in G.players">
|
||||
<PlayerBoard
|
||||
:open-money="preferences.analysis === true"
|
||||
:key="'B' + i"
|
||||
:player="p"
|
||||
:color="playerColors[i]"
|
||||
|
|
@ -566,12 +567,12 @@
|
|||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="journal-and-chat">
|
||||
<div class="journal-and-chat" :class="{ analysis: preferences.analysis }">
|
||||
<div class="mobile-panel-tabs"></div>
|
||||
<InlineLog id="container-journal-panel" v-if="G" :entries="logReversed.slice().reverse()" />
|
||||
<div id="container-chat-panel" class="chat-host"></div>
|
||||
</div>
|
||||
<div class="chat-shortcut-host"></div>
|
||||
<div class="chat-shortcut-host" v-show="!preferences.analysis"></div>
|
||||
</div>
|
||||
|
||||
<div v-if="G" :class="['modal', { visible: logVisible }]">
|
||||
|
|
@ -1993,6 +1994,16 @@ text {
|
|||
</style>
|
||||
|
||||
<style>
|
||||
.game .journal-and-chat.analysis .inline-game-log > summary {
|
||||
display: list-item;
|
||||
}
|
||||
.journal-and-chat.analysis {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.journal-and-chat.analysis > .chat-host,
|
||||
.journal-and-chat.analysis > .mobile-panel-tabs {
|
||||
display: none;
|
||||
}
|
||||
.journal-and-chat {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
|
|
|
|||
|
|
@ -198,6 +198,9 @@ import DropZone from './DropZone.vue';
|
|||
},
|
||||
})
|
||||
export default class PlayerBoard extends Vue {
|
||||
@Prop({ default: false })
|
||||
openMoney!: boolean;
|
||||
|
||||
@Prop()
|
||||
color?: string;
|
||||
|
||||
|
|
@ -224,6 +227,7 @@ export default class PlayerBoard extends Vue {
|
|||
}
|
||||
|
||||
name += this.player.name;
|
||||
if (this.openMoney && !this.ended) name += ' · $' + this.player.money;
|
||||
|
||||
if (this.player.showBid) {
|
||||
if (this.player.showAdditionalBid) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export interface UIData {
|
|||
}
|
||||
|
||||
export type Preferences = {
|
||||
analysis?: boolean;
|
||||
sound: boolean;
|
||||
disableHelp: boolean;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue