Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Speedup movepicker #78

Merged
merged 2 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Bit-Genie/src/moveorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int16_t see(Position &position, Move move)
}

template <bool quiet = false>
static void order_normal_movelist(Movelist &movelist, Search::Info &search)
static void score_movelist(Movelist &movelist, Search::Info &search)
{
Position& position = *search.position;
for (auto &move : movelist)
Expand All @@ -101,13 +101,19 @@ static void order_normal_movelist(Movelist &movelist, Search::Info &search)
else
set_move_score(move, search.history.get(position, move));
}
std::stable_sort(movelist.begin(), movelist.end(),
[](Move rhs, Move lhs) { return move_score(rhs) > move_score(lhs); });
}

void bubble_top_move(Movelist::iterator begin, Movelist::iterator end)
{
auto best = std::max_element(begin, end ,
[](Move lhs, Move rhs){return move_score(lhs) < move_score(rhs); });
std::iter_swap(best, begin);
}

void sort_qmovelist(Movelist &movelist, Search::Info& search)
{
order_normal_movelist<false>(movelist, search);
score_movelist<false>(movelist, search);
std::stable_sort(movelist.begin(), movelist.end(), [](Move lhs, Move rhs){ return move_score(lhs) > move_score(rhs); });
}

MovePicker::MovePicker(Search::Info& s)
Expand Down Expand Up @@ -139,9 +145,11 @@ bool MovePicker::next(Move &move)
if (stage == Stage::GenNoisy)
{
gen.generate<MoveGenType::noisy>(position);
order_normal_movelist(gen.movelist, *search);


score_movelist(gen.movelist, *search);
bubble_top_move(gen.movelist.begin(), gen.movelist.end());
current = gen.movelist.begin();

stage = Stage::GiveGoodNoisy;
}

Expand All @@ -150,6 +158,7 @@ bool MovePicker::next(Move &move)
if (current != gen.movelist.end() && move_score(*current) > 0)
{
move = *current++;
bubble_top_move(current, gen.movelist.end());
return true;
}
stage = Stage::Killer1;
Expand Down Expand Up @@ -184,6 +193,7 @@ bool MovePicker::next(Move &move)
if (current != gen.movelist.end())
{
move = *current++;
bubble_top_move(current, gen.movelist.end());
return true;
}
stage = Stage::GenQuiet;
Expand All @@ -194,7 +204,8 @@ bool MovePicker::next(Move &move)
gen.movelist.clear();
gen.generate<MoveGenType::quiet>(position);

order_normal_movelist<true>(gen.movelist, *search);
score_movelist<true>(gen.movelist, *search);
bubble_top_move(gen.movelist.begin(), gen.movelist.end());
current = gen.movelist.begin();
stage = Stage::GiveQuiet;
}
Expand All @@ -204,6 +215,7 @@ bool MovePicker::next(Move &move)
if (current != gen.movelist.end())
{
move = *current++;
bubble_top_move(current, gen.movelist.end());
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Bit-Genie/src/uci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "searchinit.h"
#include "polyglot.h"

const char *version = "7.11";
const char *version = "7.12";

namespace
{
Expand Down