diff --git a/README_CN.md b/README_CN.md index 82e5d27..e75dc61 100644 --- a/README_CN.md +++ b/README_CN.md @@ -62,6 +62,19 @@ pip install setuptools==65.5.0 pip==21 pip install -r requirements.txt ``` +Linux: +```bash +# 使用 GPU 训练需要手动安装完整版 PyTorch +conda install pytorch=2.0.0 torchvision pytorch-cuda=11.8 -c pytorch -c nvidia + +# 运行程序脚本测试 PyTorch 是否能成功调用 GPU +python .\utils\check_gpu_status.py + +# 安装外部代码库 +pip install setuptools==65.5.0 pip==23.1.2 +pip install -r requirements.txt +``` + ### 运行测试 项目 `main/` 文件夹下包含经典游戏《贪吃蛇》的程序脚本,基于 [Pygame](https://www.pygame.org/news) 代码库,可以直接运行以下指令进行游戏: diff --git a/main/snake_game.py b/main/snake_game.py index 003b978..664f22e 100644 --- a/main/snake_game.py +++ b/main/snake_game.py @@ -32,8 +32,10 @@ def __init__(self, seed=0, board_size=12, silent_mode=True): self.sound_game_over = mixer.Sound("sound/game_over.wav") self.sound_victory = mixer.Sound("sound/victory.wav") else: - self.screen = None - self.font = None + pygame.init() + pygame.display.set_caption("Snake Game") + self.screen = pygame.display.set_mode((self.display_width, self.display_height)) + self.font = pygame.font.Font(None, 36) self.snake = None self.non_snake = None diff --git a/main/test_cnn.py b/main/test_cnn.py index 108b8fc..fca447e 100644 --- a/main/test_cnn.py +++ b/main/test_cnn.py @@ -14,6 +14,7 @@ NUM_EPISODE = 10 RENDER = True +SILENT_MODE = True FRAME_DELAY = 0.05 # 0.01 fast, 0.05 slow ROUND_DELAY = 5 @@ -21,7 +22,7 @@ print(f"Using seed = {seed} for testing.") if RENDER: - env = SnakeEnv(seed=seed, limit_step=False, silent_mode=False) + env = SnakeEnv(seed=seed, limit_step=False, silent_mode=SILENT_MODE) else: env = SnakeEnv(seed=seed, limit_step=False, silent_mode=True) diff --git a/main/test_mlp.py b/main/test_mlp.py index eb80b8f..a31c17b 100644 --- a/main/test_mlp.py +++ b/main/test_mlp.py @@ -10,15 +10,15 @@ NUM_EPISODE = 10 RENDER = True +SILENT_MODE = True FRAME_DELAY = 0.05 # 0.01 fast, 0.05 slow ROUND_DELAY = 5 seed = random.randint(0, 1e9) print(f"Using seed = {seed} for testing.") - if RENDER: - env = SnakeEnv(seed=seed, limit_step=False, silent_mode=False) + env = SnakeEnv(seed=seed, limit_step=False, silent_mode=SILENT_MODE) else: env = SnakeEnv(seed=seed, limit_step=False, silent_mode=True) diff --git a/requirements.txt b/requirements.txt index 9bd6c91..a9040fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -gym==0.21.0 -stable-baselines3==1.8.0 -sb3-contrib==1.8.0 +gym==0.26.2 +stable-baselines3==2.0.0 +sb3-contrib==2.0.0 pygame==2.3.0 \ No newline at end of file