Build a DDQN Snake Game with TensorFlow.js in a Single HTML File
Baut ein trainierbares Snake-Spiel mit Double-DQN-KI komplett in einer HTML-Datei mit TensorFlow.js.
Baut ein trainierbares Snake-Spiel mit Double-DQN-KI komplett in einer HTML-Datei mit TensorFlow.js.
Der 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.
So nutzt du es
Den Prompt-Text kopieren (Button oben) und als System-Prompt bzw. erste Nachricht in ChatGPT, Claude oder einem lokalen Modell einfügen. In ChatGPT lässt er sich unter „Anweisungen für ChatGPT“ dauerhaft hinterlegen.
Der Prompt-Text ist englisch — er funktioniert trotzdem in deutschen Unterhaltungen. Für deutsche Antworten einfach am Ende ergänzen: „Antworte auf Deutsch.“
Im Detail
Anspruchsvoller Prompt, der das Modell anweist, ein komplettes Snake-Spiel samt Double-DQN-Reinforcement-Learning-Agent in einer einzigen HTML-Datei mit TensorFlow.js zu bauen – Spiellogik, Trainingsschleife und UI in einem. Das ist deutlich komplexer als ein normaler Spiele-Prompt, weil das Modell sowohl Spielmechanik als auch RL-Grundlagen (Q-Learning, Replay-Buffer, Zielnetzwerk) korrekt umsetzen muss. Realistisch braucht es mehrere Iterationen und manuelles Debugging, da DDQN-Implementierungen selbst für erfahrene Entwickler fehleranfällig sind. Gut geeignet zum Lernen und Experimentieren mit RL im Browser, nicht für produktionsreife KI-Anwendungen.
Praxis-Tipp
canvasWidth und canvasHeight klein halten (z. B. 400x400) und explizit nach einer Trainingsvisualisierung (Score-Verlauf) fragen, um den Lernfortschritt sichtbar zu machen.
Lizenz & Quelle
- Lizenz: CC0-1.0 (Public Domain)
- Quelle: awesome-chatgpt-prompts (GitHub)
Inhalt ansehen (build-a-ddqn-snake-game-with-tensorflow-js-in-a-single-html-file.txt)
Lade …
Erfahrungen & Kommentare.
Funktioniert der Prompt bei Ihnen? Tipps, Stolperfallen, Varianten — teilen Sie es mit der Community.
Lade Kommentare …
Passt dazu.
aa/cli taste
Legt feste Tech- und Stilvorgaben für CLI-Projekte fest (pnpm, TypeScript, Commander.js, Ordnerstruktur).
Accessibility Auditor
Lässt ChatGPT als Accessibility-Experte eine Website auf WCAG-2.2- und Section-508-Konformität prüfen.
Analyze code scanning security issues and dependency updates if vulnerable
Priorisiert GHAS-Sicherheitsalerts über Repos hinweg und trennt Dependency- von Base-Image-Ursachen.
