we did it
This commit is contained in:
@@ -2,24 +2,24 @@ import simple from "./simple";
|
||||
|
||||
export type Game<
|
||||
S = unknown,
|
||||
A extends { humanKey: string } = { humanKey: string },
|
||||
A = unknown,
|
||||
E extends { error: any } = { error: any },
|
||||
V = unknown
|
||||
> = {
|
||||
title: string;
|
||||
rules: string;
|
||||
init: () => S;
|
||||
resolveAction: (p: { state: S; action: A }) => S | E;
|
||||
resolveAction: (p: { state: S; action: A; humanKey: string }) => S | E;
|
||||
getView: (p: { state: S; humanKey: string }) => V;
|
||||
resolveQuit: (p: { state: S; humanKey: string }) => S;
|
||||
};
|
||||
|
||||
export const GAMES = {
|
||||
export const GAMES: {
|
||||
[key: string]: (config: { game: string; players: string[] }) => Game;
|
||||
} = {
|
||||
// renaissance,
|
||||
simple,
|
||||
} satisfies {
|
||||
[key: string]: (config: { game: string; players: string[] }) => Game;
|
||||
};
|
||||
export default GAMES;
|
||||
|
||||
export type GameKey = keyof typeof GAMES;
|
||||
export type GameKey = string;
|
||||
|
||||
@@ -22,10 +22,7 @@ export type SimplePlayerView = {
|
||||
myHand: Hand<Card>;
|
||||
};
|
||||
|
||||
export type SimpleAction = { humanKey: string } & (
|
||||
| { type: "draw" }
|
||||
| { type: "discard"; card: Card }
|
||||
);
|
||||
export type SimpleAction = { type: "draw" } | { type: "discard"; card: Card };
|
||||
|
||||
export const newSimpleGameState = (
|
||||
config: SimpleConfiguration
|
||||
@@ -34,9 +31,7 @@ export const newSimpleGameState = (
|
||||
return {
|
||||
deck: shuffle(newDeck()),
|
||||
turnIdx: 0,
|
||||
playerHands: Object.fromEntries(
|
||||
players.map((humanKey) => [humanKey, []])
|
||||
),
|
||||
playerHands: Object.fromEntries(players.map((humanKey) => [humanKey, []])),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -59,12 +54,13 @@ export const resolveSimpleAction = ({
|
||||
config,
|
||||
state,
|
||||
action,
|
||||
humanKey,
|
||||
}: {
|
||||
config: SimpleConfiguration;
|
||||
state: SimpleGameState;
|
||||
action: SimpleAction;
|
||||
humanKey: string;
|
||||
}): SimpleGameState => {
|
||||
const { humanKey } = action;
|
||||
const playerHand = state.playerHands[humanKey];
|
||||
if (playerHand == null) {
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user