niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.44k stars 531 forks source link

No methods other than fen to init board #149

Closed ChameleonRed closed 7 years ago

ChameleonRed commented 7 years ago

I want to init board without use of fen - how to do it?

For example by list of occupied squares, castling rights, en passant, color to move, half moves, full moves.

Currently I am constructing fen manually - can I do it much faster?

niklasf commented 7 years ago

You can use board.set_piece_at(), board.remove_piece_at() or directly assign the board.pawns, ..., board.kings, board.occupied_co[color], board.occupied, board.castling_rights bitboards. (But be sure to keep them in a consistent state). board.set_castling_fen() might also be helpful.

ChameleonRed commented 7 years ago

Yes I know but it is not optimal way - set_piece_at is cleat but using kings or pawns, castling looks very dangerous since good practice is not change fields of class directly (but not always is good). There is not function to set en_passant or set_castling_rights (I can use board.castling rights - but it is not clear).

Better is have function set_position(position, color_to_move, castling_rights, en_passant_square, half_moves, full_moves).

position can be list of [(sqaure, piece), ...]

As I said it is not clear how to set (documentation maybe or better function) and not clear what to do with en passant, half and full moves.

Currently I am using Board(fen=fen).

niklasf commented 7 years ago
niklasf commented 7 years ago

For now I don't want to add a method that does everything at once, but I added https://python-chess.readthedocs.io/en/latest/core.html#chess.BaseBoard.set_pieces and documented how to set the other fields.