Order revealed sealed bids by seat and release viewer 2.0.16
This commit is contained in:
parent
cae924287c
commit
66632f1697
5 changed files with 95 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "container-viewer",
|
||||
"version": "2.0.15",
|
||||
"version": "2.0.16",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/boardgamers/container.git",
|
||||
|
|
|
|||
|
|
@ -738,6 +738,7 @@ import ColorBlindButton from './buttons/ColorBlindButton.vue';
|
|||
import { colorBadgeHtml } from '../color-blind';
|
||||
import { playerColors, playerTextColor, playerSymbol } from '../player-colors';
|
||||
import { journalPieces } from '../journal-pieces';
|
||||
import { journalOrder } from '../journal-order';
|
||||
import { Vue, Component, Prop, Watch, Provide, ProvideReactive } from 'vue-property-decorator';
|
||||
import { bidRevision, MoveName, ended, isLoanReversal, move as engineMove } from 'container-engine';
|
||||
import type { GameState, Move } from 'container-engine';
|
||||
|
|
@ -1867,7 +1868,7 @@ export default class Game extends Vue {
|
|||
get logReversed() {
|
||||
let logReversed: string[] = [];
|
||||
if (this.G && this.G.log) {
|
||||
this.G.log.forEach((log) => {
|
||||
journalOrder(this.G.log).forEach((log) => {
|
||||
if (log.type == 'phase') {
|
||||
logReversed.push('New phase: ' + log.phase);
|
||||
} else if (log.type == 'event') {
|
||||
|
|
@ -1893,7 +1894,7 @@ export default class Game extends Vue {
|
|||
get logReversedSimple() {
|
||||
let logReversed: string[] = [];
|
||||
if (this.G && this.G.log) {
|
||||
this.G.log.forEach((log) => {
|
||||
journalOrder(this.G.log).forEach((log) => {
|
||||
if (log.type == 'phase') {
|
||||
logReversed.push('New phase: ' + log.phase);
|
||||
} else if (log.type == 'event') {
|
||||
|
|
|
|||
31
viewer/src/journal-order.ts
Normal file
31
viewer/src/journal-order.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { LogItem, LogMove } from 'container-engine/src/log';
|
||||
import { MoveName } from 'container-engine/src/move';
|
||||
|
||||
/** Order revealed bids for display only; replay must retain the actual move order. */
|
||||
export function journalOrder(log: readonly LogItem[]): LogItem[] {
|
||||
const result = [...log];
|
||||
let slots: number[] = [];
|
||||
const seats = new Set<number>();
|
||||
const flush = () => {
|
||||
const bids = slots.map((index) => log[index] as LogMove).sort((a, b) => a.player - b.player);
|
||||
slots.forEach((index, i) => (result[index] = bids[i]));
|
||||
slots = [];
|
||||
seats.clear();
|
||||
};
|
||||
log.forEach((entry, index) => {
|
||||
if (entry.type === 'move' && entry.move.name === MoveName.Bid) {
|
||||
// A seat's second bid begins the additional-bid round. Keep the two
|
||||
// rounds separate, including in saved games without round metadata.
|
||||
if (seats.has(entry.player)) flush();
|
||||
seats.add(entry.player);
|
||||
slots.push(index);
|
||||
} else if (
|
||||
entry.type !== 'move' ||
|
||||
(entry.move.name !== MoveName.GetLoan && entry.move.name !== MoveName.PayLoan)
|
||||
) {
|
||||
flush();
|
||||
}
|
||||
});
|
||||
flush();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -246,6 +246,7 @@
|
|||
"Two colours in the supply are empty, so the game ends after this turn. Your island has 3 dark green, 2 white, 1 orange, 1 tan and 1 brown. Each player has a private card with different values for these colours. Your card determines your final score; the prices you paid at auction do not.": "供应区已有两种颜色耗尽,游戏在本回合结束后结算。你的岛上有 3 个深绿色、2 个白色、1 个橙色、1 个浅褐色和 1 个棕色集装箱。每人的秘密价值卡为各颜色赋予不同价值。最终得分取决于价值卡,而不是拍卖时支付的价格。",
|
||||
"Undo": "撤销",
|
||||
"Undo last move": "撤销上一步",
|
||||
"Undo my move": "撤销我的操作",
|
||||
"Unknown Container chapter": "未知的集装箱章节",
|
||||
"Unpaid loans": "未偿还贷款",
|
||||
"Upkeep": "维护",
|
||||
|
|
|
|||
59
viewer/tests/unit/journal-order.spec.ts
Normal file
59
viewer/tests/unit/journal-order.spec.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import Game from '@/components/Game.vue';
|
||||
import { journalOrder } from '@/journal-order';
|
||||
import { expect } from 'chai';
|
||||
import { LogItem, LogMove } from 'container-engine/src/log';
|
||||
import { MoveName } from 'container-engine/src/move';
|
||||
|
||||
const bid = (player: number, amount: number, additional = false): LogMove => ({
|
||||
type: 'move',
|
||||
player,
|
||||
move: { name: MoveName.Bid, data: true, extraData: { price: amount } },
|
||||
simple: `${player} bids ${additional ? 'additional ' : ''}$${amount}`,
|
||||
pretty: `${player} bids ${additional ? 'additional ' : ''}$${amount}`,
|
||||
});
|
||||
|
||||
describe('sealed bid journal order', () => {
|
||||
it('sorts by seat rather than submission or amount without mutating replay history', () => {
|
||||
const log = [bid(3, 0), bid(2, 8), bid(0, 4)];
|
||||
const before = JSON.stringify(log);
|
||||
expect(journalOrder(log)).to.deep.equal([log[2], log[1], log[0]]);
|
||||
expect(JSON.stringify(log)).to.equal(before);
|
||||
});
|
||||
|
||||
it('keeps initial and additional rounds separate and loans in their original slots', () => {
|
||||
const loan: LogMove = {
|
||||
type: 'move',
|
||||
player: 2,
|
||||
move: { name: MoveName.GetLoan, data: true },
|
||||
simple: 'loan',
|
||||
pretty: 'loan',
|
||||
};
|
||||
const log = [bid(3, 5), loan, bid(2, 5), bid(0, 0), bid(3, 0, true), bid(2, 2, true)];
|
||||
expect(journalOrder(log)).to.deep.equal([log[3], loan, log[2], log[0], log[5], log[4]]);
|
||||
});
|
||||
|
||||
it('does not mix successive auctions or other actions', () => {
|
||||
const accept: LogMove = {
|
||||
type: 'move',
|
||||
player: 0,
|
||||
move: { name: MoveName.Accept, data: 1 },
|
||||
simple: 'accept',
|
||||
pretty: 'accept',
|
||||
};
|
||||
const log: LogItem[] = [bid(2, 4), bid(1, 8), accept, bid(2, 3), bid(1, 2)];
|
||||
expect(journalOrder(log)).to.deep.equal([log[1], log[0], accept, log[4], log[3]]);
|
||||
expect(journalOrder([])).to.deep.equal([]);
|
||||
});
|
||||
|
||||
it('uses seat order in both the inline journal and plain-text platform log', () => {
|
||||
const options = (Game as any).options;
|
||||
const log = [bid(2, 0), bid(1, 7)];
|
||||
const context = { G: { log }, preferences: { colorBlind: false }, playerColors: [] };
|
||||
for (const name of ['logReversed', 'logReversedSimple']) {
|
||||
const entries = options.computed[name].get.call(context).reverse();
|
||||
expect(entries).to.have.length(2);
|
||||
expect(entries[0]).to.contain(log[1].simple);
|
||||
expect(entries[1]).to.contain(log[0].simple);
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue