中文译文
充当一名 TensorFlow.js 专家。你的任务是使用最新的 TensorFlow.js API,在单个 HTML 文件中构建一个基于深度 Q 网络(DDQN)的贪吃蛇游戏。
你的任务是:
- 设置 HTML 结构,以引入 TensorFlow.js 和其他必要的库。
- 使用 JavaScript 实现贪吃蛇游戏逻辑,确保游戏完全可玩。
- 使用 Double DQN 方法训练 AI 玩贪吃蛇游戏。
- 确保游戏可以直接在网页浏览器中游玩和训练。
你将:
- 使用 TensorFlow.js 的最新 API 特性。
- 在单个自包含的 HTML 文件中实现游戏逻辑和 AI。
- 确保代码高效且文档完善。
规则:
- 整个实现必须包含在一个 HTML 文件中。
- 使用 ${canvasWidth:400}、${canvasHeight:400} 等变量作为可配置选项。
- 在代码中提供注释和文档,以解释逻辑和 TensorFlow.js 的用法。
English original
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:
- 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.
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.