v2 of 2
Permanent link · Nov 30, 2026
Build a single-file DDQN Snake game in TensorFlow.js
Asks the model to act as a TensorFlow.js expert and build a playable Snake game in one HTML file, training a Double DQN agent to play it in the browser with configurable canvas variables.
Act as a TensorFlow.js expert. You are tasked with building a Deep Q-Network (DDQN) based Snake game using the latest TensorFlow.js API, all within a single HTML file. Your task is to: 1. Set up the HTML structure to include TensorFlow.js and other necessary libraries. 2. Implement the Snake game logic using JavaScript, ensuring the game is fully playable. 3. Use a Double DQN approach to train the AI to play the Snake game. 4. Ensure the game can be played and trained directly within a web browser. You will: - Use TensorFlow.js's latest API features. - Implement the game logic and AI in a single, self-contained HTML file. - Ensure the code is efficient and well-documented. Rules: - The entire implementation must be contained within one HTML file. - Use variables like {{canvaswidth}}, {{canvasheight}} for configurable options. - Provide comments and documentation within the code to explain the logic and TensorFlow.js usage.
Change note for v2: Placeholders normalised from ${name} to {{name}} so the fill-in form and Copy work; wording unchanged.
Result
Versions→latest = v2
v2Patchimported· Nov 30, 2026 by @importer· Placeholders normalised from ${name} to {{name}} so the fill-in form and Copy work; wording unchanged.Permalink
Act as a TensorFlow.js expert. You are tasked with building a Deep Q-Network (DDQN) based Snake game using the latest TensorFlow.js API, all within a single HTML file. Your task is to: 1. Set up the HTML structure to include TensorFlow.js and other necessary libraries. 2. Implement the Snake game logic using JavaScript, ensuring the game is fully playable. 3. Use a Double DQN approach to train the AI to play the Snake game. 4. Ensure the game can be played and trained directly within a web browser. You will: - Use TensorFlow.js's latest API features. - Implement the game logic and AI in a single, self-contained HTML file. - Ensure the code is efficient and well-documented. Rules: - The entire implementation must be contained within one HTML file. - Use variables like${canvasWidth:400{canvaswidth}},${canvasHeight:400{canvasheight}} for configurable options. - Provide comments and documentation within the code to explain the logic and TensorFlow.js usage.
Cite this exact version as /p/build-a-single-file-ddqn-snake-game-in-tensorflowjs-fjy3/v/2.