Readme

gameplay_agent

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

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
/**
* # Agent
*
* This module provides a way to create agents for games.
*
* Agents are http services that get POSTed a game state and return an action.
* If you define your agent with {@link Connect4Agent} or {@link PokerAgent},
* then you can use {@link agentHandler} to create an http service that
* serves it. The service it creates is a standard fetch handler that can be
* used with a variety of different http server libraries.
*
* For Example
*
* ## Deno
*
* ```ts
* import { agentHandler } from "@gameplay/games/agent";
* import { myConnect4Agent } from "./my_connect4_agent.ts";
*
* const handler = agentHandler([
* { game: GameKind.Connect4, agentname: "my-agent", agent: myConnect4Agent },
* ]});
*
* Deno.serve(handler);
* ```
*
* ## Val.Town
*
* ```ts
* import { agentHandler } from "@gameplay/games/agent";
* import { myConnect4Agent } from "./my_connect4_agent.ts";
*
* const handler = agentHandler([
* { game: GameKind.Connect4, agentname: "my-agent", agent: myConnect4Agent },
* ]});
*
* export default handler;
* ```
*
* ## Bun
*
* ```ts
* import { agentHandler } from "@gameplay/games/agent";
* import { myConnect4Agent } from "./my_connect4_agent.ts";
*
* const handler = agentHandler([
* { game: GameKind.Connect4, agentname: "my-agent", agent: myConnect4Agent },
* ]});
*
* Bun.serve({fetch: handler});
* ```
*
* More than one agent can be registered so you can have multiple agents served
* by the same http service.
*
* You must host your own agent service and make sure it's publically
* accessible. You could use a service like Vercel, Cloudflare Workers, or
* Deno Deploy. The best and easiest way to host your agent service is to use
* val.town.
*
* You can also write your own agent service that implements the same http
* interface as {@link agentHandler}. This means you can use python or go or any
* other language to write your agent service, but you don't get the benefit of
* having all the game logic that you do by writing your agent in javascript or
* typescript and using this library.
*
* @module
*/
import type { Connect4Agent, Connect4AsyncAgent } from "https://esm.town/v/saolsen/gameplay_connect4";
import type { GameKind, Json } from "https://esm.town/v/saolsen/gameplay_games";
import type { PokerAgent, PokerAsyncAgent } from "https://esm.town/v/saolsen/gameplay_poker";
/**
* A Connect4 Agent
*
* @template T The type of the agent data.
* * Must extend {@link Json} which restricts it to a JSON serializable type.
*/
export interface Connect4AgentSpec<
T extends Json = Json,
> {
game: GameKind.Connect4;
/** The name of the agent. */
agentname: string;
/** The agent function. */
agent: Connect4Agent<T> | Connect4AsyncAgent<T>;
}
/**
* A Poker Agent
*
* @template T The type of the agent data.
* * Must extend {@link Json} which restricts it to a JSON serializable type.*
*/
export interface PokerAgentSpec<
T extends Json = Json,
> {
game: GameKind.Poker;
/** The name of the agent. */
agentname: string;
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.