Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/specs/examples/stream-gameFinish-ai.json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
value:
{
"type": "gameFinish",
"game":
{
"fullId": "0jJlyweLDRZW",
"gameId": "0jJlyweL",
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"color": "white",
"lastMove": "",
"source": "ai",
"status": { "id": 25, "name": "aborted" },
"variant": { "key": "standard", "name": "Standard" },
"speed": "correspondence",
"perf": "correspondence",
"rated": false,
"hasMoved": false,
"opponent": { "id": null, "username": "Stockfish level 1", "ai": 1 },
"isMyTurn": false,
"compat": { "bot": false, "board": true },
"id": "0jJlyweL",
},
}
23 changes: 23 additions & 0 deletions doc/specs/examples/stream-gameStart-ai.json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
value:
{
"type": "gameStart",
"game":
{
"fullId": "0jJlyweLDRZW",
"gameId": "0jJlyweL",
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"color": "white",
"lastMove": "",
"source": "ai",
"status": { "id": 20, "name": "started" },
"variant": { "key": "standard", "name": "Standard" },
"speed": "correspondence",
"perf": "correspondence",
"rated": false,
"hasMoved": false,
"opponent": { "id": null, "username": "Stockfish level 1", "ai": 1 },
"isMyTurn": true,
"compat": { "bot": false, "board": true },
"id": "0jJlyweL",
},
}
41 changes: 28 additions & 13 deletions doc/specs/schemas/GameEventOpponent.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
type: object
properties:
id:
type: string
username:
type: string
rating:
type: integer

required:
- id
- username
- rating
oneOf:
- type: object
title: Player
properties:
id:
type: string
username:
type: string
rating:
type: integer
required:
- id
- username
- rating
- type: object
title: AI Opponent
properties:
id:
type: "null"
username:
type: string
ai:
type: integer
description: AI level, from 1 to 8, where 1 is the weakest and 8 is the strongest.
required:
- id
- username
- ai
4 changes: 4 additions & 0 deletions doc/specs/tags/board/api-stream-event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ get:
examples:
GameStartEvent:
$ref: "../../examples/stream-gameStart.json.yaml"
GameStartEvent (vs AI):
$ref: "../../examples/stream-gameStart-ai.json.yaml"
GameFinishEvent:
$ref: "../../examples/stream-gameFinish.json.yaml"
GameFinishEvent (vs AI):
$ref: "../../examples/stream-gameFinish-ai.json.yaml"
ChallengeEvent:
$ref: "../../examples/stream-challenge.json.yaml"
ChallengeDeclinedEvent:
Expand Down
41 changes: 41 additions & 0 deletions scripts/update-examples/challenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,47 @@ await (async () => {
});
})();

await (async () => {
const challenger = "yulia";

const abortController = new AbortController();
const signal = abortController.signal;
localClient(challenger)
.GET("/api/stream/event", {
headers: {
Accept: "application/x-ndjson",
},
signal,
parseAs: "stream",
})
.then((response) => {
readNdJson(response.response, (line: any) => {
if (line.type === "gameStart") {
example("stream", "gameStart-ai", line, "json", true);
} else if (line.type === "gameFinish") {
example("stream", "gameFinish-ai", line, "json", true);
abortController.abort();
}
});
});

const challenge = await localClient(challenger).POST(
"/api/challenge/ai",
{
body: {
level: 1,
}
},
);
await localClient(challenger).POST("/api/board/game/{gameId}/abort", {
params: {
path: {
gameId: challenge.data!.id!,
},
},
});
})();

await (async () => {
const abortController = new AbortController();
const signal = abortController.signal;
Expand Down