okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge the Aurora gfx1151 branch (f-halo-int + HCD_EXACT + the expert bundle) onto 0.1.39bc6b6f87a

main
1.1 KiB36 linesraw
1// src/spec/draft_source.cpp - see include/strata/spec/draft_source.hpp.
2#include "strata/spec/draft_source.hpp"
3
4#include <vector>
5
6namespace strata::spec {
7
8std::vector<std::unique_ptr<DraftSource>>& extra_draft_sources() {
9    static std::vector<std::unique_ptr<DraftSource>> sources;
10    return sources;
11}
12
13int propose_from_sources(DraftSource& own, const int32_t* tail, int n_tail, int n_pending, int max_k, int min_match,
14                         int32_t* out, int* match, int* source) {
15    *match = 0;
16    *source = -1;
17    if (max_k <= 0) return 0;
18    int best = 0;
19    std::vector<int32_t> buf((size_t) max_k);
20    auto ask = [&](DraftSource& s, int index) {
21        int m = 0;
22        const int k = s.propose(tail, n_tail, n_pending, max_k, buf.data(), &m);
23        if (k <= 0 || m < min_match || m <= *match) return;
24        for (int i = 0; i < k && i < max_k; ++i) out[i] = buf[(size_t) i];
25        best = k < max_k ? k : max_k;
26        *match = m;
27        *source = index;
28    };
29    ask(own, 0);
30    int index = 1;
31    for (auto& s : extra_draft_sources())
32        if (s) ask(*s, index++);
33    return best;
34}
35
36}  // namespace strata::spec