Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Given a position, is it check?

Author: Gerd Isenberg

Date: 09:28:49 02/03/05

Go up one level in this thread


On February 03, 2005 at 05:01:08, Jose Cortes wrote:

>
>Hi, I have a little doubt about finding the best way to, given a position,
>verify if it is check, using whatever data estructure, bitboard, etc. There are
>a lot of ways to do it, most of them using loops, but what is the most
>efficient?Someone can help me?
>Thx.

With Bitboards one way is to interprete the king in question as rook, bishop,
knight and pawn and to intersect it's attack-sets with the sets of appropriate
opponent pieces, like:

checkingBlackPieces  =
    (getRookAttacks(wKing)      & (bRooks|bQueens) )
  | (getBishopAttacks(wKing)    & (bBishops|bQueens) )
  | (getKnightAttacks(wKing)    &  bKnights )
  | (getWhitePawnAttacks(wKing) &  bPawns )
  ;

Similar to Thomas idea it is also possible to determine checking moves during
move generation and to have a check (or even double check) flags inside your
move structure, class or type.

Same idea with the meta king as well - e.g. if you have a set of all rook
targets of the king, you have already the set of all target squares where
opponent rooks/queens may give check on rank and files, etc.

Discovered checks are done in the same pass with pinned piece detection.
An advantage of generating and keeping disjoint direction wise attacks with fill
based routines is an easier and unconditional way to determine pins and
discovered pieces in one pass per direction.

One benefit of beeing able to generate checking moves, instead of looking for a
checked king after making the move, is move sorting (trying checks earlier) and
the possible implementation of some special and conditional horizon or qsearch
movegenerator, not only expanding (winning or equal) captures but also (loosing)
checking captures as well as quite checks.

Gerd



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.