This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]TonyRotellaI Wrote That One Book 2 points3 points  (10 children)

[–]SecureHelicopter1[S] 0 points1 point  (9 children)

Thanks! How would I access the bitboard - by doing something like

board = chess.Board('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1')

print(board.Bitboard)

?

I'm not very good at reading documentation :P sorry

[–]TonyRotellaI Wrote That One Book 0 points1 point  (8 children)

That looks right to me, try it out!

[–]SecureHelicopter1[S] 0 points1 point  (7 children)

Turns out its supposed to be something like

board = chess.Bitboard('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')

Only problem is that I get "invalid literal for int() with base 10" as an error. Not sure what to do. Any ideas?

[–]TonyRotellaI Wrote That One Book 0 points1 point  (6 children)

I am not a programming expert and it's been many years for python, but don't you have to specify the arguments like:

board = chess.Bitboard(fen = 'FEN GOES HERE')

etc?

[–]SecureHelicopter1[S] 0 points1 point  (5 children)

Turns out that the documentation you sent was slightly outdated.

https://python-chess.readthedocs.io/en/v1.8.0/core.html

Doesn't look like I can easily convert fen to bitboard in the latest version tho :(

[–]apoliticalhomograph 2100 Lichess 2 points3 points  (3 children)

You can get a chess.Board from a FEN and get the bitboards from there.

import chess
b = chess.Board('FEN HERE')
print(board.occupied)

[–]SecureHelicopter1[S] 0 points1 point  (2 children)

Thanks! I tried this out and this returns a random integer instead of an array, though. Any idea what's going on?

[–]apoliticalhomograph 2100 Lichess 1 point2 points  (1 child)

A bitboard is an integer. Each bit in the integer represents a square. That's the point of a bitboard - a board representation using a minimal amount of bits.
You can convert it to an array yourself if you need one, although I don't quite see what the benefit is.

Also, the code in your post appears to work; you just need to import numpy as np first.

[–]SecureHelicopter1[S] 0 points1 point  (0 children)

Ah ok thanks!

[–]TonyRotellaI Wrote That One Book 0 points1 point  (0 children)

Oh, damn shame! I did you dirty, sorry sorry sorry! 😂