Пример #1
0
static void alists_hidden(alists_t * alists, const board_t * board, int from, int to) {

   int inc;
   int sq, piece;

   ASSERT(alists!=NULL);
   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(from));
   ASSERT(SQUARE_IS_OK(to));

   inc = DELTA_INC_LINE(to-from);

   if (inc != IncNone) { // line

      sq = from;
      do sq -= inc; while ((piece=board->square[sq]) == Empty);

      if (SLIDER_ATTACK(piece,inc)) {

         ASSERT(piece_is_ok(piece));
         ASSERT(PIECE_IS_SLIDER(piece));

         alist_add(alists->alist[PIECE_COLOUR(piece)],sq,board);
      }
   }
}
Пример #2
0
bool is_pinned(const board_t * board, int square, int colour) {

   int from, to;
   int inc;
   int sq, piece;

   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(square));
   ASSERT(COLOUR_IS_OK(colour));

   from = square;
   to = KING_POS(board,colour);

   inc = DELTA_INC_LINE(to-from);
   if (inc == IncNone) return false; // not a line

   sq = from;
   do sq += inc; while (board->square[sq] == Empty);

   if (sq != to) return false; // blocker

   sq = from;
   do sq -= inc; while ((piece=board->square[sq]) == Empty);

   return COLOUR_IS(piece,COLOUR_OPP(colour)) && SLIDER_ATTACK(piece,inc);
}
Пример #3
0
static void find_pins(int list[], const board_t * board) {

    int me, opp;
    int king;
    const sq_t * ptr;
    int from;
    int piece;
    int delta;
    int inc;
    int sq;
    int capture;
    int pin;

    ASSERT(list!=NULL);
    ASSERT(board!=NULL);

    // init

    me = board->turn;
    opp = COLOUR_OPP(me);

    king = KING_POS(board,opp);

    for (ptr = &board->piece[me][1]; (from=*ptr) != SquareNone; ptr++) { // HACK: no king

        piece = board->square[from];

        delta = king - from;
        ASSERT(delta_is_ok(delta));

        if (PSEUDO_ATTACK(piece,delta)) {

            ASSERT(PIECE_IS_SLIDER(piece));

            inc = DELTA_INC_LINE(delta);
            ASSERT(inc!=IncNone);

            ASSERT(SLIDER_ATTACK(piece,inc));

            sq = from;
            do sq += inc;
            while ((capture=board->square[sq]) == Empty);

            ASSERT(sq!=king);

            if (COLOUR_IS(capture,me)) {
                pin = sq;
                do sq += inc;
                while (board->square[sq] == Empty);
                if (sq == king) *list++ = pin;
            }
        }
    }

    *list = SquareNone;
}