Example #1
0
        // evaluate_unstoppable_pawns() scores the most advanced among the passed and
        // candidate pawns. In case opponent has no pieces but pawns, this is somewhat
        // related to the possibility that pawns are unstoppable.
        public static Score evaluate_unstoppable_pawns(Position pos, Color us, EvalInfo ei)
        {
            Bitboard b = ei.pi.passed_pawns(us) | ei.pi.candidate_pawns(us);

            if (0 == b || pos.non_pawn_material(Types.notColor(us)) != 0)
            {
                return(ScoreS.SCORE_ZERO);
            }

            return(Unstoppable * (Types.relative_rank_square(us, BitBoard.frontmost_sq(us, b))));
        }
Example #2
0
        /// generate<CAPTURES> generates all pseudo-legal captures and queen
        /// promotions. Returns a pointer to the end of the move list.
        ///
        /// generate<QUIETS> generates all pseudo-legal non-captures and
        /// underpromotions. Returns a pointer to the end of the move list.
        ///
        /// generate<NON_EVASIONS> generates all pseudo-legal captures and
        /// non-captures. Returns a pointer to the end of the move list.
        ///
        public static int generate_captures_quiets_non_evasions(Position pos, ExtMove[] mlist, int mPos, GenType Type)
        {
            Debug.Assert(Type == GenTypeS.CAPTURES || Type == GenTypeS.QUIETS || Type == GenTypeS.NON_EVASIONS);
            Debug.Assert(pos.checkers() == 0);
            Color us = pos.side_to_move();

            Bitboard target = Type == GenTypeS.CAPTURES ? pos.pieces_color(Types.notColor(us))
                  : Type == GenTypeS.QUIETS ? ~pos.pieces()
                  : Type == GenTypeS.NON_EVASIONS ? ~pos.pieces_color(us) : 0;

            return(us == ColorS.WHITE ? generate_all(pos, mlist, mPos, target, ColorS.WHITE, Type)
                                      : generate_all(pos, mlist, mPos, target, ColorS.BLACK, Type));
        }
Example #3
0
        public static int generate_castling(Position pos, ExtMove[] mlist, int mPos, Color us, CheckInfo ci, CastlingRight Cr, bool Checks, bool Chess960)
        {
            bool KingSide = (Cr == CastlingRightS.WHITE_OO || Cr == CastlingRightS.BLACK_OO);

            if (pos.castling_impeded(Cr) || 0 == pos.can_castle_castleright(Cr))
            {
                return(mPos);
            }

            // After castling, the rook and king final positions are the same in Chess960
            // as they would be in standard chess.
            Square   kfrom   = pos.king_square(us);
            Square   rfrom   = pos.castling_rook_square(Cr);
            Square   kto     = Types.relative_square(us, KingSide ? SquareS.SQ_G1 : SquareS.SQ_C1);
            Bitboard enemies = pos.pieces_color(Types.notColor(us));

            Debug.Assert(0 == pos.checkers());

            Square K = Chess960 ? kto > kfrom ? SquareS.DELTA_W : SquareS.DELTA_E
                              : KingSide ? SquareS.DELTA_W : SquareS.DELTA_E;

            for (Square s = kto; s != kfrom; s += K)
            {
                if ((pos.attackers_to(s) & enemies) != 0)
                {
                    return(mPos);
                }
            }

            // Because we generate only legal castling moves we need to verify that
            // when moving the castling rook we do not discover some hidden checker.
            // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
            if (Chess960 && (BitBoard.attacks_bb_SBBPT(kto, pos.pieces() ^ BitBoard.SquareBB[rfrom], PieceTypeS.ROOK) & pos.pieces_color_piecetype(Types.notColor(us), PieceTypeS.ROOK, PieceTypeS.QUEEN)) != 0)
            {
                return(mPos);
            }

            Move m = Types.make(kfrom, rfrom, MoveTypeS.CASTLING);

            if (Checks && !pos.gives_check(m, ci))
            {
                return(mPos);
            }

            mlist[mPos++].move = m;

            return(mPos);
        }
 public EndgameBase(Color c, EndgameType E)
 {
     this.endgameType = E;
     this.strongSide  = c;
     this.weakSide    = Types.notColor(c);
 }