-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
legal_actions
をObservationだけから生成する (#1076)
* add declaration * add tests * Update mjxproto * Apply formatter * extract IsRoundOver * add dummy action * Apply formatter * add python test * use pybind * add coment * Apply formatter * fix * fix test * add discards and tsumogiri * Apply formatter * add comments * add switch * add discard after chi/pon * Apply formatter * add discard action after riichi * add HadDrawLeft and RequireKanDraw * tmp CanRon * Apply formatter * extract TargetTile * Apply formatter * implement missed_tiles * add valid * set win state info * Apply formatter * add comments * Apply formatter * add is_ippatsu * Apply formatter * add IsRobbingKan * Apply formatter * add IsFirstTurnWithoutOpen * add chi/pon/kan/no * Apply formatter * add CanRiichi (wrong cnt = 5) * Apply formatter * add CanTsumo (wrong cnt = 4) * Apply formatter * add Kan * Apply formatter * add nine tiles (wrong cnt = 4) * Apply formatter * Update mjxproto * fix test * add assertion * enhance test * enhance tests * fix furiten * Apply formatter * fix bug in tsumo (wrong cnt 1) * fix bug in can riichi (wrong cnt = 0) * Apply formatter * add parallel tests * Update mjxproto * Apply formatter * fix bug in tyankan. # failure = 0/468 (0 %) * Apply formatter * add internal::Observation::GenerateLegalActions * Apply formatter * move test * Apply formatter * revert internal/state.h, state.cpp * fix test * Apply formatter Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3c927a0
commit 13eb4a6
Showing
11 changed files
with
698 additions
and
1,187 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <google/protobuf/util/message_differencer.h> | ||
#include <mjx/internal/state.h> | ||
#include <mjx/internal/utils.h> | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <queue> | ||
#include <thread> | ||
|
||
#include "gtest/gtest.h" | ||
|
||
using namespace mjx::internal; | ||
|
||
template <typename F> | ||
bool ParallelTest(F &&f) { | ||
static std::mutex mtx_; | ||
int total_cnt = 0; | ||
int failure_cnt = 0; | ||
|
||
auto Check = [&total_cnt, &failure_cnt, &f](int begin, int end, | ||
const auto &jsons) { | ||
// { | ||
// std::lock_guard<std::mutex> lock(mtx_); | ||
// std::cerr << std::this_thread::get_id() << " " << begin << " " << end | ||
// << std::endl; | ||
// } | ||
int curr = begin; | ||
while (curr < end) { | ||
const auto &[json, filename] = jsons[curr]; | ||
bool ok = f(json); | ||
{ | ||
std::lock_guard<std::mutex> lock(mtx_); | ||
total_cnt++; | ||
if (!ok) { | ||
failure_cnt++; | ||
std::cerr << filename << std::endl; | ||
} | ||
if (total_cnt % 1000 == 0) | ||
std::cerr << "# failure = " << failure_cnt << "/" << total_cnt << " (" | ||
<< 100.0 * failure_cnt / total_cnt << " %)" << std::endl; | ||
} | ||
curr++; | ||
} | ||
}; | ||
|
||
const auto thread_count = std::thread::hardware_concurrency(); | ||
std::vector<std::thread> threads; | ||
std::vector<std::pair<std::string, std::string>> jsons; | ||
std::string json_path = std::string(TEST_RESOURCES_DIR) + "/json"; | ||
|
||
auto Run = [&]() { | ||
const int json_size = jsons.size(); | ||
const int size_per = json_size / thread_count; | ||
for (int i = 0; i < thread_count; ++i) { | ||
const int start_ix = i * size_per; | ||
const int end_ix = | ||
(i == thread_count - 1) ? json_size : (i + 1) * size_per; | ||
threads.emplace_back(Check, start_ix, end_ix, jsons); | ||
} | ||
for (auto &t : threads) t.join(); | ||
threads.clear(); | ||
jsons.clear(); | ||
}; | ||
|
||
if (!json_path.empty()) | ||
for (const auto &filename : | ||
std::filesystem::directory_iterator(json_path)) { | ||
std::ifstream ifs(filename.path().string(), std::ios::in); | ||
while (!ifs.eof()) { | ||
std::string json; | ||
std::getline(ifs, json); | ||
if (json.empty()) continue; | ||
jsons.emplace_back(std::move(json), filename.path().string()); | ||
} | ||
if (jsons.size() > 1000) Run(); | ||
} | ||
Run(); | ||
|
||
std::cerr << "# failure = " << failure_cnt << "/" << total_cnt << " (" | ||
<< 100.0 * failure_cnt / total_cnt << " %)" << std::endl; | ||
return failure_cnt == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters