[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]
Check out Janggi (Korean Chess), our featured variant for December, 2024.
Check out Janggi (Korean Chess), our featured variant for December, 2024.
I must admit that this would currently also not work in presets generated by the Play-Testing Applet. At least for highlighting purposes: it also fails to update the 'last moved piece' when it tenttatively makes the move that might have to be highlighted in order to test if it exposes the King to capture. But if you decide to use the Applet-generated code, I can fix that.
To speed up fully-legal highlighting, I use a short-cut: Instead of trying all possible opponent moves to see if they capture the King, I only try those that might have been affected by the move of which we want to judge the legality. To that end it first marks all squares attaced by the opponent in the original position with its own King removed, and for every piece it makes a list of moves (origin and direction) that they obstruct. It also makes a list of pre-existing checking moves. After trying a move, it then only reruns the pre-existing checks in the resulting position (to see whether these are now resolved), plus the moves that were blocked by the moved piece (to check whether that piece was pinned). And for King moves it tests whether these go to a square that was marked as being under attack.
I suppose it would have to rerun all moves of an imitator too, because these are also affected by the preceding move. (And do the attacked-squares test in the initial position while imitating a King.)