@journey-to-code/games 0.0.0-stage → 0.1.0
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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mikey Nichols
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { BoardGame } from "./board.js";
|
|
2
|
+
import { type BaseRules } from "./table.js";
|
|
3
|
+
export interface BackgammonRules extends BaseRules {
|
|
4
|
+
/** A match to this many points; 0 is a single game. */
|
|
5
|
+
match: number;
|
|
6
|
+
/** The doubling cube is in play. */
|
|
7
|
+
cube: boolean;
|
|
8
|
+
/** In a match: no doubling in the first game after a player comes within a point of winning. */
|
|
9
|
+
crawford: boolean;
|
|
10
|
+
/** In a single game with the cube: gammons and backgammons only count once the cube has been turned. */
|
|
11
|
+
jacoby: boolean;
|
|
12
|
+
/** In a single game with the cube: a tied opening roll doubles the stakes (once). */
|
|
13
|
+
autoDoubles: boolean;
|
|
14
|
+
/** Where the checkers start: the standard position, or Nackgammon's (two more checkers back). */
|
|
15
|
+
start: "standard" | "nack";
|
|
16
|
+
/** A turn isn't over until its player says so, and can be taken back until then. */
|
|
17
|
+
confirm: boolean;
|
|
18
|
+
/** Tapping a checker that has only one place to go plays it at once. */
|
|
19
|
+
quick: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const friendlyBackgammon: BackgammonRules;
|
|
22
|
+
export declare const moneyBackgammon: BackgammonRules;
|
|
23
|
+
export declare const match3Backgammon: BackgammonRules;
|
|
24
|
+
export declare const match5Backgammon: BackgammonRules;
|
|
25
|
+
export declare const match7Backgammon: BackgammonRules;
|
|
26
|
+
export declare const nackgammon: BackgammonRules;
|
|
27
|
+
/** One checker moved by one die, as the state remembers it (so it can be taken back). */
|
|
28
|
+
export interface BackgammonStep {
|
|
29
|
+
seat: number;
|
|
30
|
+
/** Where from and where to, as places of `stacks`; `to` is null for a checker borne off. */
|
|
31
|
+
from: number;
|
|
32
|
+
to: number | null;
|
|
33
|
+
/** Which of the dice was used. */
|
|
34
|
+
die: number;
|
|
35
|
+
/** A blot was hit and sent to the bar. */
|
|
36
|
+
hit: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface BackgammonResult {
|
|
39
|
+
winner: number;
|
|
40
|
+
kind: "single" | "gammon" | "backgammon";
|
|
41
|
+
/** The other player turned down a double. */
|
|
42
|
+
dropped: boolean;
|
|
43
|
+
/** A gammon that didn't count: the Jacoby rule, and the cube was never turned. */
|
|
44
|
+
jacoby: boolean;
|
|
45
|
+
points: number;
|
|
46
|
+
}
|
|
47
|
+
export interface BackgammonState {
|
|
48
|
+
game: "backgammon";
|
|
49
|
+
rules: BackgammonRules;
|
|
50
|
+
seats: number;
|
|
51
|
+
rng: number;
|
|
52
|
+
/** Which game of the match, from 1. */
|
|
53
|
+
round: number;
|
|
54
|
+
/**
|
|
55
|
+
* Who is where: 26 places, each a pile of checkers from the bottom up. 1 to 24 are the points as
|
|
56
|
+
* the first seat counts them (it travels from 24 down to 1, the second seat from 1 up to 24); 25
|
|
57
|
+
* is the first seat's bar and 0 the second's. Checkers 0 to 14 are the first seat's, 15 to 29 the
|
|
58
|
+
* second's, and each keeps its number all game.
|
|
59
|
+
*/
|
|
60
|
+
stacks: number[][];
|
|
61
|
+
/** The checkers each seat has borne off. */
|
|
62
|
+
home: number[][];
|
|
63
|
+
/**
|
|
64
|
+
* "opening": each rolls a die to see who starts. "roll": `turn` is to roll (or double first).
|
|
65
|
+
* "offer": `turn` has offered a double and the other seat must take or drop. "move": `turn` is
|
|
66
|
+
* playing its dice.
|
|
67
|
+
*/
|
|
68
|
+
phase: "opening" | "roll" | "offer" | "move" | "scored" | "finished";
|
|
69
|
+
turn: number;
|
|
70
|
+
/** The opening roll: what each seat has thrown so far. */
|
|
71
|
+
opening: (number | null)[];
|
|
72
|
+
/** The dice on the table (four of them for a double), which have been played, and who threw each. */
|
|
73
|
+
dice: number[];
|
|
74
|
+
used: boolean[];
|
|
75
|
+
thrower: number[];
|
|
76
|
+
/** How many throws there have been, so the table knows when to tumble the dice. */
|
|
77
|
+
rolls: number;
|
|
78
|
+
/** The moves made so far this turn. */
|
|
79
|
+
steps: BackgammonStep[];
|
|
80
|
+
/** The turn before, for marking where it went. */
|
|
81
|
+
last: BackgammonStep[];
|
|
82
|
+
cube: {
|
|
83
|
+
value: number;
|
|
84
|
+
owner: number | null;
|
|
85
|
+
turned: boolean;
|
|
86
|
+
};
|
|
87
|
+
/** Tied opening rolls that have doubled the stakes this game. */
|
|
88
|
+
autos: number;
|
|
89
|
+
/** This is the Crawford game; and whether the match has had one. */
|
|
90
|
+
crawford: boolean;
|
|
91
|
+
crawfordDone: boolean;
|
|
92
|
+
/** Points won so far (in a single game, what it was won for). */
|
|
93
|
+
score: number[];
|
|
94
|
+
result: BackgammonResult | null;
|
|
95
|
+
ready: boolean[];
|
|
96
|
+
narration: string | null;
|
|
97
|
+
}
|
|
98
|
+
export type BackgammonMove = {
|
|
99
|
+
type: "roll";
|
|
100
|
+
} | {
|
|
101
|
+
type: "move";
|
|
102
|
+
from: number;
|
|
103
|
+
to: number;
|
|
104
|
+
} | {
|
|
105
|
+
type: "undo";
|
|
106
|
+
} | {
|
|
107
|
+
type: "confirm";
|
|
108
|
+
} | {
|
|
109
|
+
type: "double";
|
|
110
|
+
} | {
|
|
111
|
+
type: "take";
|
|
112
|
+
} | {
|
|
113
|
+
type: "drop";
|
|
114
|
+
} | {
|
|
115
|
+
type: "next";
|
|
116
|
+
};
|
|
117
|
+
/** A step the seat to move may make now, as the table and `apply` name it. */
|
|
118
|
+
export interface BackgammonOption {
|
|
119
|
+
/** Cells of the board. */
|
|
120
|
+
from: number;
|
|
121
|
+
to: number;
|
|
122
|
+
/** The die it uses (its place among the dice on the table). */
|
|
123
|
+
die: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* What the player to move may do next: one checker by one die, each as the cell it leaves and the
|
|
127
|
+
* cell it lands in (the tray for a checker borne off). Two dice that would do the same thing are
|
|
128
|
+
* one option: the one that fits exactly is used, and failing that the bigger.
|
|
129
|
+
*/
|
|
130
|
+
export declare function backgammonSteps(s: BackgammonState): BackgammonOption[];
|
|
131
|
+
/** A whole turn as the player to move could play it: each step as cells, and how many of them hit. */
|
|
132
|
+
export interface BackgammonTurn {
|
|
133
|
+
steps: {
|
|
134
|
+
from: number;
|
|
135
|
+
to: number;
|
|
136
|
+
die: number;
|
|
137
|
+
}[];
|
|
138
|
+
}
|
|
139
|
+
/** Every whole turn the player to move could play with the dice still to play: one for each position it could leave. */
|
|
140
|
+
export declare function backgammonTurns(s: BackgammonState): BackgammonTurn[];
|
|
141
|
+
/** How far a seat still has to go: every checker's distance to being off, added up. */
|
|
142
|
+
export declare function backgammonPips(s: Pick<BackgammonState, "stacks" | "home">, seat: number): number;
|
|
143
|
+
export declare function newBackgammon(rules: BackgammonRules, _seats: number, seed: number): BackgammonState;
|
|
144
|
+
/** How much looking the computer players have done so far: for measuring what a move costs. */
|
|
145
|
+
export declare const backgammonWork: () => number;
|
|
146
|
+
export declare const backgammon: BoardGame<BackgammonRules, BackgammonState, BackgammonMove>;
|