You're getting lots of error messages about moves not being well-formed. Let's fix that first, then see if your other problem remains. The error is because these moves do not include the piece label. To make sure that the move is well-formed, you have three options.
Construct the move in your stalemated subroutine as a string, and pass that string to setlegal instead of a pair of coordinates.
Restore the position before using setlegal.
Make sure you don't have moves where both coordinates end up empty. From looking at your use of #after in the stalemated subroutine, it looks like you might have moves of this sort. So, make sure to do one of the other two.
I would also recommend writing your code to the latest standard, which is the fairychess include file.
You're getting lots of error messages about moves not being well-formed. Let's fix that first, then see if your other problem remains. The error is because these moves do not include the piece label. To make sure that the move is well-formed, you have three options.
setlegal
instead of a pair of coordinates.setlegal
.stalemated
subroutine, it looks like you might have moves of this sort. So, make sure to do one of the other two.I would also recommend writing your code to the latest standard, which is the fairychess include file.