Exemple #1
0
bool parse_mask(
    const char **string, unsigned int fa_entry_count, struct filter_mask *mask)
{
    memset(mask->mask, 0, sizeof(mask->mask));

    if (read_char(string, 'R'))
        return parse_raw_mask(string, fa_entry_count, mask);
    else
    {
        bool ok = true;
        do {
            unsigned int id;
            ok = parse_id(string, fa_entry_count, &id);
            if (ok)
            {
                unsigned int end_id = id;
                if (read_char(string, '-'))
                    ok =
                        parse_id(string, fa_entry_count, &end_id)  &&
                        TEST_OK_(id <= end_id,
                            "Range %d-%d is empty", id, end_id);
                for (unsigned int i = id; ok  &&  i <= end_id; i ++)
                    set_mask_bit(mask, i);
            }
        } while (ok  &&  read_char(string, ','));

        return ok;
    }
}
Exemple #2
0
void Board::verifyMasks() const
{
  for (int c = 0; c < 2; ++c)
  {
    BitMask pawn_mask_o = 0ULL;
    BitMask pawn_mask_t = 0ULL;
    BitMask knight_mask = 0ULL;
    BitMask bishop_mask = 0ULL;
    BitMask rook_mask = 0ULL;
    BitMask queen_mask = 0ULL;
    BitMask king_mask = 0ULL;
    BitMask all_mask = 0ULL;

    Figure::Color color = (Figure::Color)c;
    for (int p = 0; p < NumOfFields; ++p)
    {
      const Field & field = getField(p);
      if ( !field || field.color() != color )
        continue;

      all_mask |= set_mask_bit(p);

      switch ( field.type() )
      {
      case Figure::TypePawn:
        {
          pawn_mask_t |= set_mask_bit(Index(p).transp());
          pawn_mask_o |= set_mask_bit(p);
        }
        break;

      case Figure::TypeKnight:
        knight_mask |= set_mask_bit(p);
        break;

      case Figure::TypeBishop:
        bishop_mask |= set_mask_bit(p);
        break;

      case Figure::TypeRook:
        rook_mask |= set_mask_bit(p);
        break;

      case Figure::TypeQueen:
        queen_mask |= set_mask_bit(p);
        break;

      case Figure::TypeKing:
        king_mask |= set_mask_bit(p);
        break;
      }
    }

    THROW_IF( pawn_mask_o != fmgr_.pawn_mask_o(color), "pawn mask invalid" );
    THROW_IF( pawn_mask_t != fmgr_.pawn_mask_t(color), "pawn mask invalid" );
    THROW_IF( knight_mask != fmgr_.knight_mask(color), "knight mask invalid" );
    THROW_IF( bishop_mask != fmgr_.bishop_mask(color), "bishop mask invalid" );
    THROW_IF( rook_mask != fmgr_.rook_mask(color), "rook mask invalid" );
    THROW_IF( queen_mask != fmgr_.queen_mask(color), "queen mask invalid" );
    THROW_IF( king_mask != fmgr_.king_mask(color), "king mask invalid" );
    THROW_IF( all_mask != fmgr_.mask(color), "invalid all figures mask" );

  }
}