implement checkmate function, should debug