Example #1
0
Bitboard SEE::extractShadowAttacker(const Position& position,
                                    Bitboard bb,
                                    Square from,
                                    Square to) {
  Direction dir = from.dir(to);
  if (dir >= Direction::EndS) {
    return bb;
  }

  Bitboard occ = nosseOr(position.getBOccupiedBitboard(),
                         position.getWOccupiedBitboard());
  RotatedBitboard occ90 = position.get90RotatedBitboard();
  RotatedBitboard occR45 = position.getRight45RotatedBitboard();
  RotatedBitboard occL45 = position.getLeft45RotatedBitboard();

  Bitboard masked;
  switch (dir) {
  case Direction::Up:
  case Direction::Down:
    masked = MoveTables::ver(occ, from);
    break;
  case Direction::Left:
  case Direction::Right:
    masked = MoveTables::hor(occ90, from);
    break;
  case Direction::RightUp:
  case Direction::LeftDown:
    masked = MoveTables::diagR45(occR45, to);
    break;
  case Direction::LeftUp:
  case Direction::RightDown:
    masked = MoveTables::diagL45(occL45, to);
    break;
  default:
    ASSERT(false);
  }

  BB_EACH(square, masked) {
    Piece piece = position.getPieceOnBoard(square);
    if (square.dir(from) == dir && MoveTables::isMovableInLongStep(piece, dir)) {
      bb.set(square);
      break;
    }
  }
void TardyMoveGenerator::generateEvasions(const Position& position, CheckState cs, Moves& moves) {
  Turn turn = position.getTurn();
  Square king = turn == Turn::Black ? position.getBlackKingSquare() : position.getWhiteKingSquare();

  if (!isDoubleCheck(cs)) {
    ::generateMoves(position, moves, [king, cs](PieceType pieceType, Square to) {
      if (pieceType == PieceType::king()) {
        return false;
      }

      auto dir = king.dir(cs.from1);

      for (auto s = king.move(dir); ; s = s.move(dir)) {
        if (s == to) { return true; }
        if (s == cs.from1) { break; }
      }

      return false;
    });
  }

  auto& list = MovableMap.find(PieceNumber::King)->second;
  for (auto& info : list) {
    Square to = king.safetyMove(info.dir);
    if (!to.isValid()) {
      continue;
    }

    Piece pieceTo = position.getPieceOnBoard(to);
    if ((turn == Turn::Black && pieceTo.isBlack()) ||
        (turn == Turn::White && pieceTo.isWhite())) {
      continue;
    }

    moves.add(Move(king, to, false));
  }
}