mostly-finalized-but-untested check and checkmate code