Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级依赖版本解决依赖冲突问题,区分渲染和静音模式变量,增加linux支持 #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) 代码库,可以直接运行以下指令进行游戏:
Expand Down
6 changes: 4 additions & 2 deletions main/snake_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion main/test_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,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)

Expand Down
4 changes: 2 additions & 2 deletions main/test_mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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