result states

This commit is contained in:
2025-08-31 22:23:30 -04:00
parent 0ea16ead64
commit b433a26fc6
7 changed files with 82 additions and 20 deletions

View File

@@ -1,10 +1,11 @@
import simple from "./simple";
export type Game<
S = unknown,
A = unknown,
E extends { error: any } = { error: any },
V = unknown
S = unknown, // state
A = unknown, // action
E extends { error: any } = { error: any }, // error
V = unknown, // view
R = unknown // results
> = {
title: string;
rules: string;
@@ -12,6 +13,7 @@ export type Game<
resolveAction: (p: { state: S; action: A; humanKey: string }) => S | E;
getView: (p: { state: S; humanKey: string }) => V;
resolveQuit: (p: { state: S; humanKey: string }) => S;
getResult: (state: S) => R | undefined;
};
export const GAMES: {

View File

@@ -101,6 +101,8 @@ export const resolveSimpleAction = ({
}
};
export type SimpleResult = string;
type SimpleError = { error: "whoops!" };
export default (config: SimpleConfiguration) =>
@@ -112,9 +114,14 @@ export default (config: SimpleConfiguration) =>
getView: ({ state, humanKey }) =>
getSimplePlayerView(config, state, humanKey),
resolveQuit: () => null,
getResult: (state) =>
Object.entries(state.playerHands).find(
([_, hand]) => hand.length === 2
)?.[0],
} satisfies Game<
SimpleGameState,
SimpleAction,
SimpleError,
SimplePlayerView
SimplePlayerView,
SimpleResult
>);

View File

@@ -50,3 +50,5 @@ export const setDiff = <T>(
});
export const set = <T>(arr: T[]) => new Set<T>(arr);
export const invert = <E>(obs: Observable<boolean, E>) => obs.map((o) => !o);