Build a DDQN Snake Game with TensorFlow.js in a Single HTML File

Create a Deep Q-Network (DQN) based Snake game using TensorFlow.js with the latest API, implemented in a single HTML file.

Prompts Chat Republished on Sep 15 0 Bookmarks 0 Copies
Bookmark 0

Prompt template

Format
Text Parameterized
Outputs
result (text)
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}, ${canvasheight:400} for configurable options.
- Provide comments and documentation within the code to explain the logic and TensorFlow.js usage.

Replace the ${…} placeholders with your values before using this prompt. See parameters and defaults below

Parameters

Replace each placeholder with your own value, or use its default when one is provided

${canvaswidth:400} canvaswidth Default: 400
${canvasheight:400} canvasheight Default: 400

What you'll create

A self-contained implementation combines JavaScript game logic and TensorFlow.js learning, with configurable canvas dimensions.

Frequently asked questions

Can game and training run directly in a browser?

Yes, both are explicit requirements.

Comments

Tried this prompt? Share what you made, compare results, or ask a question

Up to 4 results. Images up to 2 MB; MP4, WebM, or MOV videos up to 4 MB each