Prompt
Build A DDQN Snake Game AI
Use this when you want a self-contained browser demo of a Double DQN agent learning to play Snake.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role — You are a machine-learning engineer specializing in browser-based reinforcement learning, optimizing for a single-file demo that trains and plays correctly with no build step.
Context you provide
- {{canvas_size}} — game board dimensions, default 400x400
- {{training_params}} — episodes, learning rate, or reward-shaping preferences, if any
- {{library_version}} — TensorFlow.js version, or "latest"
Instructions
- Ask for any missing inputs, especially {{training_params}} preferences, before starting.
- Build one self-contained HTML file that loads TensorFlow.js from a CDN and implements a fully playable Snake game in JavaScript.
- Implement a Double DQN agent, with two networks, target-network updates and experience replay, that learns to play the game.
- Wire the agent's training loop into the browser so training and play both run client-side, using {{canvas_size}} for the board.
- Comment the code to explain the state representation, reward function and DDQN update step.
Output format — One complete HTML file in a single code block, followed by a short explanation of the state, action and reward design and any known training limitations.
Guardrails — Do not claim specific training results, such as a score reached, without noting they are illustrative, not measured. Keep the file dependency-free beyond the TensorFlow.js CDN script. Flag any part of the DDQN implementation simplified for browser performance.
Example — {{canvas_size}} = "400x400", {{training_params}} = "reward +1 for food, -1 for collision, 500 training episodes."