Skip to content

Commit

Permalink
add score
Browse files Browse the repository at this point in the history
  • Loading branch information
jsc723 committed Apr 19, 2023
1 parent 96e98f8 commit 55a53ba
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 20 deletions.
33 changes: 22 additions & 11 deletions simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ YGO::Simulator::Simulator(YAML::Node simulate)
Combo combo;
combo.name = jt->first.as<t_string>();
auto combo_node = jt->second;
if (combo_node.IsDefined() && combo_node.IsSequence())
if (combo_node["score"].IsDefined()) {
combo.score = combo_node["score"].as<double>();
}
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>();
t_string cond_k = combo_conds_node[j].as<t_string>();
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));
Expand All @@ -58,6 +65,7 @@ void YGO::Simulator::run(const Deck& deck, Context& context)
int num_topic = m_topics.size();
vector<vector<vector<int>>> success(m_turns); //turn, topic, combo
vector<vector<int>> total_success(m_turns, vector<int>(num_topic)); //turn, topic
vector<vector<double>> total_score(m_turns, vector<double>(num_topic)); //turn, topic
int max_num_combo = 0;
for (int t = 0; t < m_turns; t++)
{
Expand All @@ -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<bool> combo_test(max_num_combo);

for (int k = 0; k < m_count; k++)
{
Expand All @@ -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
}
Expand All @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace YGO {
int m_turns;
struct Combo {
t_string name;
double score = 1.0;
std::vector<t_string> condition_strings;
std::vector<Condition*> conditions;
bool test(const std::vector<Card> cards);
Expand Down
26 changes: 17 additions & 9 deletions test/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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



130 changes: 130 additions & 0 deletions test/sushi.yml
Original file line number Diff line number Diff line change
@@ -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






0 comments on commit 55a53ba

Please sign in to comment.