search: fixed a bug in NULL move pruning
[owl.git] / sort.c
blob6df03b42eb67180935bf6531f54766f2218e9ad5
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #include "common.h"
17 #include "move.h"
18 #include "engine.h"
20 void
21 sort_moves(struct moves_t *moves, int current, int ply)
23 int i;
24 int high;
26 assert(current >= 0 && current <= MAX_MOVES);
28 high = current;
29 for (i = current; i < moves->count; i++) {
30 assert(move_is_legal(moves->move[i]));
32 if (moves->move[i] == hash_moves[ply]) {
33 high = i;
34 break;
37 if (killers[ply].mate_killer == moves->move[i])
38 moves->score[i] += 15000;
39 if (killers[ply].killer1 == moves->move[i] || \
40 killers[ply].killer2 == moves->move[i])
41 moves->score[i] += 5000;
43 if (moves->score[i] > moves->score[high])
44 high = i;
47 int tmp_move = moves->move[high];
48 int tmp_score = moves->score[high];
49 int tmp_see = moves->see[high];
51 moves->move[high] = moves->move[current];
52 moves->score[high] = moves->score[current];
53 moves->see[high] = moves->see[current];
55 moves->move[current] = tmp_move;
56 moves->score[current] = tmp_score;
57 moves->see[current] = tmp_see;