My current chess program (which plays Omega Chess) tests each of the opponent's pieces to see if they are attacking the king, in order to detect check. In this, I will consider pieces and pawns separately Now, in a lot of situations, it seems that this would be a very ineffecient, slow way to detect check (especially with OmegaChess, which has a higher proportion of jumping pieces and more pieces total). Now, one idea I am thinking of is to start with the king, and look at the squares near the king, such as checking for the knight by doing knight jumps or by sliding out diagonally and orthogonally from the king to test for the champion/wizard (for the required number of squares) and for the sliding pieces (and of course stopping once the champions/wizards are ruled out and it comes up to an piece that is not attacking the king or the end of the board). In the opening, and possibly in the middlegame, it seems that this would be much quicker than testing every single one of the opponent's pieces, but in the endgame it seems like it would tend to waste more, because of the fewer pieces and more wide open spaces (meaning that the sliding tests would take longer) that are typical of endgames.
Perhaps it should be based on the existence of an opponent's piece? For example, if it knows from a(n incrementally updated) table that its opponent has no knights, then it should not test for knights, etc.
What are y'all's thoughts on this?