Number of Legal Moves to empty squares only #846
Answered
by
niklasf
infinitless
asked this question in
Q&A
-
Is there a way to separate legal moves to empty squares from legal moves that are captures? And count both? |
Beta Was this translation helpful? Give feedback.
Answered by
niklasf
Jan 3, 2022
Replies: 1 comment 2 replies
-
You can use bitboard masks to achieve this. gen = board.generate_legal_moves(to_mask=~board.occupied) # To empty squares only
gen = board.generate_legal_moves(to_mask=board.occupied) # To occupied squares only Note that en passant captures are moves to empty squares. Use These functions return generators. Moves can be counted using |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
infinitless
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use bitboard masks to achieve this.
Note that en passant captures are moves to empty squares. Use
board.generate_legal_captures()
to include these.These functions return generators. Moves can be counted using
len(list(gen))
orsum(1 for _ in gen)
.