Readme

gameplay_games

This is a val.town mirror of gameplay/games.

Click the link to see docs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Error helper for exhaustive switch cases.
*
* @example
* ```ts
* type X = "a" | "b";
* const x: X = "a";
* switch (x) {
* case "a": return "A";
* case "b": return "B";
* default: throw new Unreachable(x);
* }
* ```
*
* If you add a new case to X, the switch statement will be
* a type error because you can't assign the new case to the
* `never` type.
*/
export class Unreachable extends Error {
constructor(x: never) {
super(`Unreachable: ${x}`);
}
}
/** JSON serializable base types. See {@link Json}*/
export type JsonLiteral = string | number | boolean | null;
/**
* A type representing a JSON object. See {@link Json}
*/
export interface JsonObject {
/** Index signature */
[key: string]: Json;
}
/** A type representing a JSON serializable value. */
export type Json = JsonLiteral | JsonObject | Json[];
/** Cloneable base types. See {@link Clone}*/
export type CloneLiteral =
| undefined
| null
| boolean
| number
| string
| bigint
| Uint8Array
| Date
| RegExp;
/** A type representing a value that can be cloned with `structuredClone`. */
export type Clone = CloneLiteral | { [key: string]: Clone } | Clone[];
/**
* The different games.
* * Used to tag {@link Game}.
*/
export enum GameKind {
Connect4 = "connect4",
Poker = "poker",
}
/**
* The kind of player of a game.
* * Used to tag {@link Player}.
*/
export enum PlayerKind {
/** A real person (a user). */
User = "user",
/** An agent (a program playing the game). */
Agent = "agent",
}
/**
* Player of a game that is a real person (a user).
*/
export interface UserPlayer {
kind: typeof PlayerKind.User;
/** The username of the player. */
username: string;
}
/**
* Player of a game that is an agent (a program playing the game).
*/
export interface AgentPlayer {
kind: typeof PlayerKind.Agent;
/** The username of the user who created the agent. */
username: string;
/** The name of the agent. */
agentname: string;
}
/** A player in a game
* * {@link UserPlayer}: A real person.
* * {@link AgentPlayer}: An agent (a program playing the game).
*/
export type Player = UserPlayer | AgentPlayer;
/**
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 28, 2024