Skip to main content
Prompts TensorFlow.js DDQN Snake Game Builder

developer coding template risk: low

TensorFlow.js DDQN Snake Game Builder

The prompt tasks the model with creating a single HTML file that implements a fully playable Snake game using JavaScript and trains an AI with Double DQN via the latest TensorFlow.…

PROMPT

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.

INPUTS

canvasWidth

configurable canvas width in pixels

e.g. 400

canvasHeight

configurable canvas height in pixels

e.g. 400

OPTIONAL CONTEXT

  • configurable options like canvas size

ROLES & RULES

Role assignments

  • Act as a TensorFlow.js expert.
  1. The entire implementation must be contained within one HTML file.
  2. Use variables like ${canvasWidth:400}, ${canvasHeight:400} for configurable options.
  3. Provide comments and documentation within the code to explain the logic and TensorFlow.js usage.

EXPECTED OUTPUT

Format
html
Constraints
  • entire implementation in one HTML file
  • use configurable variables like ${canvasWidth:400}
  • efficient and well-documented with comments
  • uses latest TensorFlow.js API
  • fully playable and trainable in browser

SUCCESS CRITERIA

  • Set up the HTML structure to include TensorFlow.js and other necessary libraries.
  • Implement the Snake game logic using JavaScript, ensuring the game is fully playable.
  • Use a Double DQN approach to train the AI to play the Snake game.
  • Ensure the game can be played and trained directly within a web browser.
  • 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.

FAILURE MODES

  • May use outdated TensorFlow.js APIs.
  • May produce code requiring external files or libraries not embedded.
  • May omit configurable variables like canvas dimensions.
  • May lack sufficient code comments and documentation.
  • May incorrectly implement Double DQN logic.
  • May result in non-playable or non-trainable game in browser.

CAVEATS

Missing context
  • Snake game specifics (grid size, speed, win/lose conditions beyond standard assumptions)
  • DDQN hyperparameters (learning rate, discount factor, epsilon decay, replay buffer size)
  • Neural network architecture (layer sizes, activations)
Ambiguities
  • Unclear template syntax for variables like '${canvasWidth:400}' – literal placeholder or example?
  • Does not specify state representation, action space, or reward function for Snake.
  • Double DQN implementation details (e.g., target network update frequency) not detailed.

QUALITY

OVERALL
0.75
CLARITY
0.85
SPECIFICITY
0.75
REUSABILITY
0.50
COMPLETENESS
0.75

IMPROVEMENT SUGGESTIONS

  • Add explicit definitions: 'State: 11x11 grid as flattened vector of 121 features (snake direction, body, food). Actions: 3 (up, right, left relative). Rewards: +10 food, -10 death, -0.01 step.'
  • Specify model: 'Sequential model with Dense(24, relu), Dense(24, relu), Dense(3, linear).'
  • List hyperparameters: 'lr=0.001, gamma=0.99, epsilon=1.0 to 0.01, buffer=10000, batch=32.'
  • Clarify variable templating: 'Use placeholders like {{canvasWidth}} and provide example values.'
  • Add toggle for human play vs AI training.

USAGE

Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.

MORE FOR DEVELOPER