linyiLYi / snake-ai

An AI agent that beats the classic game "Snake".
Apache License 2.0
1.61k stars 359 forks source link

2023.10.26 test遇到的问题#bug #29

Open CODESpellCaster001 opened 11 months ago

CODESpellCaster001 commented 11 months ago

输入命令: (pytorch) PS E:\ai projection\snake-ai-master\main> python .\snake_game.py 报错: Traceback (most recent call last): File "E:\ai projection\snake-ai-master\main\snake_game.py", line 259, in game = SnakeGame(seed=seed, silent_mode=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ai projection\snake-ai-master\main\snake_game.py", line 51, in init self.reset() File "E:\ai projection\snake-ai-master\main\snake_game.py", line 60, in reset self.food = self._generate_food() ^^^^^^^^^^^^^^^^^^^^^ File "E:\ai projection\snake-ai-master\main\snake_game.py", line 140, in _generate_food food = random.sample(self.non_snake, 1)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\anaconda\envs\pytorch\Lib\random.py", line 439, in sample raise TypeError("Population must be a sequence. " TypeError: Population must be a sequence. For dicts or sets, use sorted(d). 需要修改的地方: image and image

CODESpellCaster001 commented 11 months ago

self.non_snake = [(row, col) for row in range(self.board_size) for col in range(self.board_size) if (row, col) not in self.snake]

self.non_snake.append(self.snake.pop())