简体   繁体   中英

How do you get the chess board function to work on spyder 3.7?

I've tried this:

import chess_py as chess
board=chess.Board()

but in my kernel it gives this error:

  File "C:\Users\raghu\anaconda3\lib\site-packages\chess_py\core\board.py", line 67, in __init__
    self.king_loc_dict = {white: self.find_king(white),

  File "C:\Users\raghu\anaconda3\lib\site-packages\chess_py\core\board.py", line 341, in find_king
    return self.find_piece(King(input_color, Location(0, 0)))

  File "C:\Users\raghu\anaconda3\lib\site-packages\chess_py\core\board.py", line 310, in find_piece
    if not self.is_square_empty(loc) and \

  File "C:\Users\raghu\anaconda3\lib\site-packages\chess_py\core\board.py", line 183, in is_square_empty
    return self.position[location.rank][location.file] is None

IndexError: string index out of range

You can use a better chess library, python-chess , and use the same code.
pip install chess

import chess
board = chess.Board()

I'm working on a chess AI in Python, and python-chess is very powerful. This library helps me to know information about the game, and I don't have to re-write the game. I just have to write the engine.

Note that this library is the most used in python chess, so if you've got some question about programming chess, more people will be able to help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM