📄 sort.cpp
字号:
if(see_move(move, sort->board) < 0)
continue;
if(!pseudo_is_legal(move, sort->board))
continue;
}
else
{
return 0;
}
return move;
}
// next stage
gen = code[sort->gen++];
if(false) { }
else if(gen == GEN_EVASION_QS)
{
gen_pseudo_evasions(sort->list, sort->board, sort->attack);
note_moves_simple(sort->list, sort->board);
list_sort(sort->list);
sort->test = TEST_LEGAL;
}
else if(gen == GEN_CAPTURE_QS)
{
gen_captures(sort->list, sort->board);
note_mvv_lva(sort->list, sort->board);
list_sort(sort->list);
sort->test = TEST_CAPTURE_QS;
}
else if(gen == GEN_CHECK_QS)
{
gen_quiet_checks(sort->list, sort->board);
sort->test = TEST_CHECK_QS;
}
else
{
return 0;
}
sort->pos = 0;
}
}
// good_move()
void good_move(int move, const board_t *board, int depth, int height, int thread_id)
{
uint16 index;
int i;
if(move_is_tactical(move, board))
return;
// killer
if(killer[thread_id][height][0] != move)
{
killer[thread_id][height][1] = killer[thread_id][height][0];
killer[thread_id][height][0] = move;
}
// history
index = history_index(move, board);
history[thread_id][index] += HISTORY_INC(depth);
if(history[thread_id][index] >= 16384)
{
for ( i = 0; i < 768; i++ )
{
history[thread_id][i] = (history[thread_id][i] + 1) / 2;
}
}
}
// history_good()
void history_good(int move, const board_t *board, int thread_id)
{
uint16 index;
if(move_is_tactical(move, board))
return;
// history
index = history_index(move, board);
hist_hit[thread_id][index]++;
hist_tot[thread_id][index]++;
if(hist_tot[thread_id][index] >= 16384)
{
hist_hit[thread_id][index] = (hist_hit[thread_id][index] + 1) / 2;
hist_tot[thread_id][index] = (hist_tot[thread_id][index] + 1) / 2;
}
}
// history_bad()
void history_bad(int move, const board_t *board, int thread_id)
{
uint16 index;
if(move_is_tactical(move, board))
return;
// history
index = history_index(move, board);
hist_tot[thread_id][index]++;
if(hist_tot[thread_id][index] >= 16384)
{
hist_hit[thread_id][index] = (hist_hit[thread_id][index] + 1) / 2;
hist_tot[thread_id][index] = (hist_tot[thread_id][index] + 1) / 2;
}
}
void history_reset(int move, const board_t *board, int thread_id)
{
uint16 index;
// history
index = history_index(move, board);
hist_hit[thread_id][index] = 1;
hist_tot[thread_id][index] = 1;
}
// note_moves()
void note_moves(list_t *list, const board_t *board, int height, int trans_killer, int thread_id)
{
int size;
int i, move;
size = LIST_SIZE(list);
if(size >= 2)
{
for ( i = 0; i < size; i++ )
{
move = LIST_MOVE(list, i);
list->value[i] = move_value(move, board, height, trans_killer, thread_id);
}
}
}
// note_quiet_moves()
static void note_quiet_moves(list_t *list, const board_t *board, int thread_id)
{
int size;
int i, move;
size = LIST_SIZE(list);
if(size >= 2)
{
for ( i = 0; i < size; i++ )
{
move = LIST_MOVE(list, i);
list->value[i] = quiet_move_value(move, board, thread_id);
}
}
}
// note_moves_simple()
static void note_moves_simple(list_t *list, const board_t *board)
{
int size;
int i, move;
size = LIST_SIZE(list);
if(size >= 2)
{
for ( i = 0; i < size; i++ )
{
move = LIST_MOVE(list, i);
list->value[i] = move_value_simple(move, board);
}
}
}
// note_mvv_lva()
static void note_mvv_lva(list_t *list, const board_t *board)
{
int size;
int i, move;
size = LIST_SIZE(list);
if(size >= 2)
{
for ( i = 0; i < size; i++ )
{
move = LIST_MOVE(list, i);
list->value[i] = mvv_lva(move, board);
}
}
}
// move_value()
static int move_value(int move, const board_t *board, int height, int trans_killer, int thread_id)
{
int value;
if(false) { }
else if(move == trans_killer)
{ // transposition table killer
value = 32766;
}
else if(move_is_tactical(move, board))
{ // capture or promote
value = capture_value(move, board);
}
else if(move == killer[thread_id][height][0])
{ // killer 1
value = 4;
}
else if(move == killer[thread_id][height][1])
{ // killer 2
value = 4 - 2;
}
else
{ // quiet move
value = quiet_move_value(move, board, thread_id);
}
return value;
}
// capture_value()
static int capture_value(int move, const board_t *board)
{
int value;
value = mvv_lva(move, board);
if(capture_is_good(move, board))
{
value += 4000;
}
else
{
value += -28000;
}
return value;
}
// quiet_move_value()
static int quiet_move_value(int move, const board_t *board, int thread_id)
{
int value;
uint16 index;
index = history_index(move, board);
value = -24000 + history[thread_id][index];
return value;
}
// move_value_simple()
static int move_value_simple(int move, const board_t *board)
{
int value;
value = -24000;
if(move_is_tactical(move, board))
value = mvv_lva(move, board);
return value;
}
// history_prob()
static int history_prob(int move, const board_t *board, int thread_id)
{
int value;
uint16 index;
index = history_index(move, board);
value = (hist_hit[thread_id][index] * 16384) / hist_tot[thread_id][index];
return value;
}
// capture_is_good()
static bool capture_is_good(int move, const board_t *board)
{
int piece, capture;
// special cases
if(MOVE_IS_EN_PASSANT(move))
return true;
if(move_is_under_promote(move))
return false; // REMOVE ME?
// captures and queen promotes
capture = board->square[MOVE_TO(move)];
if(capture != 0)
{
// capture
if(MOVE_IS_PROMOTE(move))
return true; // promote-capture
piece = board->square[MOVE_FROM(move)];
if(VALUE_PIECE(capture) >= VALUE_PIECE(piece))
return true;
}
return see_move(move, board) >= 0;
}
// mvv_lva()
static int mvv_lva(int move, const board_t *board)
{
int piece, capture, promote;
int value;
if(MOVE_IS_EN_PASSANT(move))
{ // en-passant capture
value = 5; // PxP
}
else if((capture = board->square[MOVE_TO(move)]) != 0)
{ // normal capture
piece = board->square[MOVE_FROM(move)];
value = PIECE_ORDER(capture) * 6 - PIECE_ORDER(piece) + 5;
}
else
{ // promote
promote = move_promote(move);
value = PIECE_ORDER(promote) - 5;
}
return value;
}
// history_index()
static uint16 history_index(int move, const board_t *board)
{
uint16 index;
index = PIECE_TO_12(board->square[MOVE_FROM(move)]) * 64 + SQUARE_TO_64(MOVE_TO(move));
return index;
}
// end of sort.cpp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -