It seems to me that you need a more sophisticated stalemated subroutine. This would have to take into consideration how a Joker would be able to move after any given piece moves. At the beginning of the subroutine, it should store the value of last_type_moved into another variable. Whenever a piece is moved for the sake of trying out a potential move, the value of last_type_moved should be changed to match the type of the piece moved. Each time the evaluation of a potential move is over, and the position has been restored, the value of last_type_moved should be restored to its original value.
It seems to me that you need a more sophisticated stalemated subroutine. This would have to take into consideration how a Joker would be able to move after any given piece moves. At the beginning of the subroutine, it should store the value of last_type_moved into another variable. Whenever a piece is moved for the sake of trying out a potential move, the value of last_type_moved should be changed to match the type of the piece moved. Each time the evaluation of a potential move is over, and the position has been restored, the value of last_type_moved should be restored to its original value.