kaggle-environments 1.22.6__py3-none-any.whl → 1.24.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaggle-environments might be problematic. Click here for more details.
- kaggle_environments/envs/connectx/visualizer/default/index.html +13 -0
- kaggle_environments/envs/connectx/visualizer/default/package.json +22 -0
- kaggle_environments/envs/connectx/visualizer/default/replays/test-replay.json +1129 -0
- kaggle_environments/envs/connectx/visualizer/default/src/main.ts +12 -0
- kaggle_environments/envs/connectx/visualizer/default/src/renderer.ts +396 -0
- kaggle_environments/envs/connectx/visualizer/default/src/style.css +38 -0
- kaggle_environments/envs/connectx/visualizer/default/tsconfig.json +4 -0
- kaggle_environments/envs/connectx/visualizer/default/vite.config.ts +7 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/repeated_poker.js +163 -88
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/index.html +13 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/package.json +23 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/replays/test-replay.json +1 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/scripts/print_first_steps.mjs +202 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/scripts/print_replay.mjs +215 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/scripts/print_steps_with_end_states.mjs +234 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/components/getRepeatedPokerStateForStep.js +260 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/components/utils.ts +61 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/debug_repeated_poker_renderer.ts +49 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/images/poker_chip_1.svg +22 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/images/poker_chip_10.svg +22 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/images/poker_chip_100.svg +48 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/images/poker_chip_25.svg +22 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/images/poker_chip_5.svg +22 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/main.ts +36 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/repeated_poker_renderer.ts +573 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/src/style.css +594 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/tsconfig.json +7 -0
- kaggle_environments/envs/open_spiel_env/games/repeated_poker/visualizer/default/vite.config.ts +6 -0
- kaggle_environments/envs/werewolf/README.md +190 -0
- kaggle_environments/envs/werewolf/harness/__init__.py +0 -0
- kaggle_environments/envs/werewolf/harness/base.py +773 -0
- kaggle_environments/envs/werewolf/harness/litellm_models.yaml +51 -0
- kaggle_environments/envs/werewolf/harness/main.py +54 -0
- kaggle_environments/envs/werewolf/harness/test_base.py +35 -0
- kaggle_environments/envs/werewolf/runner.py +146 -0
- kaggle_environments/envs/werewolf/scripts/__init__.py +0 -0
- kaggle_environments/envs/werewolf/scripts/add_audio.py +425 -0
- kaggle_environments/envs/werewolf/scripts/configs/audio/standard.yaml +24 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/block_basic.yaml +102 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/comprehensive.yaml +100 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/roundrobin_discussion_DisableDoctorSelfSave_DisableDoctorConsecutiveSave_large.yaml +104 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/roundrobin_discussion_large.yaml +103 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/roundrobin_discussion_small.yaml +103 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard.yaml +103 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_DisableDoctorSelfSave_DisableDoctorConsecutiveSave.yaml +104 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_DisableDoctorSelfSave_SeerRevealTeam.yaml +105 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_DisableDoctorSelfSave_SeerRevealTeam_NightEliminationNoReveal_DayExileNoReveal.yaml +105 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_DisableDoctorSelfSave_SeerRevealTeam_NightEliminationRevealTeam_DayExileRevealTeam.yaml +105 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_disable_doctor_self_save.yaml +103 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_parallel_voting.yaml +103 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_parallel_voting_no_tie_exile.yaml +103 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/rule_experiment/standard_parallel_voting_roundbiddiscussion.yaml +105 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/run_config.yaml +58 -0
- kaggle_environments/envs/werewolf/scripts/configs/run/vertex_api_example_config.yaml +115 -0
- kaggle_environments/envs/werewolf/scripts/measure_cost.py +251 -0
- kaggle_environments/envs/werewolf/scripts/plot_existing_trajectories.py +135 -0
- kaggle_environments/envs/werewolf/scripts/rerender_html.py +87 -0
- kaggle_environments/envs/werewolf/scripts/run.py +93 -0
- kaggle_environments/envs/werewolf/scripts/run_block.py +237 -0
- kaggle_environments/envs/werewolf/scripts/run_pairwise_matrix.py +222 -0
- kaggle_environments/envs/werewolf/scripts/self_play.py +196 -0
- kaggle_environments/envs/werewolf/scripts/utils.py +47 -0
- kaggle_environments/envs/werewolf/werewolf.json +1 -1
- {kaggle_environments-1.22.6.dist-info → kaggle_environments-1.24.3.dist-info}/METADATA +1 -1
- {kaggle_environments-1.22.6.dist-info → kaggle_environments-1.24.3.dist-info}/RECORD +68 -7
- {kaggle_environments-1.22.6.dist-info → kaggle_environments-1.24.3.dist-info}/WHEEL +0 -0
- {kaggle_environments-1.22.6.dist-info → kaggle_environments-1.24.3.dist-info}/entry_points.txt +0 -0
- {kaggle_environments-1.22.6.dist-info → kaggle_environments-1.24.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Player, PreactAdapter } from "@kaggle-environments/core";
|
|
2
|
+
import { Renderer } from "./renderer";
|
|
3
|
+
import "./style.css";
|
|
4
|
+
|
|
5
|
+
const app = document.getElementById("app");
|
|
6
|
+
if (!app) {
|
|
7
|
+
throw new Error("Could not find app element");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// TODO - fix this when we figure out a global format
|
|
11
|
+
const adapter = new PreactAdapter(Renderer as any);
|
|
12
|
+
new Player(app, adapter);
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { h, FunctionComponent } from "preact";
|
|
2
|
+
import { useEffect, useRef } from "preact/hooks";
|
|
3
|
+
import htm from "htm";
|
|
4
|
+
|
|
5
|
+
interface ReplayStep {
|
|
6
|
+
observation: Record<string, any>;
|
|
7
|
+
action: Record<string, any> | null;
|
|
8
|
+
reward: Record<string, number> | number | null;
|
|
9
|
+
info: Record<string, any>;
|
|
10
|
+
status: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ReplayData {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
steps: ReplayStep[][];
|
|
17
|
+
configuration: Record<string, any>;
|
|
18
|
+
info?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const html = htm.bind(h);
|
|
22
|
+
|
|
23
|
+
// --- Props Interface ---
|
|
24
|
+
interface RendererProps {
|
|
25
|
+
replay: ReplayData;
|
|
26
|
+
step: number;
|
|
27
|
+
agents: any[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// --- Constants and Drawing Paths (K, Goose) ---
|
|
31
|
+
const kPath = new Path2D(
|
|
32
|
+
`M78.3,96.5c-0.1,0.4-0.5,0.6-1.1,0.6H64.9c-0.7,0-1.4-0.3-1.9-1l-20.3-26L37,75.5v20.1 c0,0.9-0.5,1.4-1.4,1.4H26c-0.9,0-1.4-0.5-1.4-1.4V3.9c0-0.9,0.5-1.4,1.4-1.4h9.5C36.5,2.5,37,3,37,3.9v56.5l24.3-24.7 c0.6-0.6,1.3-1,1.9-1H76c0.6,0,0.9,0.2,1.1,0.7c0.2,0.6,0.1,1-0.1,1.2l-25.7,25L78,95.1C78.4,95.5,78.5,95.9,78.3,96.5z`
|
|
33
|
+
);
|
|
34
|
+
const goose1Path = new Path2D(
|
|
35
|
+
`M8.8,92.7c-4-18.5,4.7-37.2,20.7-46.2c0,0,2.7-1.4,3.4-1.9c2.2-1.6,3-2.1,3-5c0-5-2.1-7.2-2.1-7.2 c-3.9-3.3-6.3-8.2-6.3-13.7c0-10,8.1-18.1,18.1-18.1s18.1,8.1,18.1,18.1c0,6-1.5,32.7-2.3,38.8l-0.1,1`
|
|
36
|
+
);
|
|
37
|
+
const goose2Path = new Path2D(`M27.4,19L8.2,27.6c0,0-7.3,2.9,2.6,5c6.1,1.3,24,5.9,24,5.9l1,0.3`);
|
|
38
|
+
const goose3Path = new Path2D(`M63.7,99.6C52.3,99.6,43,90.3,43,78.9s9.3-20.7,20.7-20.7c10.6,0,34.4,0.1,35.8,9`);
|
|
39
|
+
|
|
40
|
+
const getColor = (mark: number, opacity = 1) => {
|
|
41
|
+
if (mark === 1) return `rgba(0, 255, 255, ${opacity})`; // Cyan
|
|
42
|
+
if (mark === 2) return `rgba(255, 255, 255, ${opacity})`; // White
|
|
43
|
+
return "#fff";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// --- Helper function to draw a token to a canvas and get a Data URL ---
|
|
47
|
+
const getTokenAsDataURL = (mark: number): string => {
|
|
48
|
+
const canvas = document.createElement("canvas");
|
|
49
|
+
canvas.width = 100;
|
|
50
|
+
canvas.height = 100;
|
|
51
|
+
const c = canvas.getContext("2d");
|
|
52
|
+
if (!c) return "";
|
|
53
|
+
|
|
54
|
+
// This is a simplified version of the main drawPiece function
|
|
55
|
+
c.fillStyle = getColor(mark, 0.1);
|
|
56
|
+
c.strokeStyle = getColor(mark);
|
|
57
|
+
c.shadowColor = getColor(mark);
|
|
58
|
+
c.shadowBlur = 8;
|
|
59
|
+
c.lineWidth = 1;
|
|
60
|
+
|
|
61
|
+
c.save();
|
|
62
|
+
c.beginPath();
|
|
63
|
+
c.arc(50, 50, 50, 0, 2 * Math.PI);
|
|
64
|
+
c.closePath();
|
|
65
|
+
c.lineWidth *= 4;
|
|
66
|
+
c.stroke();
|
|
67
|
+
c.fill();
|
|
68
|
+
c.restore();
|
|
69
|
+
|
|
70
|
+
c.beginPath();
|
|
71
|
+
c.arc(50, 50, 40, 0, 2 * Math.PI);
|
|
72
|
+
c.closePath();
|
|
73
|
+
c.stroke();
|
|
74
|
+
|
|
75
|
+
if (mark === 1) {
|
|
76
|
+
const scale = 0.54;
|
|
77
|
+
c.save();
|
|
78
|
+
c.translate(23, 23);
|
|
79
|
+
c.scale(scale, scale);
|
|
80
|
+
c.lineWidth /= scale;
|
|
81
|
+
c.shadowBlur /= scale;
|
|
82
|
+
c.stroke(kPath);
|
|
83
|
+
c.restore();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (mark === 2) {
|
|
87
|
+
const scale = 0.6;
|
|
88
|
+
c.save();
|
|
89
|
+
c.translate(24, 28);
|
|
90
|
+
c.scale(scale, scale);
|
|
91
|
+
c.lineWidth /= scale;
|
|
92
|
+
c.shadowBlur /= scale;
|
|
93
|
+
c.stroke(goose1Path);
|
|
94
|
+
c.stroke(goose2Path);
|
|
95
|
+
c.stroke(goose3Path);
|
|
96
|
+
c.beginPath();
|
|
97
|
+
c.arc(38.5, 18.6, 2.7, 0, Math.PI * 2);
|
|
98
|
+
c.closePath();
|
|
99
|
+
c.fill();
|
|
100
|
+
c.restore();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return canvas.toDataURL();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// --- Game Status Component ---
|
|
107
|
+
const GameStatus: FunctionComponent<RendererProps> = ({ replay, step, agents }) => {
|
|
108
|
+
const isLastStep = step === replay.steps.length - 1;
|
|
109
|
+
if (!isLastStep) {
|
|
110
|
+
return html`<div class="status-bar"></div>`; // Reserve space
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const finalStep = replay.steps[step];
|
|
114
|
+
const winnerStep = finalStep.find((agentStep) => agentStep.reward === 1);
|
|
115
|
+
|
|
116
|
+
let message = "Game Over";
|
|
117
|
+
let tokenUrl = null;
|
|
118
|
+
|
|
119
|
+
if (winnerStep) {
|
|
120
|
+
const winnerIndex = finalStep.indexOf(winnerStep);
|
|
121
|
+
const winnerAgent = agents.find((a) => a.index === winnerIndex);
|
|
122
|
+
tokenUrl = getTokenAsDataURL(winnerIndex + 1);
|
|
123
|
+
let winnerName = null;
|
|
124
|
+
if (winnerAgent && winnerAgent.name) {
|
|
125
|
+
winnerName = winnerAgent.name;
|
|
126
|
+
} else if (replay.info && replay.info.TeamNames && replay.info.TeamNames[winnerIndex]) {
|
|
127
|
+
winnerName = replay.info.TeamNames[winnerIndex];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (winnerName) {
|
|
131
|
+
message = `Winner: ${winnerName}`;
|
|
132
|
+
} else {
|
|
133
|
+
message = `Winner: Player ${winnerIndex + 1}`;
|
|
134
|
+
}
|
|
135
|
+
} else if (finalStep.every((agentStep) => agentStep.reward === 0)) {
|
|
136
|
+
message = "Draw";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return html`
|
|
140
|
+
<div class="status-bar">
|
|
141
|
+
${tokenUrl && html`<img src=${tokenUrl} class="token" />`}
|
|
142
|
+
<span>${message}</span>
|
|
143
|
+
</div>
|
|
144
|
+
`;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// --- Main Renderer Component ---
|
|
148
|
+
export const Renderer: FunctionComponent<RendererProps> = ({ replay, step, agents }) => {
|
|
149
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
150
|
+
const animationFrameId = useRef<number>();
|
|
151
|
+
const prevStep = useRef(step);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
const isBackStep = step < prevStep.current;
|
|
155
|
+
prevStep.current = step;
|
|
156
|
+
const canvas = canvasRef.current;
|
|
157
|
+
if (!canvas) return;
|
|
158
|
+
const c = canvas.getContext("2d");
|
|
159
|
+
if (!c) return;
|
|
160
|
+
|
|
161
|
+
const { configuration, steps } = replay;
|
|
162
|
+
const { columns, rows, inarow } = configuration;
|
|
163
|
+
const board = steps[step][0].observation.board;
|
|
164
|
+
|
|
165
|
+
const draw = (frame: number) => {
|
|
166
|
+
const { width, height } = canvas.getBoundingClientRect();
|
|
167
|
+
canvas.width = width;
|
|
168
|
+
canvas.height = height;
|
|
169
|
+
|
|
170
|
+
const unit = 8;
|
|
171
|
+
const minCanvasSize = Math.min(height, width);
|
|
172
|
+
const minOffset = minCanvasSize > 400 ? 30 : unit / 2;
|
|
173
|
+
const cellSize = Math.min((width - minOffset * 2) / columns, (height - minOffset * 2) / rows);
|
|
174
|
+
const cellInset = 0.8;
|
|
175
|
+
const pieceScale = cellSize / 100;
|
|
176
|
+
const xOffset = Math.max(0, (width - cellSize * columns) / 2);
|
|
177
|
+
const yOffset = Math.max(0, (height - cellSize * rows) / 2);
|
|
178
|
+
|
|
179
|
+
c.fillStyle = "#000B2A";
|
|
180
|
+
c.fillRect(0, 0, canvas.width, canvas.height);
|
|
181
|
+
|
|
182
|
+
const getRowCol = (cell: number) => [Math.floor(cell / columns), cell % columns];
|
|
183
|
+
|
|
184
|
+
const drawCellCircle = (cell: number) => {
|
|
185
|
+
const [row, col] = getRowCol(cell);
|
|
186
|
+
c.arc(
|
|
187
|
+
xOffset + (col * cellSize + cellSize / 2),
|
|
188
|
+
yOffset + (row * cellSize + cellSize / 2),
|
|
189
|
+
(cellInset * cellSize) / 2,
|
|
190
|
+
0,
|
|
191
|
+
2 * Math.PI,
|
|
192
|
+
false as any
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const drawPiece = (mark: number) => {
|
|
197
|
+
const opacity = minCanvasSize < 300 ? 0.6 - minCanvasSize / 1000 : 0.1;
|
|
198
|
+
c.fillStyle = getColor(mark, opacity);
|
|
199
|
+
c.strokeStyle = getColor(mark);
|
|
200
|
+
c.shadowColor = getColor(mark);
|
|
201
|
+
c.shadowBlur = 8 / cellInset;
|
|
202
|
+
c.lineWidth = 1 / cellInset;
|
|
203
|
+
|
|
204
|
+
c.save();
|
|
205
|
+
c.beginPath();
|
|
206
|
+
c.arc(50, 50, 50, 2 * Math.PI, false as any);
|
|
207
|
+
c.closePath();
|
|
208
|
+
c.lineWidth *= 4;
|
|
209
|
+
c.stroke();
|
|
210
|
+
c.fill();
|
|
211
|
+
c.restore();
|
|
212
|
+
|
|
213
|
+
c.beginPath();
|
|
214
|
+
c.arc(50, 50, 40, 2 * Math.PI, false as any);
|
|
215
|
+
c.closePath();
|
|
216
|
+
c.stroke();
|
|
217
|
+
|
|
218
|
+
if (mark === 1) {
|
|
219
|
+
const scale = 0.54;
|
|
220
|
+
c.save();
|
|
221
|
+
c.translate(23, 23);
|
|
222
|
+
c.scale(scale, scale);
|
|
223
|
+
c.lineWidth /= scale;
|
|
224
|
+
c.shadowBlur /= scale;
|
|
225
|
+
c.stroke(kPath);
|
|
226
|
+
c.restore();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (mark === 2) {
|
|
230
|
+
const scale = 0.6;
|
|
231
|
+
c.save();
|
|
232
|
+
c.translate(24, 28);
|
|
233
|
+
c.scale(scale, scale);
|
|
234
|
+
c.lineWidth /= scale;
|
|
235
|
+
c.shadowBlur /= scale;
|
|
236
|
+
c.stroke(goose1Path);
|
|
237
|
+
c.stroke(goose2Path);
|
|
238
|
+
c.stroke(goose3Path);
|
|
239
|
+
c.beginPath();
|
|
240
|
+
c.arc(38.5, 18.6, 2.7, 0, Math.PI * 2, false as any);
|
|
241
|
+
c.closePath();
|
|
242
|
+
c.fill();
|
|
243
|
+
c.restore();
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
for (let i = 0; i < board.length; i++) {
|
|
248
|
+
const [row, col] = getRowCol(i);
|
|
249
|
+
if (board[i] === 0) continue;
|
|
250
|
+
|
|
251
|
+
let yFrame = 1;
|
|
252
|
+
if (!isBackStep && step > 0 && replay.steps[step - 1][0].observation.board[i] !== board[i]) {
|
|
253
|
+
yFrame = Math.min(1, frame * 2);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
c.save();
|
|
257
|
+
c.translate(
|
|
258
|
+
xOffset + cellSize * col + (cellSize - cellSize * cellInset) / 2,
|
|
259
|
+
yOffset + yFrame * (cellSize * row) + (cellSize - cellSize * cellInset) / 2
|
|
260
|
+
);
|
|
261
|
+
c.scale(pieceScale * cellInset, pieceScale * cellInset);
|
|
262
|
+
drawPiece(board[i]);
|
|
263
|
+
c.restore();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const bgRadius = (Math.min(rows, columns) * cellSize) / 2;
|
|
267
|
+
const bgStyle = c.createRadialGradient(
|
|
268
|
+
xOffset + (cellSize * columns) / 2,
|
|
269
|
+
yOffset + (cellSize * rows) / 2,
|
|
270
|
+
0,
|
|
271
|
+
xOffset + (cellSize * columns) / 2,
|
|
272
|
+
yOffset + (cellSize * rows) / 2,
|
|
273
|
+
bgRadius
|
|
274
|
+
);
|
|
275
|
+
bgStyle.addColorStop(0, "#000B49");
|
|
276
|
+
bgStyle.addColorStop(1, "#000B2A");
|
|
277
|
+
|
|
278
|
+
c.beginPath();
|
|
279
|
+
c.rect(0, 0, canvas.width, canvas.height);
|
|
280
|
+
c.closePath();
|
|
281
|
+
c.shadowBlur = 0;
|
|
282
|
+
for (let i = 0; i < board.length; i++) {
|
|
283
|
+
drawCellCircle(i);
|
|
284
|
+
c.closePath();
|
|
285
|
+
}
|
|
286
|
+
c.fillStyle = bgStyle;
|
|
287
|
+
c.fill("evenodd");
|
|
288
|
+
|
|
289
|
+
for (let i = 0; i < board.length; i++) {
|
|
290
|
+
c.beginPath();
|
|
291
|
+
drawCellCircle(i);
|
|
292
|
+
c.strokeStyle = "#0361B2";
|
|
293
|
+
c.lineWidth = 1;
|
|
294
|
+
c.stroke();
|
|
295
|
+
c.closePath();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const drawLine = (fromCell: number, toCell: number) => {
|
|
299
|
+
if (frame < 0.5) return;
|
|
300
|
+
const lineFrame = (frame - 0.5) / 0.5;
|
|
301
|
+
const x1 = xOffset + (fromCell % columns) * cellSize + cellSize / 2;
|
|
302
|
+
const x2 = x1 + lineFrame * (xOffset + ((toCell % columns) * cellSize + cellSize / 2) - x1);
|
|
303
|
+
const y1 = yOffset + Math.floor(fromCell / columns) * cellSize + cellSize / 2;
|
|
304
|
+
const y2 = y1 + lineFrame * (yOffset + Math.floor(toCell / columns) * cellSize + cellSize / 2 - y1);
|
|
305
|
+
c.beginPath();
|
|
306
|
+
c.lineCap = "round";
|
|
307
|
+
c.lineWidth = 4;
|
|
308
|
+
c.strokeStyle = getColor(board[fromCell]);
|
|
309
|
+
c.shadowBlur = 8;
|
|
310
|
+
c.shadowColor = getColor(board[fromCell]);
|
|
311
|
+
c.moveTo(x1, y1);
|
|
312
|
+
c.lineTo(x2, y2);
|
|
313
|
+
c.stroke();
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const getCell = (cell: number, rowOffset: number, columnOffset: number) => {
|
|
317
|
+
const row = Math.floor(cell / columns) + rowOffset;
|
|
318
|
+
const col = (cell % columns) + columnOffset;
|
|
319
|
+
if (row < 0 || row >= rows || col < 0 || col >= columns) return -1;
|
|
320
|
+
return col + row * columns;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const makeNode = (cell: number) => {
|
|
324
|
+
const node = { cell, directions: [] as number[], value: board[cell] };
|
|
325
|
+
for (let r = -1; r <= 1; r++) {
|
|
326
|
+
for (let c = -1; c <= 1; c++) {
|
|
327
|
+
if (r === 0 && c === 0) continue;
|
|
328
|
+
node.directions.push(getCell(cell, r, c));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return node;
|
|
332
|
+
};
|
|
333
|
+
const graph = board.map((_: any, i: number) => makeNode(i));
|
|
334
|
+
|
|
335
|
+
const getSequence = (node: ReturnType<typeof makeNode>, direction: number) => {
|
|
336
|
+
const sequence = [node.cell];
|
|
337
|
+
while (sequence.length < inarow) {
|
|
338
|
+
const nextNodeIndex = node.directions[direction];
|
|
339
|
+
if (nextNodeIndex === -1) return;
|
|
340
|
+
const next = graph[nextNodeIndex];
|
|
341
|
+
if (!next || node.value !== next.value || next.value === 0) return;
|
|
342
|
+
node = next;
|
|
343
|
+
sequence.push(node.cell);
|
|
344
|
+
}
|
|
345
|
+
return sequence;
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
if (replay.steps[step].some((s) => s.status === "DONE")) {
|
|
349
|
+
for (let i = 0; i < board.length; i++) {
|
|
350
|
+
for (let d = 0; d < 8; d++) {
|
|
351
|
+
const seq = getSequence(graph[i], d);
|
|
352
|
+
if (seq) {
|
|
353
|
+
drawLine(seq[0], seq[inarow - 1]);
|
|
354
|
+
i = board.length;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
let start = Date.now();
|
|
363
|
+
const animate = () => {
|
|
364
|
+
const frame = Math.min((Date.now() - start) / 500, 1);
|
|
365
|
+
draw(frame);
|
|
366
|
+
if (frame < 1) {
|
|
367
|
+
animationFrameId.current = requestAnimationFrame(animate);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
animate();
|
|
372
|
+
|
|
373
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
374
|
+
if (animationFrameId.current) {
|
|
375
|
+
cancelAnimationFrame(animationFrameId.current);
|
|
376
|
+
}
|
|
377
|
+
start = Date.now();
|
|
378
|
+
animate();
|
|
379
|
+
});
|
|
380
|
+
resizeObserver.observe(canvas);
|
|
381
|
+
|
|
382
|
+
return () => {
|
|
383
|
+
resizeObserver.disconnect();
|
|
384
|
+
if (animationFrameId.current) {
|
|
385
|
+
cancelAnimationFrame(animationFrameId.current);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}, [replay, step]);
|
|
389
|
+
|
|
390
|
+
return html`
|
|
391
|
+
<div class="renderer-container">
|
|
392
|
+
<canvas ref=${canvasRef} />
|
|
393
|
+
<${GameStatus} replay=${replay} step=${step} agents=${agents} />
|
|
394
|
+
</div>
|
|
395
|
+
`;
|
|
396
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
html, body, #app {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: 0;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.renderer-container {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
width: 100%;
|
|
13
|
+
height: 100%;
|
|
14
|
+
background: #000B2A;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.renderer-container canvas {
|
|
18
|
+
flex-grow: 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.status-bar {
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
padding: 8px;
|
|
26
|
+
color: white;
|
|
27
|
+
font-family: sans-serif;
|
|
28
|
+
font-size: 14px;
|
|
29
|
+
font-weight: 500;
|
|
30
|
+
min-height: 18px;
|
|
31
|
+
flex-shrink: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.status-bar .token {
|
|
35
|
+
width: 20px;
|
|
36
|
+
height: 20px;
|
|
37
|
+
margin-right: 8px;
|
|
38
|
+
}
|