Beispiel #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;
    }
  }
Beispiel #2
0
  MoveStack* generateDropMoves20151211(MoveStack* moveStackList, const Position& pos, const Bitboard& target) {
    const Hand hand = pos.hand(US);
    // まず、歩に対して指し手を生成
    if (hand.exists<HPawn>()) {
      Bitboard toBB = target;
      // 一段目には打てない
      const Rank TRank9 = (US == Black ? Rank9 : Rank1);
      toBB.andEqualNot(rankMask<TRank9>());

      // 二歩の回避
      Bitboard pawnsBB = pos.bbOf(Pawn, US);
      Square pawnsSquare;
      foreachBB(pawnsBB, pawnsSquare, [&](const int part) {
        toBB.set(part, toBB.p(part) & ~squareFileMask(pawnsSquare).p(part));
      });

      // 打ち歩詰めの回避
      const Rank TRank1 = (US == Black ? Rank1 : Rank9);
      const SquareDelta TDeltaS = (US == Black ? DeltaS : DeltaN);

      const Square ksq = pos.kingSquare(oppositeColor(US));
      // 相手玉が九段目なら、歩で王手出来ないので、打ち歩詰めを調べる必要はない。
      if (makeRank(ksq) != TRank1) {
        const Square pawnDropCheckSquare = ksq + TDeltaS;
        assert(isInSquare(pawnDropCheckSquare));
        if (toBB.isSet(pawnDropCheckSquare) && pos.piece(pawnDropCheckSquare) == Empty) {
          if (!pos.isPawnDropCheckMate(US, pawnDropCheckSquare)) {
            // ここで clearBit だけして MakeMove しないことも出来る。
            // 指し手が生成される順番が変わり、王手が先に生成されるが、後で問題にならないか?
            (*moveStackList++).move = makeDropMove(Pawn, pawnDropCheckSquare);
          }
          toBB.xorBit(pawnDropCheckSquare);
        }
      }

      Square to;
      FOREACH_BB(toBB, to, {
        (*moveStackList++).move = makeDropMove(Pawn, to);
      });