iamlucaswolf / gym-chess

OpenAI Gym environments for Chess
GNU General Public License v3.0
21 stars 20 forks source link

'list' object has no attribute 'drop' #6

Open Leci37 opened 1 year ago

Leci37 commented 1 year ago

Thank very much for your public work, I am learing RL , my friend recomented this project

When I runing in it

import gym
import gym_chess
import random

env = gym.make('Chess-v0')
print(env.render())

env.reset()
done = False

while not done:
    action =   random.sample(env.legal_moves, 10)
    env.step(action)
    print(env.render(mode='unicode'))

env.close()

I recive this error

Traceback (most recent call last):
  File "C:\Users\Luis\Documents\GitHub\gym-chess\start.py", line 13, in <module>
    env.step(action)
  File "C:\Users\Luis\Documents\GitHub\gym-chess\gym_chess\envs.py", line 97, in step
    if action not in self._board.legal_moves:
  File "C:\Users\Luis\.conda\envs\RLhaha\lib\site-packages\chess\__init__.py", line 3554, in __contains__
    return self.board.is_legal(move)
  File "C:\Users\Luis\.conda\envs\RLhaha\lib\site-packages\chess\__init__.py", line 1659, in is_legal
    return not self.is_variant_end() and self.is_pseudo_legal(move) and not self.is_into_check(move)
  File "C:\Users\Luis\.conda\envs\RLhaha\lib\site-packages\chess\__init__.py", line 1615, in is_pseudo_legal
    if move.drop:
AttributeError: 'list' object has no attribute 'drop'

Process finished with exit code 1
iamlucaswolf commented 1 year ago

HI @Leci37 , thank you for using gym-chess.

random.sample returns a list, but env.step only takes a single action at a time. If you look at the README, I've included a code example that plays a game with random moves.

Let me know if that helps. Cheers! 😊