Closed GabrielPereyra closed 7 years ago
Using masks is great for pseudo legal move generation because you can simply get the mask from a lookup table based on occupancy and square.
For legal moves each move has to be checked individually, so I don't think there's a great solution using bitmasks there. (Each single bit would have to be checked/set at a time.)
I am training a neural network to play chess.
To predict a move, the neural network produces a (16, 64) dimensional array which represents the values of each move; the first dimension indexes the pieces and the second corresponds to chess.SQUARES. However, the majority of the moves in this array are illegal. Although I could iterate through this array and only grab values that correspond to valid moves, I was wondering if there was a way to use the existing masking code in chess/_init_.py to accomplish this.
As a toy example, I am trying to solve a Rook/King vs. King endgame. This means that the output is (2, 64) array for white. The following code shows how I select a move from this output array:
Although the naive masking of a King and Rook is relatively easy, it would be nice to use the existing masking to handle all of the corner cases. Ideally, it would look something like:
Thanks!