forked from stevemaughan/maverick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoveorder.cpp
117 lines (101 loc) · 3.52 KB
/
moveorder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//===========================================================//
//
// Maverick Chess Engine
// Copyright 2013 Steve Maughan
//
//===========================================================//
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "defs.h"
#include "data.h"
#include "procs.h"
void order_moves(struct t_board *board, struct t_move_list *move_list, int ply) {
struct t_move_record *hash_move = move_list->hash_move;
struct t_move_record *move;
struct t_move_record *killer1 = board->pv_data[ply].killer1;
struct t_move_record *killer2 = board->pv_data[ply].killer2;
struct t_move_record *killer3 = NULL;
struct t_move_record *killer4 = NULL;
if (ply > 1) {
killer3 = board->pv_data[ply - 2].killer1;
killer4 = board->pv_data[ply - 2].killer2;
}
for (int i = move_list->count - 1; i >= 0; i--)
{
move = move_list->move[i];
if (move == hash_move){
move_list->value[i] = MOVE_ORDER_HASH;
}
else if (move->captured) {
move_list->value[i] = move->mvvlva + MOVE_ORDER_CAPTURE;
}
else if (move == killer1)
move_list->value[i] = MOVE_ORDER_KILLER1;
else if (move == killer2)
move_list->value[i] = MOVE_ORDER_KILLER2;
else if (move == killer3)
move_list->value[i] = MOVE_ORDER_KILLER3;
else if (move == killer4)
move_list->value[i] = MOVE_ORDER_KILLER4;
else
move_list->value[i] = move->history;
}
}
void order_evade_check(struct t_board *board, struct t_move_list *move_list, int ply) {
struct t_move_record *hash_move = move_list->hash_move;
struct t_move_record *move;
struct t_move_record *killer1 = board->pv_data[ply].check_killer1;
struct t_move_record *killer2 = board->pv_data[ply].check_killer2;
struct t_move_record *killer3 = NULL;
struct t_move_record *killer4 = NULL;
if (ply > 1) {
killer3 = board->pv_data[ply - 2].check_killer1;
killer4 = board->pv_data[ply - 2].check_killer2;
}
for (int i = move_list->count - 1; i >= 0; i--)
{
move = move_list->move[i];
if (move == hash_move){
move_list->value[i] = MOVE_ORDER_HASH;
}
else if (move->captured){
move_list->value[i] = move->mvvlva + MOVE_ORDER_CAPTURE;
}
else if (move == killer1)
move_list->value[i] = MOVE_ORDER_KILLER1;
else if (move == killer2)
move_list->value[i] = MOVE_ORDER_KILLER2;
else if (move == killer3)
move_list->value[i] = MOVE_ORDER_KILLER3;
else if (move == killer4)
move_list->value[i] = MOVE_ORDER_KILLER4;
else
move_list->value[i] = move->history;
}
}
void order_captures(struct t_board *board, struct t_move_list *move_list) {
for (int i = move_list->count - 1; i >= 0; i--)
move_list->value[i] = move_list->move[i]->mvvlva;
}
void age_history_scores()
{
for (int i = 0; i < GLOBAL_MOVE_COUNT; i++) {
xmove_list[i].history /= 16;
}
}
void update_killers(struct t_pv_data *pv, int depth){
if (!pv->current_move->captured && (pv->current_move != pv->killer1)) {
pv->killer2 = pv->killer1;
pv->killer1 = pv->current_move;
pv->current_move->history += (depth * depth);
}
}
void update_check_killers(struct t_pv_data *pv, int depth){
if (!pv->current_move->captured && (pv->current_move != pv->check_killer1)) {
pv->check_killer2 = pv->check_killer1;
pv->check_killer1 = pv->current_move;
pv->current_move->history += (depth * depth);
}
}