-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.ts
More file actions
31 lines (23 loc) · 1.18 KB
/
Copy pathquickstart.ts
File metadata and controls
31 lines (23 loc) · 1.18 KB
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
// Quickstart — read a game, see the board, build a reply. No network.
// node examples/quickstart.ts
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import * as op from "../src/index.ts";
import { render } from "../src/games/connect4.ts";
const HERE = dirname(fileURLToPath(import.meta.url));
const vec = (g: string) =>
JSON.parse(readFileSync(join(HERE, "..", "test", "vectors", g + ".json"), "utf8"))
.find((x: any) => x.kind === "move").url;
console.log("games:", Object.keys(op.gameList()).join(", "), "\n");
// read a real Connect 4 move
const m = op.read(vec("connect4"));
console.log(`game=${m.game} num=${m.num} turn->player${m.turn}`);
console.log("\nthe board (what an agent 'sees'):");
console.log(render(m.state));
console.log("\nlast move:", m.state.move);
// make a reply (your logic goes here; OpenPigeon ships none)
const reply = m.reply({ botId: "00000000-0000-4000-8000-OPENPIGEONBOT", state: m.state });
console.log("\nreply URL:", reply.slice(0, 70), "...");
console.log("decodes back to num =", op.read(reply).num);
console.log("\nfresh invite:", op.invite("pool").url.slice(0, 80), "...");