Rev 154 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 154 | Rev 169 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
4 | Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
5 | Copyright (C) 2015- |
5 | Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad |
6 | 6 | ||
7 | Stockfish is free software: you can redistribute it and/or modify |
7 | Stockfish is free software: you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation, either version 3 of the License, or |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. |
10 | (at your option) any later version. |
Line 40... | Line 40... | ||
40 | Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1); |
40 | Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1); |
41 | Bitboard enemies = pos.pieces(~us); |
41 | Bitboard enemies = pos.pieces(~us); |
42 | 42 | ||
43 | assert(!pos.checkers()); |
43 | assert(!pos.checkers()); |
44 | 44 | ||
45 | const |
45 | const Direction K = Chess960 ? kto > kfrom ? WEST : EAST |
46 | : KingSide ? WEST : EAST; |
46 | : KingSide ? WEST : EAST; |
47 | 47 | ||
48 | for (Square s = kto; s != kfrom; s += K) |
48 | for (Square s = kto; s != kfrom; s += K) |
49 | if (pos.attackers_to(s) & enemies) |
49 | if (pos.attackers_to(s) & enemies) |
50 | return moveList; |
50 | return moveList; |
51 | 51 | ||
Line 63... | Line 63... | ||
63 | *moveList++ = m; |
63 | *moveList++ = m; |
64 | return moveList; |
64 | return moveList; |
65 | } |
65 | } |
66 | 66 | ||
67 | 67 | ||
68 | template<GenType Type, |
68 | template<GenType Type, Direction D> |
69 | ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) { |
69 | ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) { |
70 | 70 | ||
71 | if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) |
71 | if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) |
72 | *moveList++ = make<PROMOTION>(to - D, to, QUEEN); |
72 | *moveList++ = make<PROMOTION>(to - D, to, QUEEN); |
73 | 73 | ||
Line 78... | Line 78... | ||
78 | *moveList++ = make<PROMOTION>(to - D, to, KNIGHT); |
78 | *moveList++ = make<PROMOTION>(to - D, to, KNIGHT); |
79 | } |
79 | } |
80 | 80 | ||
81 | // Knight promotion is the only promotion that can give a direct check |
81 | // Knight promotion is the only promotion that can give a direct check |
82 | // that's not already included in the queen promotion. |
82 | // that's not already included in the queen promotion. |
83 | if (Type == QUIET_CHECKS && ( |
83 | if (Type == QUIET_CHECKS && (PseudoAttacks[KNIGHT][to] & ksq)) |
84 | *moveList++ = make<PROMOTION>(to - D, to, KNIGHT); |
84 | *moveList++ = make<PROMOTION>(to - D, to, KNIGHT); |
85 | else |
85 | else |
86 | (void)ksq; // Silence a warning under MSVC |
86 | (void)ksq; // Silence a warning under MSVC |
87 | 87 | ||
88 | return moveList; |
88 | return moveList; |
Line 92... | Line 92... | ||
92 | template<Color Us, GenType Type> |
92 | template<Color Us, GenType Type> |
93 | ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) { |
93 | ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) { |
94 | 94 | ||
95 | // Compute our parametrized parameters at compile time, named according to |
95 | // Compute our parametrized parameters at compile time, named according to |
96 | // the point of view of white side. |
96 | // the point of view of white side. |
97 | const Color Them = (Us == WHITE ? BLACK : WHITE); |
97 | const Color Them = (Us == WHITE ? BLACK : WHITE); |
98 | const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB); |
98 | const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB); |
99 | const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB); |
99 | const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB); |
100 | const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); |
100 | const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); |
101 | const |
101 | const Direction Up = (Us == WHITE ? NORTH : SOUTH); |
102 | const |
102 | const Direction Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST); |
103 | const |
103 | const Direction Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST); |
104 | 104 | ||
105 | Bitboard emptySquares; |
105 | Bitboard emptySquares; |
106 | 106 | ||
107 | Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB; |
107 | Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB; |
108 | Bitboard pawnsNotOn7 = pos.pieces(Us, PAWN) & ~TRank7BB; |
108 | Bitboard pawnsNotOn7 = pos.pieces(Us, PAWN) & ~TRank7BB; |
Line 344... | Line 344... | ||
344 | PieceType pt = type_of(pos.piece_on(from)); |
344 | PieceType pt = type_of(pos.piece_on(from)); |
345 | 345 | ||
346 | if (pt == PAWN) |
346 | if (pt == PAWN) |
347 | continue; // Will be generated together with direct checks |
347 | continue; // Will be generated together with direct checks |
348 | 348 | ||
349 | Bitboard b = pos.attacks_from( |
349 | Bitboard b = pos.attacks_from(pt, from) & ~pos.pieces(); |
350 | 350 | ||
351 | if (pt == KING) |
351 | if (pt == KING) |
352 | b &= ~PseudoAttacks[QUEEN][pos.square<KING>(~us)]; |
352 | b &= ~PseudoAttacks[QUEEN][pos.square<KING>(~us)]; |
353 | 353 | ||
354 | while (b) |
354 | while (b) |