Support mixed Truthtrance questions in Richese auctions
Verify and publish checkpoint container / container (push) Canceled after 0s
Verify and publish checkpoint container / container (push) Canceled after 0s
This commit is contained in:
1 parent
1f3bc349ba
commit
6ce9a4b4a7
16 files changed
+504
-10
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { compileMixedActionExpression } from '../game/mixed-action-question';
|
||||
import { mixedRicheseBidResidual, type MixedRicheseBidClaim } from '../game/mixed-richese-bid-question';
|
||||
import { truthQuestionText, validateTruthQuestionReceipt, type TruthQuestion } from '../game/truthtrance';
|
||||
import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid';
|
||||
|
||||
const mixed: MixedRicheseBidClaim['mixed'] = {kind:'and',terms:[
|
||||
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},
|
||||
{kind:'or',terms:[{kind:'action',action:{minimum:4}},{kind:'action',action:{minimum:7}}]},
|
||||
]};
|
||||
|
||||
void test('Richese mixed bid reduction preserves the actual turn, public event and native threshold', () => {
|
||||
const claim: MixedRicheseBidClaim = {turn:3,event:'original-public-lot',mixed};
|
||||
const result = compileMixedActionExpression(mixed,() => 'yes',true);
|
||||
assert.deepEqual(mixedRicheseBidResidual(claim,result),{turn:3,event:'original-public-lot',minimum:4});
|
||||
assert.throws(() => mixedRicheseBidResidual({...claim,event:' stale '},result));
|
||||
assert.throws(() => mixedRicheseBidResidual(claim,compileMixedActionExpression(mixed,() => 'no',false)));
|
||||
});
|
||||
|
||||
void test('a Richese mixed bid question binds a current Once Around event without accepting old or extra metadata', () => {
|
||||
const f = createTruthRicheseBidFixture(false);
|
||||
const question: TruthQuestion = {kind:'mixedRicheseBid',target:f.target,turn:f.game.turn,event:f.lot,mixed};
|
||||
assert.doesNotThrow(() => validateTruthQuestionReceipt(f.game,f.asker,question));
|
||||
assert.match(truthQuestionText(question,id => id,id => id,id => id),/Richese auction/);
|
||||
assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,event:'stale-lot'}));
|
||||
assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,turn:f.game.turn+1}));
|
||||
assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,lot:1} as TruthQuestion));
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createElement, isValidElement, type ReactElement, type ReactNode } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { MixedBidFields, mixedBidInputError } from '../components/mixed-bid-fields';
|
||||
import { MixedRicheseBidPromises } from '../components/mixed-richese-bid-promises';
|
||||
import { Truthtrance } from '../components/truthtrance';
|
||||
import { viewGame, type Action, type Game, type GameView } from '../game/engine';
|
||||
import type { BidActionClaim } from '../game/mixed-bid-question';
|
||||
import type { MixedActionExpression } from '../game/mixed-action-question';
|
||||
import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid';
|
||||
import { createTruthRicheseSilentFixture } from './fixture-truth-richese-silent';
|
||||
import { actTruthtranceRichesePromises as act, passTruthRicheseFreshDiscard } from './fixture-truthtrance-richese-promises';
|
||||
|
||||
type Expr = MixedActionExpression<BidActionClaim>;
|
||||
type Fixture = ReturnType<typeof createTruthRicheseBidFixture> | ReturnType<typeof createTruthRicheseSilentFixture>;
|
||||
type Props = { children?: ReactNode; [key: string]: unknown };
|
||||
const expression: Expr = {kind:'and',terms:[
|
||||
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},
|
||||
{kind:'action',action:{minimum:4}},
|
||||
]};
|
||||
function elements(node: ReactNode): ReactElement<Props>[] {
|
||||
if (Array.isArray(node)) return node.flatMap(elements);
|
||||
if (!isValidElement<Props>(node)) return [];
|
||||
return [node,...elements(node.props.children)];
|
||||
}
|
||||
function ask(f: Fixture, source: Game) {
|
||||
let game = act(source,f.asker,{type:'card',card:f.truth});
|
||||
for (let n = 0; game.truthtrance?.stage === 'priority' && n < game.players.length; n++) {
|
||||
const seat = game.players.find(player => !game.truthtrance!.passed.includes(player.id)); assert.ok(seat);
|
||||
game = act(game,seat.id,{type:'truthPass'});
|
||||
}
|
||||
assert.equal(game.truthtrance?.stage,'ask');
|
||||
return game;
|
||||
}
|
||||
const truth = (game: GameView) => renderToStaticMarkup(createElement(Truthtrance,{game,busy:false,act() {}}));
|
||||
const panel = (game: GameView) => renderToStaticMarkup(createElement(MixedRicheseBidPromises,{game,busy:false,send() {}}));
|
||||
|
||||
for (const method of ['onceAround','silent'] as const) void test(
|
||||
`Advanced ${method} mixed Richese question controls show the right editor, answer and owned aggregate`, () => {
|
||||
const f = method === 'onceAround' ? createTruthRicheseBidFixture(true) : createTruthRicheseSilentFixture(true);
|
||||
const source = method === 'onceAround' ? act(f.game,f.asker,{type:'richeseBid',event:f.lot,amount:null}) : f.game;
|
||||
let game = ask(f,source);
|
||||
const asker = viewGame(game,f.asker);
|
||||
assert.ok(asker.truthMixedRicheseBidTargets.includes(f.target));
|
||||
assert.match(truth(asker),/Combine current facts and a Richese bid/);
|
||||
const fields = renderToStaticMarkup(createElement(MixedBidFields,{value:expression,game:asker,target:f.target,
|
||||
disabled:false,variant:'richese',onChange() {}}));
|
||||
assert.equal(mixedBidInputError(expression,asker,f.target,'richese'),null);
|
||||
assert.match(fields,method === 'silent' ? /Silent/ : /Once Around/);
|
||||
assert.match(fields,/one remaining accepted bid declaration/);
|
||||
assert.match(fields,/submitted bid amounts stay private/);
|
||||
assert.doesNotMatch(fields,/Ordinary bank auctions only/);
|
||||
const bad = {kind:'and',terms:[expression.terms[0],{kind:'action',action:{minimum:0}}]};
|
||||
assert.ok(mixedBidInputError(bad,asker,f.target,'richese'));
|
||||
|
||||
game = act(game,f.asker,{type:'truthAsk',question:{kind:'mixedRicheseBid',target:f.target,
|
||||
turn:game.turn,event:f.lot,mixed:expression}});
|
||||
const answer = truth(viewGame(game,f.target));
|
||||
assert.match(answer,/Answer the whole mixed question/);
|
||||
assert.match(answer,/Answer Yes/); assert.match(answer,/Answer No/);
|
||||
assert.match(answer,/Silent bids remain sealed/);
|
||||
assert.doesNotMatch(truth(viewGame(game,f.owner)),/Answer Yes/);
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.target,{type:'truthAnswer',answer:'yes'}));
|
||||
const target = viewGame(game,f.target), rendered = panel(target);
|
||||
assert.match(rendered,/Your mixed Richese bid promises/);
|
||||
assert.match(rendered,/You answered Yes/); assert.match(rendered,/at least 4 spice/);
|
||||
assert.match(rendered,/data-testid="mixed-richese-bid-promise-guide"/);
|
||||
assert.doesNotMatch(rendered,new RegExp(f.lot));
|
||||
assert.doesNotMatch(panel(viewGame(game,f.owner)),/Your mixed Richese bid promises/);
|
||||
});
|
||||
|
||||
void test('mixed Richese guide forwards its original legal action and refuses busy, foreign or stale receipts', () => {
|
||||
const f = createTruthRicheseSilentFixture(true);
|
||||
let game = ask(f,f.game);
|
||||
game = act(game,f.asker,{type:'truthAsk',question:{kind:'mixedRicheseBid',target:f.target,
|
||||
turn:game.turn,event:f.lot,mixed:expression}});
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.target,{type:'truthAnswer',answer:'yes'}));
|
||||
const view = viewGame(game,f.target), sent: Action[] = [];
|
||||
const props = {game:view,busy:false,send(action:Action) {sent.push(action);}};
|
||||
const tree = MixedRicheseBidPromises(props); assert.ok(tree);
|
||||
const button = elements(tree).find(element => element.props['data-testid'] === 'mixed-richese-bid-promise-guide'); assert.ok(button);
|
||||
(button.props.onClick as () => void)();
|
||||
assert.deepEqual(sent,[view.richeseBidPromiseGuide!.action]);
|
||||
props.busy = true;
|
||||
(button.props.onClick as () => void)(); assert.equal(sent.length,1);
|
||||
props.busy = false;
|
||||
view.mixedRicheseBidPromises[0].fulfilled = true;
|
||||
(button.props.onClick as () => void)(); assert.equal(sent.length,1);
|
||||
view.mixedRicheseBidPromises[0].fulfilled = false;
|
||||
view.richeseAuction!.event = 'later-lot';
|
||||
(button.props.onClick as () => void)(); assert.equal(sent.length,1);
|
||||
assert.doesNotMatch(panel(view),/data-testid="mixed-richese-bid-promise-guide"/);
|
||||
});
|
||||
@@ -0,0 +1,127 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import type { BidActionClaim } from '../game/mixed-bid-question';
|
||||
import type { MixedActionExpression } from '../game/mixed-action-question';
|
||||
import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid';
|
||||
import { createTruthRicheseSilentFixture } from './fixture-truth-richese-silent';
|
||||
import { actTruthtranceRichesePromises as act, passTruthRicheseFreshDiscard,
|
||||
truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player
|
||||
} from './fixture-truthtrance-richese-promises';
|
||||
|
||||
type Fixture = ReturnType<typeof createTruthRicheseBidFixture> | ReturnType<typeof createTruthRicheseSilentFixture>;
|
||||
type Expr = MixedActionExpression<BidActionClaim>;
|
||||
const fact = (value:number): Expr => ({kind:'fact',fact:{kind:'spice',compare:'gte',value}});
|
||||
const bid = (minimum:number): Expr => ({kind:'action',action:{minimum}});
|
||||
const mixed = (kind:'and'|'or', value:number, minimum = 4): Expr => ({kind,terms:[fact(value),bid(minimum)]});
|
||||
function reject(game:Game, actor:string, action:Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,actor,action));
|
||||
assert.deepEqual(game,before);
|
||||
}
|
||||
function ask(f:Fixture, source:Game, expression:Expr) {
|
||||
let game = act(source,f.asker,{type:'card',card:f.truth});
|
||||
for(let n=0;game.truthtrance?.stage === 'priority' && n<game.players.length;n++) {
|
||||
const seat = game.players.find(p => !game.truthtrance!.passed.includes(p.id)); assert.ok(seat);
|
||||
game = act(game,seat.id,{type:'truthPass'});
|
||||
}
|
||||
assert.equal(game.truthtrance?.stage,'ask');
|
||||
return act(game,f.asker,{type:'truthAsk',question:{kind:'mixedRicheseBid',target:f.target,
|
||||
turn:game.turn,event:f.lot,mixed:expression}});
|
||||
}
|
||||
function answer(f:Fixture, game:Game, choice:'yes'|'no') {
|
||||
return passTruthRicheseFreshDiscard(act(game,f.target,{type:'truthAnswer',answer:choice}));
|
||||
}
|
||||
|
||||
// Both fixture families originate in actual public setup and an original cache
|
||||
// lot; only their disclosed unopened deal/Spice ordering and scalar rolls are
|
||||
// controlled. No hand, wallet, bid, answer, or commitment is injected.
|
||||
for(const advanced of [false,true]) for(const method of ['onceAround','silent'] as const)
|
||||
for(const choice of ['yes','no'] as const) void test(
|
||||
`${advanced?'Advanced':'Basic'} ${method} mixed fact AND bid ${choice} constrains and settles the real lot`,() => {
|
||||
const f = method === 'onceAround' ? createTruthRicheseBidFixture(advanced) : createTruthRicheseSilentFixture(advanced);
|
||||
const source = method === 'onceAround' ? act(f.game,f.asker,{type:'richeseBid',event:f.lot,amount:null}) : f.game;
|
||||
assert.equal(player(source,f.target).spice,10);
|
||||
const expression = mixed('and',10), asked = ask(f,source,expression);
|
||||
assert.deepEqual(viewGame(asked,f.target).truthMixedRicheseBidAnswers,['yes','no']);
|
||||
assert.equal(viewGame(asked,f.asker).truthMixedRicheseBidAnswers,null);
|
||||
const bound = answer(f,asked,choice), projected = viewGame(bound,f.target);
|
||||
const aggregate = projected.mixedRicheseBidPromises.find(row => row.player === f.target); assert.ok(aggregate);
|
||||
assert.deepEqual(aggregate.mixed,expression);
|
||||
assert.equal(aggregate.fulfilled,false); assert.equal(aggregate.released,false);
|
||||
assert.equal(viewGame(bound,f.owner).mixedRicheseBidPromises.length,0);
|
||||
const guide = projected.richeseBidPromiseGuide; assert.ok(guide);
|
||||
assert.equal(guide.action.richeseBidPromiseId,aggregate.id);
|
||||
reject(bound,f.target,{...guide.action,richeseBidPromiseId:'stale-aggregate'});
|
||||
reject(bound,f.target,{...guide.action,event:'stale-lot'});
|
||||
reject(bound,f.target,{type:'richeseBid',event:f.lot,amount:choice === 'yes' ? 3 : 4,allyPayment:0});
|
||||
const amount = choice === 'yes' ? 4 : 2;
|
||||
let game = act(bound,f.target,{type:'richeseBid',event:f.lot,amount,allyPayment:0});
|
||||
assert.equal(player(game,f.target).spice,10,'The bid is not an early invoice');
|
||||
const receipt = viewGame(game,f.target).mixedRicheseBidPromises.find(row => row.player === f.target);
|
||||
assert.ok(receipt);
|
||||
assert.equal(receipt.id,aggregate.id); assert.equal(receipt.fulfilled,true); assert.equal(receipt.released,false);
|
||||
reject(game,f.target,guide.action);
|
||||
if(method === 'silent') {
|
||||
assert.equal(viewGame(game,f.target).richeseAuction?.ownBid,amount);
|
||||
assert.equal(viewGame(game,f.owner).richeseAuction?.ownBid,null);
|
||||
assert.equal(viewGame(game,f.owner).richeseAuction?.revealedBids,null);
|
||||
game = act(game,f.asker,{type:'richeseBid',event:f.lot,amount:0,allyPayment:0});
|
||||
game = act(game,f.owner,{type:'richeseBid',event:f.lot,amount:0,allyPayment:0});
|
||||
} else if(game.richeseAuction?.event === f.lot && game.richeseAuction.active === f.owner) {
|
||||
game = act(game,f.owner,{type:'richeseBid',event:f.lot,amount:null});
|
||||
}
|
||||
assert.ok(player(game,f.target).hand.some(card => card.id === f.card));
|
||||
assert.equal(player(game,f.target).spice,10-amount);
|
||||
assert.equal(game.discard.filter(card => card.id === f.truth).length,1);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
|
||||
for(const method of ['onceAround','silent'] as const) void test(
|
||||
`Advanced ${method} fact OR bid uses whole answer semantics and legal bot choices`,() => {
|
||||
const f = method === 'onceAround' ? createTruthRicheseBidFixture(true) : createTruthRicheseSilentFixture(true);
|
||||
const source = method === 'onceAround' ? act(f.game,f.asker,{type:'richeseBid',event:f.lot,amount:null}) : f.game;
|
||||
// False current fact makes the disjunction depend on the future bid.
|
||||
const asked = ask(f,source,mixed('or',11));
|
||||
assert.deepEqual(viewGame(asked,f.target).truthMixedRicheseBidAnswers,['yes','no']);
|
||||
for(const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(asked,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
|
||||
const proposed = botActions(view)[0]; assert.equal(proposed?.type,'truthAnswer',difficulty);
|
||||
const bound = passTruthRicheseFreshDiscard(act(structuredClone(asked),f.target,proposed));
|
||||
const bidView = viewGame(bound,f.target); bidView.players.find(row => row.id === f.target)!.bot = difficulty;
|
||||
const guide = bidView.richeseBidPromiseGuide; assert.ok(guide,difficulty);
|
||||
assert.deepEqual(botActions(bidView)[0],guide.action);
|
||||
assert.doesNotThrow(() => act(bound,f.target,guide.action));
|
||||
}
|
||||
// A true current fact makes OR inevitably true without any bid obligation.
|
||||
const always = ask(f,source,mixed('or',10));
|
||||
assert.deepEqual(viewGame(always,f.target).truthMixedRicheseBidAnswers,['yes']);
|
||||
reject(always,f.target,{type:'truthAnswer',answer:'no'});
|
||||
const settled = answer(f,always,'yes');
|
||||
assert.equal(viewGame(settled,f.target).richeseBidPromiseGuide,null);
|
||||
const aggregate = viewGame(settled,f.target).mixedRicheseBidPromises.find(row => row.player === f.target);
|
||||
assert.ok(aggregate); assert.equal(aggregate.fulfilled,true); assert.equal(aggregate.released,false);
|
||||
assert.ok(!(settled.richeseBidPromises ?? []).some(row => row.id === aggregate.id));
|
||||
assert.deepEqual(inventory(settled),f.originalCards);
|
||||
});
|
||||
|
||||
for(const advanced of [false,true]) void test(
|
||||
`${advanced?'Advanced':'Basic'} an opposing Once Around raise releases an impossible mixed Yes`,() => {
|
||||
const f = createTruthRicheseBidFixture(advanced);
|
||||
const asked = ask(f,f.game,mixed('or',11));
|
||||
let game = answer(f,asked,'yes');
|
||||
const before = viewGame(game,f.target).mixedRicheseBidPromises.find(row => row.player === f.target);
|
||||
assert.ok(before); assert.equal(before.fulfilled,false); assert.equal(before.released,false);
|
||||
assert.equal(viewGame(game,f.target).richeseBidPromiseGuide,null);
|
||||
game = act(game,f.asker,{type:'richeseBid',event:f.lot,amount:10,allyPayment:0});
|
||||
const after = viewGame(game,f.target).mixedRicheseBidPromises.find(row => row.id === before.id);
|
||||
assert.ok(after); assert.equal(after.fulfilled,false); assert.equal(after.released,true);
|
||||
game = act(game,f.target,{type:'richeseBid',event:f.lot,amount:null});
|
||||
if(game.richeseAuction?.event === f.lot && game.richeseAuction.active === f.owner)
|
||||
game = act(game,f.owner,{type:'richeseBid',event:f.lot,amount:null});
|
||||
assert.ok(player(game,f.asker).hand.some(card => card.id === f.card));
|
||||
assert.equal(player(game,f.target).spice,10);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
Reference in new issue
Block a user