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 109... | Line 109... | ||
| 109 | KPKPosition::KPKPosition(unsigned idx) { |
109 | KPKPosition::KPKPosition(unsigned idx) { |
| 110 | 110 | ||
| 111 | ksq[WHITE] = Square((idx >> 0) & 0x3F); |
111 | ksq[WHITE] = Square((idx >> 0) & 0x3F); |
| 112 | ksq[BLACK] = Square((idx >> 6) & 0x3F); |
112 | ksq[BLACK] = Square((idx >> 6) & 0x3F); |
| 113 | us = Color ((idx >> 12) & 0x01); |
113 | us = Color ((idx >> 12) & 0x01); |
| 114 | psq = make_square(File((idx >> 13) & 0x3), RANK_7 - |
114 | psq = make_square(File((idx >> 13) & 0x3), Rank(RANK_7 - ((idx >> 15) & 0x7))); |
| 115 | 115 | ||
| 116 | // Check if two pieces are on the same square or if a king can be captured |
116 | // Check if two pieces are on the same square or if a king can be captured |
| 117 | if ( distance(ksq[WHITE], ksq[BLACK]) <= 1 |
117 | if ( distance(ksq[WHITE], ksq[BLACK]) <= 1 |
| 118 | || ksq[WHITE] == psq |
118 | || ksq[WHITE] == psq |
| 119 | || ksq[BLACK] == psq |
119 | || ksq[BLACK] == psq |
| 120 | || (us == WHITE && ( |
120 | || (us == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK]))) |
| 121 | result = INVALID; |
121 | result = INVALID; |
| 122 | 122 | ||
| 123 | // Immediate win if a pawn can be promoted without getting captured |
123 | // Immediate win if a pawn can be promoted without getting captured |
| 124 | else if ( us == WHITE |
124 | else if ( us == WHITE |
| 125 | && rank_of(psq) == RANK_7 |
125 | && rank_of(psq) == RANK_7 |
| 126 | && ksq[us] != psq + NORTH |
126 | && ksq[us] != psq + NORTH |
| 127 | && ( distance(ksq[~us], psq + NORTH) > 1 |
127 | && ( distance(ksq[~us], psq + NORTH) > 1 |
| 128 | || ( |
128 | || (PseudoAttacks[KING][ksq[us]] & (psq + NORTH)))) |
| 129 | result = WIN; |
129 | result = WIN; |
| 130 | 130 | ||
| 131 | // Immediate draw if it is a stalemate or a king captures undefended pawn |
131 | // Immediate draw if it is a stalemate or a king captures undefended pawn |
| 132 | else if ( us == BLACK |
132 | else if ( us == BLACK |
| 133 | && ( !( |
133 | && ( !(PseudoAttacks[KING][ksq[us]] & ~(PseudoAttacks[KING][ksq[~us]] | PawnAttacks[~us][psq])) |
| 134 | || ( |
134 | || (PseudoAttacks[KING][ksq[us]] & psq & ~PseudoAttacks[KING][ksq[~us]]))) |
| 135 | result = DRAW; |
135 | result = DRAW; |
| 136 | 136 | ||
| 137 | // Position will be classified later |
137 | // Position will be classified later |
| 138 | else |
138 | else |
| 139 | result = UNKNOWN; |
139 | result = UNKNOWN; |
| Line 155... | Line 155... | ||
| 155 | const Color Them = (Us == WHITE ? BLACK : WHITE); |
155 | const Color Them = (Us == WHITE ? BLACK : WHITE); |
| 156 | const Result Good = (Us == WHITE ? WIN : DRAW); |
156 | const Result Good = (Us == WHITE ? WIN : DRAW); |
| 157 | const Result Bad = (Us == WHITE ? DRAW : WIN); |
157 | const Result Bad = (Us == WHITE ? DRAW : WIN); |
| 158 | 158 | ||
| 159 | Result r = INVALID; |
159 | Result r = INVALID; |
| 160 | Bitboard b = |
160 | Bitboard b = PseudoAttacks[KING][ksq[Us]]; |
| 161 | 161 | ||
| 162 | while (b) |
162 | while (b) |
| 163 | r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)] |
163 | r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)] |
| 164 | : db[index(Them, pop_lsb(&b), ksq[Them] , psq)]; |
164 | : db[index(Them, pop_lsb(&b), ksq[Them] , psq)]; |
| 165 | 165 | ||