Commit 987146ea authored by biluo.shen's avatar biluo.shen

Add discard_hand

parent 15833b80
#created by wxapp_ygo
#main
62849088
05141117
93490856
93490856
93490856
55273560
55273560
55273560
20001443
20001443
20001443
56495147
56495147
56495147
59438930
59438930
14558127
14558127
23434538
23434538
83764718
93850690
56465981
56465981
56465981
18144506
83308376
24224830
24224830
39730727
39730727
10045474
10045474
23068051
23068051
78836195
14821890
14821890
14821890
99137266
#extra
53971455
86682165
84815190
96633955
47710198
09464441
69248256
69248256
93039339
05402805
78917791
29301450
!side
\ No newline at end of file
......@@ -52,4 +52,8 @@
69248256
83755611
43202238
32519092
32519092
32519092
78917791
!side
......@@ -4,7 +4,8 @@ add_repositories("my-repo repo")
add_requires(
"ygopro-core", "pybind11 2.10.*", "fmt 10.2.*", "glog 0.6.0",
"concurrentqueue 1.0.4", "sqlitecpp 3.2.1", "unordered_dense 4.4.*")
"sqlite3 3.43.0+200", "concurrentqueue 1.0.4", "unordered_dense 4.4.*",
"sqlitecpp 3.2.1")
-- target("dummy_ygopro")
......
......@@ -2,10 +2,12 @@
#define YGOENV_YGOPRO_YGOPRO_H_
// clang-format off
#include <numeric>
#include <stdexcept>
#include <string>
#include <fstream>
#include <shared_mutex>
#include <iostream>
#include <fmt/core.h>
#include <fmt/ranges.h>
......@@ -883,7 +885,8 @@ inline card_data db_query_card_data(const SQLite::Database &db, CardCode code) {
card_data card;
card.code = code;
card.alias = query.getColumn("alias");
card.setcode = query.getColumn("setcode").getInt64();
uint64_t setcode = query.getColumn("setcode").getInt64();
card.set_setcode(setcode);
card.type = query.getColumn("type");
uint32_t level_ = query.getColumn("level");
card.level = level_ & 0xff;
......@@ -1311,6 +1314,9 @@ protected:
std::vector<std::string> revealed_;
// discard hand cards
bool discard_hand_ = false;
public:
YGOProEnv(const Spec &spec, int env_id)
: Env<YGOProEnvSpec>(spec, env_id),
......@@ -1442,10 +1448,51 @@ public:
if (ha_p < 0) {
ha_p = n_history_actions_ - 1;
}
history_actions[ha_p].Zero();
_set_obs_action(history_actions, ha_p, msg_, options_[idx], {},
h_card_ids[idx]);
}
void show_deck(const std::vector<CardCode> &deck, const std::string &prefix) const {
fmt::print("{} deck:", prefix);
for (auto code : deck) {
fmt::print(" {}", c_get_card(code).name());
}
fmt::print("\n");
}
void show_turn() const {
fmt::println("turn: {}, phase: {}, tplayer: {}", turn_count_, phase_to_string(current_phase_), tp_);
}
void show_deck(PlayerId player) const {
fmt::print("Player {}'s deck:\n", player);
show_deck(player == 0 ? main_deck0_ : main_deck1_, "Main");
show_deck(player == 0 ? extra_deck0_ : extra_deck1_, "Extra");
}
void show_history_actions(PlayerId player) const {
const auto &ha = player == 0 ? history_actions_0_ : history_actions_1_;
// print card ids of history actions
for (int i = 0; i < n_history_actions_; ++i) {
fmt::print("history {}\n", i);
uint8_t msg_id = uint8_t(ha(i, _obs_action_feat_offset()));
int msg = _msgs[msg_id - 1];
fmt::print("msg: {},", msg_to_string(msg));
for (int j = 0; j < spec_.config["max_multi_select"_]; j++) {
auto v1 = static_cast<CardId>(ha(i, 2 * j));
auto v2 = static_cast<CardId>(ha(i, 2 * j + 1));
CardId card_id = (v1 << 8) + v2;
fmt::print(" {}", card_id);
}
fmt::print(";");
for (int j = _obs_action_feat_offset() + 1; j < ha.Shape()[1]; j++) {
fmt::print(" {}", uint8_t(ha(i, j)));
}
fmt::print("\n");
}
}
void Step(const Action &action) override {
// clock_t start = clock();
......@@ -2421,13 +2468,13 @@ private:
players_[pl]->notify(fmt::format("{} equipped to {}.", c, t));
}
} else if (msg_ == MSG_HINT) {
if (!verbose_) {
dp_ = dl_;
return;
}
auto hint_type = int(read_u8());
auto hint_type = read_u8();
auto player = read_u8();
auto value = read_u32();
if (hint_type == HINT_SELECTMSG && value == 501) {
discard_hand_ = true;
}
// non-GUI don't need hint
return;
if (hint_type == HINT_SELECTMSG) {
......@@ -3055,14 +3102,6 @@ private:
auto max = read_u8();
auto size = read_u8();
if (min > spec_.config["max_multi_select"_]) {
fmt::println("min: {}, max: {}, size: {}", min, max, size);
throw std::runtime_error(
fmt::format("Min > {} not implemented for select card",
spec_.config["max_multi_select"_]));
}
max = std::min(max, uint8_t(spec_.config["max_multi_select"_]));
std::vector<std::string> specs;
specs.reserve(size);
if (verbose_) {
......@@ -3098,6 +3137,38 @@ private:
}
}
if (min > spec_.config["max_multi_select"_]) {
if (discard_hand_) {
// random discard
std::vector<int> comb(size);
std::iota(comb.begin(), comb.end(), 0);
std::shuffle(comb.begin(), comb.end(), gen_);
resp_buf_[0] = min;
for (int i = 0; i < min; ++i) {
resp_buf_[i + 1] = comb[i];
}
set_responseb(pduel_, resp_buf_);
discard_hand_ = false;
return;
}
show_turn();
show_deck(player);
show_history_actions(player);
show_deck(1-player);
show_history_actions(1-player);
fmt::println("player: {}, min: {}, max: {}, size: {}", player, min, max, size);
std::cout << std::flush;
throw std::runtime_error(
fmt::format("Min > {} not implemented for select card",
spec_.config["max_multi_select"_]));
}
max = std::min(max, uint8_t(spec_.config["max_multi_select"_]));
std::vector<std::vector<int>> combs;
for (int i = min; i <= max; ++i) {
for (const auto &comb : combinations(size, i)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment