@journey-to-code/games 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/backgammon.d.ts +146 -0
- package/dist/backgammon.js +1221 -0
- package/dist/backgammon.js.map +1 -0
- package/dist/blackjack.d.ts +66 -0
- package/dist/blackjack.js +452 -0
- package/dist/blackjack.js.map +1 -0
- package/dist/bluff.d.ts +60 -0
- package/dist/bluff.js +239 -0
- package/dist/bluff.js.map +1 -0
- package/dist/board.d.ts +387 -0
- package/dist/board.js +105 -0
- package/dist/board.js.map +1 -0
- package/dist/bridge.d.ts +86 -0
- package/dist/bridge.js +494 -0
- package/dist/bridge.js.map +1 -0
- package/dist/canasta.d.ts +88 -0
- package/dist/canasta.js +646 -0
- package/dist/canasta.js.map +1 -0
- package/dist/checkers.d.ts +108 -0
- package/dist/checkers.js +756 -0
- package/dist/checkers.js.map +1 -0
- package/dist/chess.d.ts +162 -0
- package/dist/chess.js +904 -0
- package/dist/chess.js.map +1 -0
- package/dist/chesscore.d.ts +136 -0
- package/dist/chesscore.js +1121 -0
- package/dist/chesscore.js.map +1 -0
- package/dist/combat.d.ts +102 -0
- package/dist/combat.js +772 -0
- package/dist/combat.js.map +1 -0
- package/dist/contractrummy.d.ts +77 -0
- package/dist/contractrummy.js +430 -0
- package/dist/contractrummy.js.map +1 -0
- package/dist/crazy8.d.ts +65 -0
- package/dist/crazy8.js +366 -0
- package/dist/crazy8.js.map +1 -0
- package/dist/cribbage.d.ts +75 -0
- package/dist/cribbage.js +428 -0
- package/dist/cribbage.js.map +1 -0
- package/dist/cuckoo.d.ts +43 -0
- package/dist/cuckoo.js +216 -0
- package/dist/cuckoo.js.map +1 -0
- package/dist/drinkingpyramid.d.ts +54 -0
- package/dist/drinkingpyramid.js +213 -0
- package/dist/drinkingpyramid.js.map +1 -0
- package/dist/drinks.d.ts +25 -0
- package/dist/drinks.js +40 -0
- package/dist/drinks.js.map +1 -0
- package/dist/dropfour.d.ts +103 -0
- package/dist/dropfour.js +577 -0
- package/dist/dropfour.js.map +1 -0
- package/dist/durak.d.ts +58 -0
- package/dist/durak.js +332 -0
- package/dist/durak.js.map +1 -0
- package/dist/euchre.d.ts +80 -0
- package/dist/euchre.js +453 -0
- package/dist/euchre.js.map +1 -0
- package/dist/fivedraw.d.ts +50 -0
- package/dist/fivedraw.js +289 -0
- package/dist/fivedraw.js.map +1 -0
- package/dist/fivehundred.d.ts +90 -0
- package/dist/fivehundred.js +504 -0
- package/dist/fivehundred.js.map +1 -0
- package/dist/freecell.d.ts +50 -0
- package/dist/freecell.js +327 -0
- package/dist/freecell.js.map +1 -0
- package/dist/fruitsalad.d.ts +69 -0
- package/dist/fruitsalad.js +427 -0
- package/dist/fruitsalad.js.map +1 -0
- package/dist/gin.d.ts +72 -0
- package/dist/gin.js +393 -0
- package/dist/gin.js.map +1 -0
- package/dist/go.d.ts +132 -0
- package/dist/go.js +659 -0
- package/dist/go.js.map +1 -0
- package/dist/goboard.d.ts +218 -0
- package/dist/goboard.js +880 -0
- package/dist/goboard.js.map +1 -0
- package/dist/gofish.d.ts +37 -0
- package/dist/gofish.js +235 -0
- package/dist/gofish.js.map +1 -0
- package/dist/golf.d.ts +64 -0
- package/dist/golf.js +343 -0
- package/dist/golf.js.map +1 -0
- package/dist/handfoot.d.ts +86 -0
- package/dist/handfoot.js +515 -0
- package/dist/handfoot.js.map +1 -0
- package/dist/hearts.d.ts +65 -0
- package/dist/hearts.js +390 -0
- package/dist/hearts.js.map +1 -0
- package/dist/holdem.d.ts +45 -0
- package/dist/holdem.js +286 -0
- package/dist/holdem.js.map +1 -0
- package/dist/horserace.d.ts +49 -0
- package/dist/horserace.js +207 -0
- package/dist/horserace.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/kingscorner.d.ts +59 -0
- package/dist/kingscorner.js +374 -0
- package/dist/kingscorner.js.map +1 -0
- package/dist/kingscup.d.ts +44 -0
- package/dist/kingscup.js +185 -0
- package/dist/kingscup.js.map +1 -0
- package/dist/kit.d.ts +283 -0
- package/dist/kit.js +73 -0
- package/dist/kit.js.map +1 -0
- package/dist/klondike.d.ts +57 -0
- package/dist/klondike.js +314 -0
- package/dist/klondike.js.map +1 -0
- package/dist/liarspoker.d.ts +61 -0
- package/dist/liarspoker.js +298 -0
- package/dist/liarspoker.js.map +1 -0
- package/dist/memory.d.ts +36 -0
- package/dist/memory.js +181 -0
- package/dist/memory.js.map +1 -0
- package/dist/minigolf.d.ts +104 -0
- package/dist/minigolf.js +724 -0
- package/dist/minigolf.js.map +1 -0
- package/dist/minigolfcourse.d.ts +127 -0
- package/dist/minigolfcourse.js +470 -0
- package/dist/minigolfcourse.js.map +1 -0
- package/dist/offers.d.ts +136 -0
- package/dist/offers.js +279 -0
- package/dist/offers.js.map +1 -0
- package/dist/ohhell.d.ts +66 -0
- package/dist/ohhell.js +331 -0
- package/dist/ohhell.js.map +1 -0
- package/dist/oldmaid.d.ts +40 -0
- package/dist/oldmaid.js +186 -0
- package/dist/oldmaid.js.map +1 -0
- package/dist/pinochle.d.ts +94 -0
- package/dist/pinochle.js +466 -0
- package/dist/pinochle.js.map +1 -0
- package/dist/pitch.d.ts +77 -0
- package/dist/pitch.js +362 -0
- package/dist/pitch.js.map +1 -0
- package/dist/poker.d.ts +79 -0
- package/dist/poker.js +268 -0
- package/dist/poker.js.map +1 -0
- package/dist/president.d.ts +56 -0
- package/dist/president.js +339 -0
- package/dist/president.js.map +1 -0
- package/dist/pyramid.d.ts +39 -0
- package/dist/pyramid.js +200 -0
- package/dist/pyramid.js.map +1 -0
- package/dist/registry.d.ts +17 -0
- package/dist/registry.js +70 -0
- package/dist/registry.js.map +1 -0
- package/dist/reversi.d.ts +69 -0
- package/dist/reversi.js +584 -0
- package/dist/reversi.js.map +1 -0
- package/dist/ridethebus.d.ts +48 -0
- package/dist/ridethebus.js +257 -0
- package/dist/ridethebus.js.map +1 -0
- package/dist/rummy500.d.ts +89 -0
- package/dist/rummy500.js +474 -0
- package/dist/rummy500.js.map +1 -0
- package/dist/sevens.d.ts +48 -0
- package/dist/sevens.js +221 -0
- package/dist/sevens.js.map +1 -0
- package/dist/slapjack.d.ts +42 -0
- package/dist/slapjack.js +224 -0
- package/dist/slapjack.js.map +1 -0
- package/dist/speed.d.ts +44 -0
- package/dist/speed.js +201 -0
- package/dist/speed.js.map +1 -0
- package/dist/spider.d.ts +51 -0
- package/dist/spider.js +320 -0
- package/dist/spider.js.map +1 -0
- package/dist/spite.d.ts +75 -0
- package/dist/spite.js +372 -0
- package/dist/spite.js.map +1 -0
- package/dist/sport.d.ts +266 -0
- package/dist/sport.js +48 -0
- package/dist/sport.js.map +1 -0
- package/dist/switch.d.ts +69 -0
- package/dist/switch.js +393 -0
- package/dist/switch.js.map +1 -0
- package/dist/table.d.ts +284 -0
- package/dist/table.js +67 -0
- package/dist/table.js.map +1 -0
- package/dist/talk.d.ts +17 -0
- package/dist/talk.js +44 -0
- package/dist/talk.js.map +1 -0
- package/dist/thirtyone.d.ts +66 -0
- package/dist/thirtyone.js +372 -0
- package/dist/thirtyone.js.map +1 -0
- package/dist/tictactoe.d.ts +68 -0
- package/dist/tictactoe.js +541 -0
- package/dist/tictactoe.js.map +1 -0
- package/dist/tricks.d.ts +21 -0
- package/dist/tricks.js +48 -0
- package/dist/tricks.js.map +1 -0
- package/dist/war.d.ts +44 -0
- package/dist/war.js +185 -0
- package/dist/war.js.map +1 -0
- package/dist/whist.d.ts +52 -0
- package/dist/whist.js +218 -0
- package/dist/whist.js.map +1 -0
- package/dist/yacht.d.ts +96 -0
- package/dist/yacht.js +653 -0
- package/dist/yacht.js.map +1 -0
- package/package.json +41 -4
- package/README.md +0 -3
package/dist/tricks.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The winning play: the highest trump if any was played, else the highest card of the suit led.
|
|
3
|
+
* `suitOf` says which suit a card counts as (Euchre's left bower is a trump), `power` how high it is.
|
|
4
|
+
*/
|
|
5
|
+
export function trickWinner(plays, trump, suitOf, power) {
|
|
6
|
+
const led = suitOf(plays[0].card);
|
|
7
|
+
let best = plays[0];
|
|
8
|
+
for (const p of plays.slice(1)) {
|
|
9
|
+
const s = suitOf(p.card);
|
|
10
|
+
const b = suitOf(best.card);
|
|
11
|
+
if (trump && s === trump && b !== trump)
|
|
12
|
+
best = p;
|
|
13
|
+
else if (s === b && power(p.card) > power(best.card))
|
|
14
|
+
best = p;
|
|
15
|
+
else if (!trump && s === led && b !== led)
|
|
16
|
+
best = p;
|
|
17
|
+
}
|
|
18
|
+
return best;
|
|
19
|
+
}
|
|
20
|
+
/** Cards that follow the suit led, or every card when you have none of it. */
|
|
21
|
+
export function following(hand, plays, suitOf) {
|
|
22
|
+
if (!plays.length)
|
|
23
|
+
return hand;
|
|
24
|
+
const led = suitOf(plays[0].card);
|
|
25
|
+
const same = hand.filter((c) => suitOf(c) === led);
|
|
26
|
+
return same.length ? same : hand;
|
|
27
|
+
}
|
|
28
|
+
/** Would this card win the trick if played now? */
|
|
29
|
+
export function wouldWin(card, seat, plays, trump, suitOf, power) {
|
|
30
|
+
if (!plays.length)
|
|
31
|
+
return true;
|
|
32
|
+
return trickWinner([...plays, { seat, card }], trump, suitOf, power).seat === seat;
|
|
33
|
+
}
|
|
34
|
+
/** For a player who wants this trick: the cheapest card that wins it now, or null. */
|
|
35
|
+
export function cheapestWinner(legal, seat, plays, trump, suitOf, power) {
|
|
36
|
+
const winners = legal.filter((c) => wouldWin(c, seat, plays, trump, suitOf, power));
|
|
37
|
+
return winners.sort((a, b) => strength(a, trump, suitOf, power) - strength(b, trump, suitOf, power))[0] ?? null;
|
|
38
|
+
}
|
|
39
|
+
/** For a player who doesn't want it: the strongest card that still loses, else the weakest card. */
|
|
40
|
+
export function bestLoser(legal, seat, plays, trump, suitOf, power) {
|
|
41
|
+
const losers = legal.filter((c) => plays.length && !wouldWin(c, seat, plays, trump, suitOf, power));
|
|
42
|
+
if (losers.length)
|
|
43
|
+
return losers.sort((a, b) => strength(b, trump, suitOf, power) - strength(a, trump, suitOf, power))[0];
|
|
44
|
+
return [...legal].sort((a, b) => strength(a, trump, suitOf, power) - strength(b, trump, suitOf, power))[0];
|
|
45
|
+
}
|
|
46
|
+
/** One number for how strong a card is overall: trumps above everything else. */
|
|
47
|
+
export const strength = (c, trump, suitOf, power) => power(c) + (trump && suitOf(c) === trump ? 100 : 0);
|
|
48
|
+
//# sourceMappingURL=tricks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tricks.js","sourceRoot":"","sources":["../src/tricks.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAkB,EAAE,MAA0B,EAAE,KAA2B;IACpH,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IACrB,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACzB,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK;YAAE,IAAI,GAAG,CAAC,CAAC;aAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,IAAI,GAAG,CAAC,CAAC;aAC1D,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;YAAE,IAAI,GAAG,CAAC,CAAC;IACt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AAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/war.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type BaseRules, type CardGame, type KCard } from "./kit.js";
|
|
2
|
+
export interface WarRules extends BaseRules {
|
|
3
|
+
/** Flips before the game ends and the most cards wins; 0 = until someone has them all. */
|
|
4
|
+
limit: number;
|
|
5
|
+
/** Cards each player puts face down in a war (then one face up). */
|
|
6
|
+
warDown: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const quickWar: WarRules;
|
|
9
|
+
export declare const longWar: WarRules;
|
|
10
|
+
export declare const littleWar: WarRules;
|
|
11
|
+
/** Even "until someone has them all" stops here, and the most cards wins. */
|
|
12
|
+
export declare const WAR_SAFETY_LIMIT = 2000;
|
|
13
|
+
type Phase = "flipping" | "finished";
|
|
14
|
+
export interface WarState {
|
|
15
|
+
game: "war";
|
|
16
|
+
rules: WarRules;
|
|
17
|
+
seats: number;
|
|
18
|
+
rng: number;
|
|
19
|
+
hand: number;
|
|
20
|
+
dealer: number;
|
|
21
|
+
phase: Phase;
|
|
22
|
+
/** Each player's face-down pile, top card first. */
|
|
23
|
+
decks: KCard[][];
|
|
24
|
+
/** Who has pressed Flip for the next battle. */
|
|
25
|
+
ready: boolean[];
|
|
26
|
+
battles: number;
|
|
27
|
+
/** The last battle: the face-up cards, who won, how many wars it took and how many cards were won. */
|
|
28
|
+
last: {
|
|
29
|
+
plays: {
|
|
30
|
+
seat: number;
|
|
31
|
+
card: KCard;
|
|
32
|
+
}[];
|
|
33
|
+
winner: number | null;
|
|
34
|
+
wars: number;
|
|
35
|
+
pot: number;
|
|
36
|
+
} | null;
|
|
37
|
+
narration: string | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function newWar(rules: WarRules, seats: number, seed: number): WarState;
|
|
40
|
+
type Move = {
|
|
41
|
+
type: "flip";
|
|
42
|
+
};
|
|
43
|
+
export declare const war: CardGame<WarRules, WarState, Move>;
|
|
44
|
+
export {};
|
package/dist/war.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { clone, FULL, GameError, makeDeck, markReady, nextRandom, rankLabel, rankSeats, shuffled, who, } from "./kit.js";
|
|
2
|
+
export const quickWar = { id: "war-quick", name: "Quick War (50 flips)", limit: 50, warDown: 3 };
|
|
3
|
+
export const longWar = { ...quickWar, id: "war-classic", name: "Classic (until someone has them all)", limit: 0 };
|
|
4
|
+
export const littleWar = { ...quickWar, id: "war-little", name: "Little war (one card down)", warDown: 1 };
|
|
5
|
+
/** Even "until someone has them all" stops here, and the most cards wins. */
|
|
6
|
+
export const WAR_SAFETY_LIMIT = 2000;
|
|
7
|
+
const rankOf = (c) => c.rank;
|
|
8
|
+
const name = (c) => rankLabel(rankOf(c));
|
|
9
|
+
const alive = (s) => s.decks.map((d, i) => i).filter((i) => s.decks[i].length > 0);
|
|
10
|
+
export function newWar(rules, seats, seed) {
|
|
11
|
+
const s = { game: "war", rules, seats, rng: seed >>> 0, hand: 0, dealer: seed % seats, battles: 0, last: null, narration: null };
|
|
12
|
+
const deck = shuffled(makeDeck({ ranks: FULL }), nextRandom(s));
|
|
13
|
+
s.decks = Array.from({ length: seats }, () => []);
|
|
14
|
+
deck.forEach((c, i) => s.decks[(s.dealer + 1 + i) % seats].push(c));
|
|
15
|
+
s.ready = Array.from({ length: seats }, () => false);
|
|
16
|
+
s.phase = "flipping";
|
|
17
|
+
return s;
|
|
18
|
+
}
|
|
19
|
+
/** One battle, wars and all. Everyone still holding cards has flipped. */
|
|
20
|
+
function battle(s) {
|
|
21
|
+
const rand = nextRandom(s);
|
|
22
|
+
const pot = [];
|
|
23
|
+
const shown = new Map();
|
|
24
|
+
let contenders = alive(s);
|
|
25
|
+
let wars = 0;
|
|
26
|
+
let winner = null;
|
|
27
|
+
for (let round = 0; round < 60 && contenders.length; round++) {
|
|
28
|
+
const flips = new Map();
|
|
29
|
+
for (const seat of contenders) {
|
|
30
|
+
const card = s.decks[seat].shift();
|
|
31
|
+
if (!card)
|
|
32
|
+
continue;
|
|
33
|
+
pot.push(card);
|
|
34
|
+
flips.set(seat, card);
|
|
35
|
+
shown.set(seat, card);
|
|
36
|
+
}
|
|
37
|
+
if (!flips.size)
|
|
38
|
+
break;
|
|
39
|
+
const best = Math.max(...[...flips.values()].map(rankOf));
|
|
40
|
+
const tied = [...flips.keys()].filter((seat) => rankOf(flips.get(seat)) === best);
|
|
41
|
+
if (tied.length === 1) {
|
|
42
|
+
winner = tied[0];
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
// War: the tied players put cards face down, keeping one to flip. Someone with nothing left to flip drops out.
|
|
46
|
+
wars++;
|
|
47
|
+
for (const seat of tied)
|
|
48
|
+
pot.push(...s.decks[seat].splice(0, Math.min(s.rules.warDown, Math.max(0, s.decks[seat].length - 1))));
|
|
49
|
+
const able = tied.filter((seat) => s.decks[seat].length > 0);
|
|
50
|
+
if (able.length === 1) {
|
|
51
|
+
winner = able[0];
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (!able.length)
|
|
55
|
+
break;
|
|
56
|
+
contenders = able;
|
|
57
|
+
}
|
|
58
|
+
if (winner !== null) {
|
|
59
|
+
// The winnings go under the winner's pile, mixed up (always the same order could loop forever).
|
|
60
|
+
s.decks[winner].push(...shuffled(pot, rand));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Everyone in the war ran out at once: the cards go back around, one each.
|
|
64
|
+
const back = alive(s).length ? alive(s) : [...shown.keys()];
|
|
65
|
+
shuffled(pot, rand).forEach((c, i) => s.decks[back[i % back.length]].push(c));
|
|
66
|
+
}
|
|
67
|
+
s.battles += 1;
|
|
68
|
+
s.last = { plays: [...shown].map(([seat, card]) => ({ seat, card })), winner, wars, pot: pot.length };
|
|
69
|
+
const plays = [...shown];
|
|
70
|
+
if (winner === null)
|
|
71
|
+
s.narration = "Nobody could finish the war: the cards went back around.";
|
|
72
|
+
else if (wars)
|
|
73
|
+
s.narration = `${wars > 1 ? `${wars} wars! ` : "War! "}The ${name(shown.get(winner))} wins it: ${pot.length} cards to ${who(winner)}`;
|
|
74
|
+
else if (plays.length === 2)
|
|
75
|
+
s.narration = `The ${name(shown.get(winner))} beats the ${name(plays.find(([seat]) => seat !== winner)[1])}: two cards to ${who(winner)}`;
|
|
76
|
+
else
|
|
77
|
+
s.narration = `The ${name(shown.get(winner))} is highest: ${plays.length} cards to ${who(winner)}`;
|
|
78
|
+
const limit = s.rules.limit || WAR_SAFETY_LIMIT;
|
|
79
|
+
if (alive(s).length <= 1 || s.battles >= limit)
|
|
80
|
+
s.phase = "finished";
|
|
81
|
+
s.ready = s.decks.map((d) => d.length === 0);
|
|
82
|
+
}
|
|
83
|
+
function apply(state, seat, move) {
|
|
84
|
+
const s = clone(state);
|
|
85
|
+
if (move.type !== "flip")
|
|
86
|
+
throw new GameError("That's not a move in War.");
|
|
87
|
+
if (s.phase !== "flipping")
|
|
88
|
+
throw new GameError("The game is over.");
|
|
89
|
+
if (!s.decks[seat].length)
|
|
90
|
+
throw new GameError("You're out of cards.");
|
|
91
|
+
if (markReady(s.ready, seat))
|
|
92
|
+
battle(s);
|
|
93
|
+
return s;
|
|
94
|
+
}
|
|
95
|
+
function winners(s) {
|
|
96
|
+
const counts = s.decks.map((d) => d.length);
|
|
97
|
+
const best = Math.max(...counts);
|
|
98
|
+
return counts.map((n, i) => (n === best ? i : -1)).filter((i) => i >= 0);
|
|
99
|
+
}
|
|
100
|
+
function view(s, seat) {
|
|
101
|
+
const over = s.phase === "finished";
|
|
102
|
+
const w = over ? winners(s) : [];
|
|
103
|
+
const waiting = !over && s.decks[seat].length > 0 && !s.ready[seat];
|
|
104
|
+
const limit = s.rules.limit;
|
|
105
|
+
return {
|
|
106
|
+
game: "war",
|
|
107
|
+
seats: s.seats,
|
|
108
|
+
me: seat,
|
|
109
|
+
teams: false,
|
|
110
|
+
phase: s.phase,
|
|
111
|
+
turn: null,
|
|
112
|
+
dealer: s.dealer,
|
|
113
|
+
hand: [],
|
|
114
|
+
handHidden: true,
|
|
115
|
+
tap: null,
|
|
116
|
+
pick: null,
|
|
117
|
+
choices: waiting ? { prompt: "", options: [{ label: "Flip!", move: { type: "flip" }, primary: true }] } : null,
|
|
118
|
+
players: s.decks.map((d) => ({ cards: d.length, line: d.length ? "" : "Out", out: d.length === 0 })),
|
|
119
|
+
center: {
|
|
120
|
+
kind: "trick",
|
|
121
|
+
plays: s.last?.plays ?? [],
|
|
122
|
+
winner: s.last?.winner ?? null,
|
|
123
|
+
lead: s.last?.wars ? `War${s.last.wars > 1 ? ` ×${s.last.wars}` : ""}! ${s.last.pot} cards` : null,
|
|
124
|
+
},
|
|
125
|
+
melds: [],
|
|
126
|
+
info: [limit ? `Flip ${Math.min(s.battles + (over ? 0 : 1), limit)} of ${limit}` : `Flip ${s.battles + (over ? 0 : 1)}`],
|
|
127
|
+
narration: s.narration,
|
|
128
|
+
scores: s.decks.map((d, i) => ({ seats: [i], value: d.length })),
|
|
129
|
+
result: null,
|
|
130
|
+
over: over ? { winners: w, title: w.length > 1 ? "It's a tie!" : s.decks[w[0]].length === 52 ? `${who(w[0])} won every card!` : `${who(w[0])} wins with ${s.decks[w[0]].length} cards` } : null,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function bot(s, seat, _style) {
|
|
134
|
+
return s.phase === "flipping" && s.decks[seat].length > 0 && !s.ready[seat] ? { type: "flip" } : null;
|
|
135
|
+
}
|
|
136
|
+
export const war = {
|
|
137
|
+
id: "war",
|
|
138
|
+
name: "War",
|
|
139
|
+
emoji: "⚔️",
|
|
140
|
+
blurb: "Flip, and the highest card takes all",
|
|
141
|
+
tagline: "Everybody flips, the highest card takes them all, and a tie means war.",
|
|
142
|
+
seats: { min: 2, max: 4, default: 2 },
|
|
143
|
+
teams: false,
|
|
144
|
+
presets: [quickWar, longWar, littleWar],
|
|
145
|
+
fields: [
|
|
146
|
+
{ key: "limit", label: "Game ends", kind: "choice", options: [[25, "After 25 flips"], [50, "After 50 flips"], [100, "After 100 flips"], [0, "When someone has every card"]] },
|
|
147
|
+
{ key: "warDown", label: "Cards down in a war", kind: "choice", options: [[1, "One"], [2, "Two"], [3, "Three"]] },
|
|
148
|
+
],
|
|
149
|
+
normalize(rules) {
|
|
150
|
+
const given = (rules && typeof rules === "object" ? rules : {});
|
|
151
|
+
const base = [quickWar, longWar, littleWar].find((p) => p.id === given.id) ?? quickWar;
|
|
152
|
+
const merged = { ...base, ...given };
|
|
153
|
+
return { ...merged, limit: Math.max(0, Math.round(Number(merged.limit) || 0)), warDown: Math.min(3, Math.max(1, Math.round(Number(merged.warDown) || 3))) };
|
|
154
|
+
},
|
|
155
|
+
validate: (r) => (r.limit < 0 || r.limit > 1000 ? ["Flips between 1 and 1,000 (or no limit)."] : []),
|
|
156
|
+
describe(r) {
|
|
157
|
+
return [
|
|
158
|
+
"The whole deck is dealt face down. Nobody looks.",
|
|
159
|
+
"Everybody flips their top card at once. Highest card takes them all (aces are high), under your pile.",
|
|
160
|
+
`A tie for highest is war: the tied players put ${r.warDown === 1 ? "a card" : `${r.warDown} cards`} face down and flip one more. Highest takes everything on the table. Run short of cards and you go to war with what you have.`,
|
|
161
|
+
r.limit ? `After ${r.limit} flips, whoever has the most cards wins.` : "Play until someone has every card.",
|
|
162
|
+
];
|
|
163
|
+
},
|
|
164
|
+
newGame: newWar,
|
|
165
|
+
apply,
|
|
166
|
+
view,
|
|
167
|
+
bot,
|
|
168
|
+
thinkingTime: () => 500,
|
|
169
|
+
summary(s) {
|
|
170
|
+
const over = s.phase === "finished";
|
|
171
|
+
return {
|
|
172
|
+
game: "war",
|
|
173
|
+
rules: s.rules.name,
|
|
174
|
+
phase: s.phase,
|
|
175
|
+
over,
|
|
176
|
+
hand: s.battles,
|
|
177
|
+
scoreLine: s.decks.map((d) => d.length).join(" · ") + " cards",
|
|
178
|
+
order: over ? rankSeats(s.decks.map((d, i) => ({ seats: [i], score: d.length }))) : null,
|
|
179
|
+
winners: over ? winners(s) : null,
|
|
180
|
+
teams: false,
|
|
181
|
+
seats: s.seats,
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=war.js.map
|
package/dist/war.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"war.js","sourceRoot":"","sources":["../src/war.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,EACL,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,GAAG,GAMJ,MAAM,UAAU,CAAC;AASlB,MAAM,CAAC,MAAM,QAAQ,GAAa,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,sBAAsB,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AAC3G,MAAM,CAAC,MAAM,OAAO,GAAa,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,sCAAsC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAC5H,MAAM,CAAC,MAAM,SAAS,GAAa,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AAErH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAsBrC,MAAM,MAAM,GAAG,CAAC,CAAQ,EAAE,EAAE,CAAE,CAAa,CAAC,IAAI,CAAC;AACjD,MAAM,IAAI,GAAG,CAAC,CAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,MAAM,KAAK,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC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O,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;YACjC,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/whist.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Suit } from "@journey-to-code/rules";
|
|
2
|
+
import { type BaseRules, type CardGame, type KCard } from "./kit.js";
|
|
3
|
+
import { type Play } from "./tricks.js";
|
|
4
|
+
export interface WhistRules extends BaseRules {
|
|
5
|
+
playTo: number;
|
|
6
|
+
/** A side holding all four honours (A K Q J of trump) scores 4; three of them, 2. */
|
|
7
|
+
honours: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const shortWhist: WhistRules;
|
|
10
|
+
export declare const longWhist: WhistRules;
|
|
11
|
+
export declare const honoursWhist: WhistRules;
|
|
12
|
+
type Phase = "playing" | "scored" | "finished";
|
|
13
|
+
export interface WhistState {
|
|
14
|
+
game: "whist";
|
|
15
|
+
rules: WhistRules;
|
|
16
|
+
seats: 4;
|
|
17
|
+
rng: number;
|
|
18
|
+
hand: number;
|
|
19
|
+
dealer: number;
|
|
20
|
+
phase: Phase;
|
|
21
|
+
hands: KCard[][];
|
|
22
|
+
trump: Suit;
|
|
23
|
+
/** The card turned up for trump: the dealer's, back in their hand once the first trick is played. */
|
|
24
|
+
turned: KCard;
|
|
25
|
+
trick: Play[];
|
|
26
|
+
lastTrick: {
|
|
27
|
+
plays: Play[];
|
|
28
|
+
winner: number;
|
|
29
|
+
} | null;
|
|
30
|
+
turn: number;
|
|
31
|
+
tricks: [number, number];
|
|
32
|
+
/** Honours (A K Q J of trump) each side was dealt. */
|
|
33
|
+
honoursHeld: [number, number];
|
|
34
|
+
scores: [number, number];
|
|
35
|
+
lastHand: {
|
|
36
|
+
tricks: [number, number];
|
|
37
|
+
odd: [number, number];
|
|
38
|
+
honours: [number, number];
|
|
39
|
+
} | null;
|
|
40
|
+
ready: boolean[];
|
|
41
|
+
narration: string | null;
|
|
42
|
+
}
|
|
43
|
+
export declare function newWhist(rules: WhistRules, _seats: number, seed: number): WhistState;
|
|
44
|
+
export declare const whistLegal: (s: WhistState, seat: number) => KCard[];
|
|
45
|
+
type Move = {
|
|
46
|
+
type: "play";
|
|
47
|
+
card: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: "next";
|
|
50
|
+
};
|
|
51
|
+
export declare const whist: CardGame<WhistRules, WhistState, Move>;
|
|
52
|
+
export {};
|
package/dist/whist.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { clone, FULL, GameError, makeDeck, markReady, nextHandChoices, nextRandom, rankLabel, rankSeats, shuffled, sortCards, SYMBOL, teamOfSeat, thinkFor, who, } from "./kit.js";
|
|
2
|
+
import { bestLoser, cheapestWinner, following, trickWinner } from "./tricks.js";
|
|
3
|
+
export const shortWhist = { id: "whist-short", name: "Short Whist (to 5)", playTo: 5, honours: false };
|
|
4
|
+
export const longWhist = { id: "whist-long", name: "Long Whist (to 7)", playTo: 7, honours: false };
|
|
5
|
+
export const honoursWhist = { id: "whist-honours", name: "With honours (to 5)", playTo: 5, honours: true };
|
|
6
|
+
const suitOf = (c) => c.suit;
|
|
7
|
+
const power = (c) => c.rank;
|
|
8
|
+
const isHonour = (c, trump) => suitOf(c) === trump && power(c) >= 11;
|
|
9
|
+
function deal(s) {
|
|
10
|
+
const deck = shuffled(makeDeck({ ranks: FULL }), nextRandom(s));
|
|
11
|
+
// Dealt one at a time from the dealer's left; the last card (the dealer's) is turned for trump.
|
|
12
|
+
s.hands = [[], [], [], []];
|
|
13
|
+
deck.forEach((c, i) => s.hands[(s.dealer + 1 + i) % 4].push(c));
|
|
14
|
+
s.turned = deck.at(-1);
|
|
15
|
+
s.trump = suitOf(s.turned);
|
|
16
|
+
s.honoursHeld = [0, 0];
|
|
17
|
+
s.hands.forEach((h, seat) => (s.honoursHeld[teamOfSeat(seat)] += h.filter((c) => isHonour(c, s.trump)).length));
|
|
18
|
+
s.hands = s.hands.map((h) => sortCards(h));
|
|
19
|
+
s.trick = [];
|
|
20
|
+
s.lastTrick = null;
|
|
21
|
+
s.tricks = [0, 0];
|
|
22
|
+
s.ready = [false, false, false, false];
|
|
23
|
+
s.turn = (s.dealer + 1) % 4;
|
|
24
|
+
s.phase = "playing";
|
|
25
|
+
s.narration = `${SYMBOL[s.trump]} is trump: ${who(s.dealer)} turned up the ${rankLabel(power(s.turned))}${SYMBOL[s.trump]}`;
|
|
26
|
+
}
|
|
27
|
+
export function newWhist(rules, _seats, seed) {
|
|
28
|
+
const s = { game: "whist", rules, seats: 4, rng: seed >>> 0, hand: 0, dealer: seed % 4, scores: [0, 0], lastHand: null };
|
|
29
|
+
deal(s);
|
|
30
|
+
return s;
|
|
31
|
+
}
|
|
32
|
+
export const whistLegal = (s, seat) => (s.phase === "playing" && s.turn === seat ? following(s.hands[seat], s.trick, suitOf) : []);
|
|
33
|
+
function apply(state, seat, move) {
|
|
34
|
+
const s = clone(state);
|
|
35
|
+
if (move.type === "next") {
|
|
36
|
+
if (s.phase !== "scored")
|
|
37
|
+
throw new GameError("The hand isn't over.");
|
|
38
|
+
if (markReady(s.ready, seat)) {
|
|
39
|
+
s.hand += 1;
|
|
40
|
+
s.dealer = (s.dealer + 1) % 4;
|
|
41
|
+
deal(s);
|
|
42
|
+
}
|
|
43
|
+
return s;
|
|
44
|
+
}
|
|
45
|
+
if (move.type !== "play")
|
|
46
|
+
throw new GameError("That's not a move in Whist.");
|
|
47
|
+
if (s.phase !== "playing" || s.turn !== seat)
|
|
48
|
+
throw new GameError("It's not your turn.");
|
|
49
|
+
const card = s.hands[seat].find((c) => c.id === move.card);
|
|
50
|
+
if (!card)
|
|
51
|
+
throw new GameError("You don't have that card.");
|
|
52
|
+
if (!whistLegal(s, seat).some((c) => c.id === card.id))
|
|
53
|
+
throw new GameError(`Follow ${SYMBOL[suitOf(s.trick[0].card)]} if you can.`);
|
|
54
|
+
if (!s.trick.length)
|
|
55
|
+
s.lastTrick = null;
|
|
56
|
+
s.hands[seat] = s.hands[seat].filter((c) => c.id !== card.id);
|
|
57
|
+
s.trick.push({ seat, card });
|
|
58
|
+
s.narration = null;
|
|
59
|
+
if (s.trick.length < 4) {
|
|
60
|
+
s.turn = (seat + 1) % 4;
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
63
|
+
const win = trickWinner(s.trick, s.trump, suitOf, power);
|
|
64
|
+
s.tricks[teamOfSeat(win.seat)] += 1;
|
|
65
|
+
s.lastTrick = { plays: s.trick, winner: win.seat };
|
|
66
|
+
s.trick = [];
|
|
67
|
+
s.turn = win.seat;
|
|
68
|
+
if (s.hands.every((h) => !h.length))
|
|
69
|
+
scoreHand(s);
|
|
70
|
+
return s;
|
|
71
|
+
}
|
|
72
|
+
function scoreHand(s) {
|
|
73
|
+
const odd = s.tricks.map((t) => Math.max(0, t - 6));
|
|
74
|
+
const honours = [0, 0];
|
|
75
|
+
if (s.rules.honours) {
|
|
76
|
+
const held = s.honoursHeld;
|
|
77
|
+
for (const t of [0, 1]) {
|
|
78
|
+
// Honours can't take a side to game from one point short (the old rule): they stop at one under.
|
|
79
|
+
const points = held[t] === 4 ? 4 : held[t] === 3 ? 2 : 0;
|
|
80
|
+
honours[t] = Math.max(0, Math.min(points, s.rules.playTo - 1 - s.scores[t] - odd[t]));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
s.scores = [s.scores[0] + odd[0] + honours[0], s.scores[1] + odd[1] + honours[1]];
|
|
84
|
+
s.lastHand = { tricks: [...s.tricks], odd, honours };
|
|
85
|
+
const side = odd[0] > 0 ? 0 : 1;
|
|
86
|
+
s.narration = `${who(side)} & ${who(side + 2)} took ${s.tricks[side]} tricks: ${odd[side]} over six`;
|
|
87
|
+
s.ready = [false, false, false, false];
|
|
88
|
+
s.phase = s.scores.some((n) => n >= s.rules.playTo) ? "finished" : "scored";
|
|
89
|
+
}
|
|
90
|
+
const winner = (s) => (s.scores[0] >= s.scores[1] ? 0 : 1);
|
|
91
|
+
function view(s, seat) {
|
|
92
|
+
const over = s.phase === "finished";
|
|
93
|
+
const w = over ? winner(s) : null;
|
|
94
|
+
const legal = whistLegal(s, seat);
|
|
95
|
+
const firstTrick = s.hands.reduce((n, h) => n + h.length, 0) + s.trick.length === 52;
|
|
96
|
+
return {
|
|
97
|
+
game: "whist",
|
|
98
|
+
seats: 4,
|
|
99
|
+
me: seat,
|
|
100
|
+
teams: true,
|
|
101
|
+
phase: s.phase,
|
|
102
|
+
turn: s.phase === "playing" ? s.turn : null,
|
|
103
|
+
dealer: s.dealer,
|
|
104
|
+
hand: s.hands[seat],
|
|
105
|
+
tap: legal.length ? { type: "play", cards: legal.map((c) => c.id) } : null,
|
|
106
|
+
pick: null,
|
|
107
|
+
choices: s.phase === "scored" ? nextHandChoices(s.ready, seat, false) : null,
|
|
108
|
+
players: s.hands.map((h, i) => ({ cards: h.length, line: "", team: teamOfSeat(i), dealer: i === s.dealer, badge: i === s.dealer && firstTrick ? `Turned ${rankLabel(power(s.turned))}${SYMBOL[s.trump]}` : undefined })),
|
|
109
|
+
center: { kind: "trick", plays: s.trick.length ? s.trick : (s.lastTrick?.plays ?? []), winner: s.trick.length ? null : (s.lastTrick?.winner ?? null) },
|
|
110
|
+
melds: [],
|
|
111
|
+
info: [`Trump ${SYMBOL[s.trump]}`, `Tricks ${s.tricks[teamOfSeat(seat)]} to ${s.tricks[1 - teamOfSeat(seat)]}`, `To ${s.rules.playTo}`],
|
|
112
|
+
narration: s.narration,
|
|
113
|
+
scores: [
|
|
114
|
+
{ seats: [0, 2], value: s.scores[0] },
|
|
115
|
+
{ seats: [1, 3], value: s.scores[1] },
|
|
116
|
+
],
|
|
117
|
+
result: s.lastHand && (s.phase === "scored" || over)
|
|
118
|
+
? {
|
|
119
|
+
key: `whist-${s.hand}`,
|
|
120
|
+
title: "Hand over",
|
|
121
|
+
sides: [
|
|
122
|
+
[0, 2],
|
|
123
|
+
[1, 3],
|
|
124
|
+
],
|
|
125
|
+
rows: [
|
|
126
|
+
{ label: "Tricks", values: s.lastHand.tricks.map(String) },
|
|
127
|
+
...(s.rules.honours ? [{ label: "Honours", values: s.lastHand.honours.map((n) => (n ? `+${n}` : "0")) }] : []),
|
|
128
|
+
{ label: "This hand", values: s.lastHand.odd.map((n, t) => n + s.lastHand.honours[t]).map((n) => (n ? `+${n}` : "0")), tone: "score" },
|
|
129
|
+
{ label: "Score", values: s.scores.map(String), tone: "total" },
|
|
130
|
+
],
|
|
131
|
+
}
|
|
132
|
+
: null,
|
|
133
|
+
over: w !== null ? { winners: [w, w + 2], title: `${who(w)} & ${who(w + 2)} win ${s.scores[w]} to ${s.scores[1 - w]}` } : null,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// ---- Computer players --------------------------------------------------------------------------
|
|
137
|
+
function bot(s, seat, style) {
|
|
138
|
+
if (s.phase === "scored")
|
|
139
|
+
return s.ready[seat] ? null : { type: "next" };
|
|
140
|
+
if (s.phase !== "playing" || s.turn !== seat)
|
|
141
|
+
return null;
|
|
142
|
+
const legal = whistLegal(s, seat);
|
|
143
|
+
const sloppy = Math.random() < (style.sloppy ?? 0) + (1 - (style.skill ?? 1)) * 0.3;
|
|
144
|
+
if (legal.length === 1 || sloppy)
|
|
145
|
+
return { type: "play", card: legal[Math.floor(Math.random() * legal.length)].id };
|
|
146
|
+
const hand = s.hands[seat];
|
|
147
|
+
const low = (cards) => [...cards].sort((a, b) => power(a) - power(b))[0];
|
|
148
|
+
if (!s.trick.length) {
|
|
149
|
+
// Lead an ace, else from the longest plain suit (keep trumps), low.
|
|
150
|
+
const aces = legal.filter((c) => power(c) === 14 && suitOf(c) !== s.trump);
|
|
151
|
+
if (aces.length)
|
|
152
|
+
return { type: "play", card: aces[0].id };
|
|
153
|
+
const plain = legal.filter((c) => suitOf(c) !== s.trump);
|
|
154
|
+
const pool = plain.length ? plain : legal;
|
|
155
|
+
const len = (c) => hand.filter((x) => suitOf(x) === suitOf(c)).length;
|
|
156
|
+
return { type: "play", card: [...pool].sort((a, b) => len(b) - len(a) || power(a) - power(b))[0].id };
|
|
157
|
+
}
|
|
158
|
+
const winning = trickWinner(s.trick, s.trump, suitOf, power);
|
|
159
|
+
const partner = teamOfSeat(winning.seat) === teamOfSeat(seat);
|
|
160
|
+
const last = s.trick.length === 3;
|
|
161
|
+
// Second hand low; partner winning: play low; otherwise win as cheaply as you can.
|
|
162
|
+
if (partner && (last || power(winning.card) >= 13 || suitOf(winning.card) === s.trump))
|
|
163
|
+
return { type: "play", card: bestLoser(legal, seat, s.trick, s.trump, suitOf, power).id };
|
|
164
|
+
if (s.trick.length === 1 && suitOf(legal[0]) === suitOf(s.trick[0].card) && !legal.some((c) => power(c) === 14))
|
|
165
|
+
return { type: "play", card: low(legal).id };
|
|
166
|
+
const win = cheapestWinner(legal, seat, s.trick, s.trump, suitOf, power);
|
|
167
|
+
return { type: "play", card: (win ?? bestLoser(legal, seat, s.trick, s.trump, suitOf, power)).id };
|
|
168
|
+
}
|
|
169
|
+
export const whist = {
|
|
170
|
+
id: "whist",
|
|
171
|
+
name: "Whist",
|
|
172
|
+
emoji: "🎩",
|
|
173
|
+
blurb: "Spades' grandparent: partners and tricks",
|
|
174
|
+
tagline: "The old parlour game: trump is turned up, partners sit across, and every trick over six counts.",
|
|
175
|
+
seats: { min: 4, max: 4, default: 4 },
|
|
176
|
+
teams: true,
|
|
177
|
+
presets: [shortWhist, longWhist, honoursWhist],
|
|
178
|
+
fields: [
|
|
179
|
+
{ key: "playTo", label: "Game to", kind: "choice", options: [[5, "5 (short whist)"], [7, "7 (long whist)"], [10, "10"]] },
|
|
180
|
+
{ key: "honours", label: "Honours", hint: "A side dealt all four of A K Q J of trump scores 4; three of them, 2.", kind: "toggle" },
|
|
181
|
+
],
|
|
182
|
+
normalize(rules) {
|
|
183
|
+
const given = (rules && typeof rules === "object" ? rules : {});
|
|
184
|
+
const base = [shortWhist, longWhist, honoursWhist].find((p) => p.id === given.id) ?? shortWhist;
|
|
185
|
+
return { ...base, ...given };
|
|
186
|
+
},
|
|
187
|
+
validate: (r) => (r.playTo >= 1 && r.playTo <= 20 ? [] : ["Play to between 1 and 20."]),
|
|
188
|
+
describe(r) {
|
|
189
|
+
return [
|
|
190
|
+
"Partners across. Thirteen cards each. The dealer's last card is turned face up: its suit is trump for the hand.",
|
|
191
|
+
"The player left of the dealer leads. Follow suit if you can; if you can't, play anything (a trump wins it). Highest trump, or highest card of the suit led, takes the trick.",
|
|
192
|
+
`Each trick your side takes over six scores a point.${r.honours ? " Honours: a side dealt all four of the ace, king, queen and jack of trump scores 4 more; three of them, 2 (but honours alone can't win the game)." : ""}`,
|
|
193
|
+
`First side to ${r.playTo} wins.`,
|
|
194
|
+
];
|
|
195
|
+
},
|
|
196
|
+
newGame: newWhist,
|
|
197
|
+
apply,
|
|
198
|
+
view,
|
|
199
|
+
bot,
|
|
200
|
+
thinkingTime: (s, seat) => (s.phase === "scored" ? 1400 : thinkFor(whistLegal(s, seat).length)),
|
|
201
|
+
summary(s) {
|
|
202
|
+
const over = s.phase === "finished";
|
|
203
|
+
const w = winner(s);
|
|
204
|
+
return {
|
|
205
|
+
game: "whist",
|
|
206
|
+
rules: s.rules.name,
|
|
207
|
+
phase: s.phase,
|
|
208
|
+
over,
|
|
209
|
+
hand: s.hand + 1,
|
|
210
|
+
scoreLine: `${s.scores[0]} to ${s.scores[1]}`,
|
|
211
|
+
order: over ? rankSeats([{ seats: [0, 2], score: s.scores[0] }, { seats: [1, 3], score: s.scores[1] }]) : null,
|
|
212
|
+
winners: over ? [w, w + 2] : null,
|
|
213
|
+
teams: true,
|
|
214
|
+
seats: 4,
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
//# sourceMappingURL=whist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whist.js","sourceRoot":"","sources":["../src/whist.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,EACL,IAAI,EACJ,SAAS,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