mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Better document RootMoveList c'tor
Also some code tidy-up. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
973eb543a4
commit
9ec12da028
2 changed files with 38 additions and 39 deletions
|
@ -82,7 +82,7 @@ namespace {
|
||||||
void sort_multipv(int n);
|
void sort_multipv(int n);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int compare_root_moves(const RootMove &rm1, const RootMove &rm2);
|
static bool compare_root_moves(const RootMove &rm1, const RootMove &rm2);
|
||||||
static const int MaxRootMoves = 500;
|
static const int MaxRootMoves = 500;
|
||||||
RootMove moves[MaxRootMoves];
|
RootMove moves[MaxRootMoves];
|
||||||
int count;
|
int count;
|
||||||
|
@ -562,9 +562,11 @@ namespace {
|
||||||
|
|
||||||
void id_loop(const Position &pos, Move searchMoves[]) {
|
void id_loop(const Position &pos, Move searchMoves[]) {
|
||||||
Position p(pos);
|
Position p(pos);
|
||||||
RootMoveList rml(p, searchMoves);
|
|
||||||
SearchStack ss[PLY_MAX_PLUS_2];
|
SearchStack ss[PLY_MAX_PLUS_2];
|
||||||
|
|
||||||
|
// searchMoves are verified, copied, scored and sorted
|
||||||
|
RootMoveList rml(p, searchMoves);
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
TT.new_search();
|
TT.new_search();
|
||||||
H.clear();
|
H.clear();
|
||||||
|
@ -1602,45 +1604,40 @@ namespace {
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|
||||||
RootMoveList::RootMoveList(Position &pos, Move searchMoves[]) {
|
RootMoveList::RootMoveList(Position& pos, Move searchMoves[]) : count(0) {
|
||||||
|
|
||||||
MoveStack mlist[MaxRootMoves];
|
MoveStack mlist[MaxRootMoves];
|
||||||
bool includeAllMoves = (searchMoves[0] == MOVE_NONE);
|
bool includeAllMoves = (searchMoves[0] == MOVE_NONE);
|
||||||
int i, j = 0, k;
|
|
||||||
|
|
||||||
// Generate all legal moves
|
// Generate all legal moves
|
||||||
count = generate_legal_moves(pos, mlist);
|
int lm_count = generate_legal_moves(pos, mlist);
|
||||||
|
|
||||||
// Add each move to the moves[] array
|
// Add each move to the moves[] array
|
||||||
for(i = 0; i < count; i++) {
|
for (int i = 0; i < lm_count; i++)
|
||||||
UndoInfo u;
|
{
|
||||||
SearchStack ss[PLY_MAX_PLUS_2];
|
bool includeMove = includeAllMoves;
|
||||||
bool includeMove;
|
|
||||||
|
|
||||||
if(includeAllMoves)
|
for (int k = 0; !includeMove && searchMoves[k] != MOVE_NONE; k++)
|
||||||
includeMove = true;
|
includeMove = (searchMoves[k] == mlist[i].move);
|
||||||
else {
|
|
||||||
includeMove = false;
|
|
||||||
for(k = 0; searchMoves[k] != MOVE_NONE; k++)
|
|
||||||
if(searchMoves[k] == mlist[i].move) {
|
|
||||||
includeMove = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(includeMove) {
|
if (includeMove)
|
||||||
moves[j].move = mlist[i].move;
|
{
|
||||||
moves[j].nodes = 0ULL;
|
// Find a quick score for the move
|
||||||
pos.do_move(moves[j].move, u);
|
UndoInfo u;
|
||||||
moves[j].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE,
|
SearchStack ss[PLY_MAX_PLUS_2];
|
||||||
Depth(0), 1, 0);
|
|
||||||
pos.undo_move(moves[j].move, u);
|
moves[count].move = mlist[i].move;
|
||||||
moves[j].pv[0] = moves[i].move;
|
moves[count].nodes = 0ULL;
|
||||||
moves[j].pv[1] = MOVE_NONE; // FIXME
|
pos.do_move(moves[count].move, u);
|
||||||
j++;
|
moves[count].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE,
|
||||||
}
|
Depth(0), 1, 0);
|
||||||
|
pos.undo_move(moves[count].move, u);
|
||||||
|
moves[count].pv[0] = moves[i].move;
|
||||||
|
moves[count].pv[1] = MOVE_NONE; // FIXME
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
count = j;
|
sort();
|
||||||
this->sort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1689,9 +1686,10 @@ namespace {
|
||||||
// is returned, otherwise the function returns MOVE_NONE. It is very
|
// is returned, otherwise the function returns MOVE_NONE. It is very
|
||||||
// important that this function is called at the right moment: The code
|
// important that this function is called at the right moment: The code
|
||||||
// assumes that the first iteration has been completed and the moves have
|
// assumes that the first iteration has been completed and the moves have
|
||||||
// been sorted.
|
// been sorted. This is done in RootMoveList c'tor.
|
||||||
|
|
||||||
Move RootMoveList::scan_for_easy_move() const {
|
Move RootMoveList::scan_for_easy_move() const {
|
||||||
|
|
||||||
Value bestMoveValue = this->get_move_score(0);
|
Value bestMoveValue = this->get_move_score(0);
|
||||||
for(int i = 1; i < this->move_count(); i++)
|
for(int i = 1; i < this->move_count(); i++)
|
||||||
if(this->get_move_score(i) >= bestMoveValue - EasyMoveMargin)
|
if(this->get_move_score(i) >= bestMoveValue - EasyMoveMargin)
|
||||||
|
@ -1734,13 +1732,13 @@ namespace {
|
||||||
// be better than a move m2 if it has a higher score, or if the moves have
|
// be better than a move m2 if it has a higher score, or if the moves have
|
||||||
// equal score but m1 has the higher node count.
|
// equal score but m1 has the higher node count.
|
||||||
|
|
||||||
int RootMoveList::compare_root_moves(const RootMove &rm1,
|
bool RootMoveList::compare_root_moves(const RootMove &rm1,
|
||||||
const RootMove &rm2) {
|
const RootMove &rm2) {
|
||||||
if(rm1.score < rm2.score) return 1;
|
|
||||||
else if(rm1.score > rm2.score) return 0;
|
if (rm1.score != rm2.score)
|
||||||
else if(rm1.nodes < rm2.nodes) return 1;
|
return (rm1.score < rm2.score);
|
||||||
else if(rm1.nodes > rm2.nodes) return 0;
|
|
||||||
else return 1;
|
return rm1.nodes <= rm2.nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ namespace {
|
||||||
|
|
||||||
// load_defaults populates the options vector with the hard
|
// load_defaults populates the options vector with the hard
|
||||||
// coded names and default values.
|
// coded names and default values.
|
||||||
|
|
||||||
void load_defaults(Options& o) {
|
void load_defaults(Options& o) {
|
||||||
|
|
||||||
o.push_back(Option("Use Search Log", false));
|
o.push_back(Option("Use Search Log", false));
|
||||||
|
|
Loading…
Add table
Reference in a new issue