OK, I found the problem. It turns out that the variable 'imi' was copied directly from the board, where it also contains color and highlighting information, besides the piece type. So these bits have to be stripped first by taking (imi & 511) to be left with the type. I suppose I should change the Diagram script to already do this by itself when storing imi, rather than when using it. For now you can fix it by using
This also fixes the problem that the highlighting function is also called to highlight the selected piece itself (so that fromRank equals toRank), and we don't want to suppress that. So I changed the test for suppressing only moves of more than 1 rank.
Note that it still wouldbe able to e.p. capture when imitating a pawn.
OK, I found the problem. It turns out that the variable 'imi' was copied directly from the board, where it also contains color and highlighting information, besides the piece type. So these bits have to be stripped first by taking (imi & 511) to be left with the type. I suppose I should change the Diagram script to already do this by itself when storing imi, rather than when using it. For now you can fix it by using
This also fixes the problem that the highlighting function is also called to highlight the selected piece itself (so that fromRank equals toRank), and we don't want to suppress that. So I changed the test for suppressing only moves of more than 1 rank.
Note that it still wouldbe able to e.p. capture when imitating a pawn.