From 55a53ba9517d10dcbd5d17507b4d3a6471e9c10c Mon Sep 17 00:00:00 2001 From: jsc723 Date: Wed, 19 Apr 2023 10:12:43 -0700 Subject: [PATCH] add score --- simulator.cpp | 33 ++++++++---- simulator.h | 1 + test/example.yml | 26 ++++++---- test/sushi.yml | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+), 20 deletions(-) create mode 100644 test/sushi.yml diff --git a/simulator.cpp b/simulator.cpp index 00c8854..0e03864 100644 --- a/simulator.cpp +++ b/simulator.cpp @@ -30,14 +30,21 @@ YGO::Simulator::Simulator(YAML::Node simulate) Combo combo; combo.name = jt->first.as(); auto combo_node = jt->second; - if (combo_node.IsDefined() && combo_node.IsSequence()) + if (combo_node["score"].IsDefined()) { + combo.score = combo_node["score"].as(); + } + auto combo_conds_node = combo_node["conditions"]; + if (combo_conds_node.IsDefined() && combo_conds_node.IsSequence()) { - for (int j = 0; j < combo_node.size(); j++) + for (int j = 0; j < combo_conds_node.size(); j++) { - t_string cond_k = combo_node[j].as(); + t_string cond_k = combo_conds_node[j].as(); combo.condition_strings.push_back(cond_k); } } + else { + panic("Combo is not correctly defined: " + combo.name); + } topic.m_combos.emplace_back(std::move(combo)); } m_topics.emplace_back(std::move(topic)); @@ -58,6 +65,7 @@ void YGO::Simulator::run(const Deck& deck, Context& context) int num_topic = m_topics.size(); vector>> success(m_turns); //turn, topic, combo vector> total_success(m_turns, vector(num_topic)); //turn, topic + vector> total_score(m_turns, vector(num_topic)); //turn, topic int max_num_combo = 0; for (int t = 0; t < m_turns; t++) { @@ -80,7 +88,6 @@ void YGO::Simulator::run(const Deck& deck, Context& context) printf("Simulate %d times...\n", m_count); auto start_time = chrono::high_resolution_clock::now(); - vector combo_test(max_num_combo); for (int k = 0; k < m_count; k++) { @@ -91,15 +98,18 @@ void YGO::Simulator::run(const Deck& deck, Context& context) for (int i = 0; i < m_topics.size(); i++) { const int num_combo = m_topics[i].m_combos.size(); - fill(combo_test.begin(), combo_test.begin() + num_combo, false); bool any_success = false; + double max_topic_score = 0.0; for (int j = 0; j < num_combo; j++) { - combo_test[j] = m_topics[i].m_combos[j].test(handCards); - any_success |= combo_test[j]; - success[t][i][j] += combo_test[j]; + if (m_topics[i].m_combos[j].test(handCards)) { + success[t][i][j]++; + any_success = true; + max_topic_score = std::max(max_topic_score, m_topics[i].m_combos[j].score); + } } total_success[t][i] += any_success; + total_score[t][i] += max_topic_score; } handCards.push_back(cards[m_start_card + t + 1]); //draw } @@ -114,12 +124,13 @@ void YGO::Simulator::run(const Deck& deck, Context& context) cout << "Topic: " << m_topics[i].name << endl; for (int t = 0; t < m_turns; t++) { const int num_combo = m_topics[i].m_combos.size(); - printf("Turn %d total: %.2lf%% ", t + 1, (double)total_success[t][i] / m_count * 100.0); + printf("Turn %d average success rate: %.2lf%% ", t + 1, (double)total_success[t][i] / m_count * 100.0); + printf("average score: %.2lf\n", (double)total_score[t][i] / m_count); for (int j = 0; j < num_combo; j++) { - printf("%s: %.2lf%% ", m_topics[i].m_combos[j].name.c_str(), (double)success[t][i][j] / m_count * 100.0); + printf(" %s: %.2lf%% ", m_topics[i].m_combos[j].name.c_str(), (double)success[t][i][j] / m_count * 100.0); } - printf("\n"); + printf("\n\n"); } printf("\n"); } diff --git a/simulator.h b/simulator.h index 585e88a..2b67338 100644 --- a/simulator.h +++ b/simulator.h @@ -14,6 +14,7 @@ namespace YGO { int m_turns; struct Combo { t_string name; + double score = 1.0; std::vector condition_strings; std::vector conditions; bool test(const std::vector cards); diff --git a/test/example.yml b/test/example.yml index c4ffdcb..0d5b5dc 100644 --- a/test/example.yml +++ b/test/example.yml @@ -66,22 +66,30 @@ simulate: tests: Expand: witches1: - - a:start - - Witches-Magic + score: 1.0 + conditions: + - a:start + - Witches-Magic witches2: - - Witches-Monster !a:low - - w-demo - - Witches-Magic + conditions: + - Witches-Monster !a:low + - w-demo + - Witches-Magic dhero: - - dhero-fusion + score: 1.5 + conditions: + - dhero-fusion Field: field: - - sato + conditions: + - sato Resist: hand-trap: - - a:handtrap + conditions: + - a:handtrap huai-shou: - - huai-shou + conditions: + - huai-shou diff --git a/test/sushi.yml b/test/sushi.yml new file mode 100644 index 0000000..c978b27 --- /dev/null +++ b/test/sushi.yml @@ -0,0 +1,130 @@ + +deck: + cards: + sushi-white-rice: + count: 3 + attribute: ['M', 'sushi', 'rice', 'rice-like'] + sushi-red-rice: + count: 3 + attribute: ['M', 'sushi', 'rice', 'rice-like'] + sushi-ikura: + count: 2 + attribute: ['M', 'sushi'] + sushi-shirauo: + count: 3 + attribute: ['M', 'sushi'] + sushi-uni: + count: 3 + attribute: ['M2', 'sushi'] + kowakuma-trion: + count: 3 + attribute: ['M', 'kowakuma'] + kowakuma-tio: + count: 1 + attribute: ['M', 'kowakuma'] + kowakuma-ranka: + count: 0 + attribute: ['M', 'kowakuma'] + kowakuma-jiner: + count: 1 + attribute: ['M', 'kowakuma'] + + ketsudann: + count: 3 + attribute: ['H', 'rice-like'] + umisen: + count: 1 + attribute: ['H', 'sushi'] + kiri-yami: + count: 0 + attribute: ['H'] + kimagure: + count: 2 + attribute: ['T', 'sushi'] + + urara: + count: 3 + attribute: ['M', 'hand-trip'] + zou-g: + count: 3 + attribute: ['M', 'hand-trip'] + houyou: + count: 2 + attribute: ['T', 'hand-trip', 'general-trip'] + other-trip: + count: 7 + attribute: ['T', 'general-trip'] + + others: + count: 2 + classes: + Sushi: a:sushi A:M? + Sushi5: a:sushi a:M2 + Sushi4-Non-Rice: a:sushi a:M !a:rice + Sushi-Non-Rice: Sushi !a:rice + Kowakuma: a:kowakuma a:M +simulate: + count: 50000 + start_card: 5 + turns: 3 + tests: + Expand: + A1: + score: 1.0 + conditions: + - a:rice + - a:rice-like + A3: + score: 3.6 + conditions: + - a:rice + - a:rice-like + - Kowakuma + - a:T + B1: + score: 0.0 + conditions: + - sushi-ikura + - a:rice-like + B2: + score: 1.5 + conditions: + - sushi-shirauo + - a:rice-like + B3: + score: 2.5 + conditions: + - sushi-ikura + - sushi-shirauo + - a:rice-like + B4: + score: 3.5 #shirauo 1.5 + sera 2.0 + conditions: + - sushi-ikura + - sushi-shirauo + - a:rice-like + - a:T + C1: + score: 1.0 + conditions: + - Sushi5 + - a:rice-like + C2: + score: 2.0 + conditions: + - Sushi5 + - a:rice-like + - Sushi4-Non-Rice + C3: + score: 3.6 #r5 1 + trion 0.6 + sera 2.0 + conditions: + - Sushi5 + - a:rice-like + - Kowakuma + - a:T + + + + + +