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

Aspiration window #67

Merged
merged 6 commits into from
Jun 26, 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
7 changes: 5 additions & 2 deletions Bit-Genie/src/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ namespace BenchMark
std::cout << fen;
throw std::runtime_error("Invalid fen in bench");
}
Search::Info info;
info.position = &position;
info.limits.max_depth = 12;

uint64_t count = bench_search_position(position);
auto count = Search::bestmove(info, false);
std::cout << fen << ": " << count << '\n';
nodes += count;
std::cout << fen << ": " << nodes << std::endl;
}
watch.stop();

Expand Down
4 changes: 2 additions & 2 deletions Bit-Genie/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ int main(int argc, char **argv)
{
Attacks::init();
ZobristKey::init();
init_lmr_array();
uci_input_loop(argc, argv);
Search::init();
UCI::init(argc, argv);
}
3 changes: 0 additions & 3 deletions Bit-Genie/src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class SHistory;
class TTable;
class ZobristKey;

struct SearchInfo;
struct SearchLimits;
struct Search;
struct TEntry;

template <typename E>
Expand Down
31 changes: 17 additions & 14 deletions Bit-Genie/src/moveorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ static int16_t see(Position &position, Move move)
}

template <bool quiet = false>
static void order_normal_movelist(Position &position, Movelist &movelist, Search &search)
static void order_normal_movelist(Movelist &movelist, Search::Info &search)
{
Position& position = *search.position;
for (auto &move : movelist)
{
if constexpr (!quiet)
Expand All @@ -104,29 +105,31 @@ static void order_normal_movelist(Position &position, Movelist &movelist, Search
[](Move rhs, Move lhs) { return move_score(rhs) > move_score(lhs); });
}

void sort_qmovelist(Movelist &movelist, Position &position, Search &search)
void sort_qmovelist(Movelist &movelist, Search::Info& search)
{
order_normal_movelist<false>(position, movelist, search);
order_normal_movelist<false>(movelist, search);
}

MovePicker::MovePicker(Position &p, Search &s)
: position(&p), search(&s)
MovePicker::MovePicker(Search::Info& s)
: search(&s)
{
stage = Stage::HashMove;
}

bool MovePicker::next(Move &move)
{
Position& position = *search->position;

auto can_move = [&](Move m) {
return position->move_is_pseudolegal(m) && position->move_is_legal(m);
return position.move_is_pseudolegal(m) && position.move_is_legal(m);
};

if (stage == Stage::HashMove)
{
stage = Stage::GenNoisy;
auto& entry = TT.retrieve(*position);
auto& entry = TT.retrieve(position);

if (entry.hash == position->key.data() && can_move((Move)entry.move))
if (entry.hash == position.key.data() && can_move((Move)entry.move))
{
move = (Move)entry.move;
return true;
Expand All @@ -135,8 +138,8 @@ bool MovePicker::next(Move &move)

if (stage == Stage::GenNoisy)
{
gen.generate<MoveGenType::noisy>(*position);
order_normal_movelist(*position, gen.movelist, *search);
gen.generate<MoveGenType::noisy>(position);
order_normal_movelist(gen.movelist, *search);

current = gen.movelist.begin();
stage = Stage::GiveGoodNoisy;
Expand All @@ -155,7 +158,7 @@ bool MovePicker::next(Move &move)
if (stage == Stage::Killer1)
{
stage = Stage::Killer2;
Move killer = search->killers.first(search->info.ply);
Move killer = search->killers.first(search->stats.ply);

if (can_move(killer))
{
Expand All @@ -167,7 +170,7 @@ bool MovePicker::next(Move &move)
if (stage == Stage::Killer2)
{
stage = Stage::GiveBadNoisy;
Move killer = search->killers.second(search->info.ply);
Move killer = search->killers.second(search->stats.ply);

if (can_move(killer))
{
Expand All @@ -189,9 +192,9 @@ bool MovePicker::next(Move &move)
if (stage == Stage::GenQuiet)
{
gen.movelist.clear();
gen.generate<MoveGenType::quiet>(*position);
gen.generate<MoveGenType::quiet>(position);

order_normal_movelist<true>(*position, gen.movelist, *search);
order_normal_movelist<true>(gen.movelist, *search);
current = gen.movelist.begin();
stage = Stage::GiveQuiet;
}
Expand Down
11 changes: 5 additions & 6 deletions Bit-Genie/src/moveorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "search.h"
#include "movegen.h"

class MovePicker
{
public:
Expand All @@ -33,17 +33,16 @@ class MovePicker
GiveQuiet
};

MovePicker(Position &, Search &);
MovePicker(Search::Info&);

bool next(Move &);

MoveGenerator<true> gen;
Stage stage = Stage::HashMove;

private:
Position *position;
Search *search;

Search::Info *search;
Movelist::iterator current;
};

void sort_qmovelist(Movelist &, Position &, Search &search);
void sort_qmovelist(Movelist &, Search::Info& );
Loading