From 2fd6f5dac8239b6c7d7b281d9ec35ee33c774bc0 Mon Sep 17 00:00:00 2001 From: jsc723 Date: Wed, 19 Apr 2023 13:58:59 -0700 Subject: [PATCH] update documentation --- README.md | 210 ++++++++++++++++++++++------------------------- test/example.yml | 4 +- test/sushi.yml | 35 +++++--- ygo-calc.cpp | 10 +-- 4 files changed, 127 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index f7cb5bf..565c31b 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,16 @@ deck:配置牌组 attribute: 一个列表,定义赋予该卡的属性(标签) 属性内容自定义,例如怪兽卡、魔法卡,本家卡、泛用卡、手坑等等,均用字符串表示 注意卡牌总数不要超过之前定义的size - classes: 定义卡片的类型,每个class是一个类型,格式为 - 类型名: 条件1 条件2 条件3 ... - 每个条件之间是逻辑与(&&)关系 - 每个条件的格式必须是以下一种: + conditions: 给条件或条件的组合起别名,格式为 + 条件名: <条件列表> + <条件列表>的格式为` ...`,中间用空格隔开 + 每个condition之间是逻辑与(&&)关系 + 每个condition的格式必须是以下一种: 1. 牌组(deck)中定义的卡牌名 - 2. 定义在当前class之前的类型名 (例如class1已经定义,当前在定义class2,则定义class2时可以引用class1) - 3. a:属性 -> 要求该类型包含某种特定的属性 - 4. A:属性(模糊匹配) -> 要求该类型包含某种特定的属性,后面的表达式可以带*(匹配任意个任意字符)或?(匹配一个任意字符) - 5. !条件 -> 逻辑取反(要求后面跟的条件为假) + 2. a:属性 -> 要求该类型包含某种特定的属性 + 3. A:属性(模糊匹配) -> 要求该类型包含某种特定的属性,后面的表达式可以带*(匹配任意个任意字符)或?(匹配一个任意字符) + 4. !条件 -> 逻辑取反(要求后面跟的条件为假) + 5. 定义在此项之前的条件名 simulate: 模拟器配置 count:模拟次数 start_card: 初始手牌为多少张卡(默认5) @@ -27,14 +28,18 @@ simulate: 模拟器配置 tests:列举想要关注的主题(例:展开、阻抗),每个主题之间互不相干 主题名: 列举当前主题希望得到的手牌组合,每个组合之间是逻辑与(||)关系 组合名: 定义一种希望满足的条件,列举需要的手牌 - - 手牌类型1 (引用deck定义的卡牌名或classes定义的类型名) - ... - (注:当一张卡牌匹配了一种手牌类型之后,这张卡牌不会被用于匹配其他手牌类型,列举在前的手牌类型具有更高的优先级) + score: 该组合的分数(比如有多少个阻抗,默认1.0) + conditions: + - condition1 (conditions定义的条件名,或者<条件列表>) + - condition2 + ... + (注:当一张卡牌匹配了一种手牌类型之后,这张卡牌不会被用于匹配其他手牌类型,列举在前的手牌类型具有更高的优先级) ``` 注:文档里请只写半角字符(不要写中文不然可能出错) #### 例 ```yaml +deck: deck: size: 40 cards: @@ -80,8 +85,6 @@ deck: dhero-fusion: count: 2 attribute: ['H1', 'dhero'] - w-patoro: - attribute: ['W', 'witches'] urara: count: 2 attribute: ['M', 'handtrap'] @@ -90,44 +93,49 @@ deck: attribute: ['M', 'huai-shou'] others: count: -1 - classes: + conditions: Witches: A:w*ch?s Witches-Monster: Witches a:M Witches-Low-Monster: Witches a:M a:low Witches-High-Monster: Witches-Monster !a:low Witches-Magic: Witches A:H? Witches-Search: w-creation - Witches-Start: a:start - Field: sato - DHERO-Fusion: dhero-fusion - Hand-Trap: a:handtrap simulate: - count: 50000 + count: 1000 start_card: 5 turns: 6 tests: Expand: witches1: - - Witches-Start - - Witches-Magic + score: 1.0 + conditions: + - a:start + - Witches-Magic witches2: - - Witches-High-Monster - - w-demo - - Witches-Magic + conditions: + - Witches-High-Monster + - w-demo + - Witches-Magic dhero: - - DHERO-Fusion + score: 2.0 + conditions: + - dhero-fusion Field: field: - - Field + conditions: + - sato Resist: hand-trap: - - Hand-Trap + conditions: + - a:handtrap huai-shou: - - huai-shou + conditions: + - huai-shou + ``` 在`deck`中,我定义了一个40卡魔女术牌组,从上至下依次是魔女术本家的7种怪,7种本家魔法卡,魔法族之村(sato), -融合命运,灰流,坏兽,其他卡 +融合命运,灰流丽,坏兽,其他卡 我把所有怪兽都赋予`M`标签,所有魔法卡按照类型分别赋予`H1` `H2` `H0` `Hf`(通常,速攻,永继,场地) 魔女术本家卡片赋予`witches`标签 @@ -155,11 +163,11 @@ Witches-High-Monster: Witches-Monster !a:low 其中展开又分为本家的两种展开和凤凰人展开,场地卡只有魔法族之村,阻抗又分成手坑和坏兽(暂且归为阻抗)每一中主题里,希望得到什么样的组合,就直接列举出来: -本家第一种展开(witches1),我希望手上有一张本家初动(Witches-Start:下级怪或检索魔法卡),并且还有另一张任意本家魔法卡(Witches-Magic),其他手牌任意 +本家第一种展开(witches1),我希望手上有一张本家初动(a:start:下级怪或检索魔法卡),并且还有另一张任意本家魔法卡(Witches-Magic),其他手牌任意(这种展开我给的分数是1分) -本家第二种展开(witches2),我希望手上有一张本家高级怪,一张演示(出高级怪),和另一张任意本家魔法卡 +本家第二种展开(witches2),我希望手上有一张本家高级怪,一张演示(出高级怪),和另一张任意本家魔法卡(这种展开我给的分数也是1分) -第三种展开(dhero),只要我手上有融合命运就行(DHERO-Fusion) +第三种展开(dhero),只要我手上有融合命运就行(DHERO-Fusion),这种展开的给的分数是2分 程序的输出中,对于每一个主题,每一个回合,都会显示每个主题成功的概率,以及每种组合单独的概率 (输出样例在下面) @@ -178,93 +186,67 @@ ygo-calc.exe ## 程序输出样例 ``` $ ./ygo-calc.exe example.yml -size: 40 -cards: -name: w-red, count: 3, attribute: [M low start witches ] -name: w-yellow, count: 2, attribute: [M low start witches ] -name: w-grey, count: 2, attribute: [M low start witches ] -name: w-green, count: 1, attribute: [M low start witches ] -name: w-blue, count: 2, attribute: [M witches ] -name: w-black, count: 2, attribute: [M witches ] -name: w-white, count: 1, attribute: [M witches ] -name: w-creation, count: 3, attribute: [H1 start witches ] -name: w-sabo, count: 2, attribute: [H1 witches ] -name: w-colab, count: 1, attribute: [H1 witches ] -name: w-demo, count: 2, attribute: [H2 witches ] -name: w-wind, count: 1, attribute: [H2 witches ] -name: w-street, count: 1, attribute: [H0 witches ] -name: w-scroll, count: 1, attribute: [H0 witches ] -name: sato, count: 4, attribute: [Hf ] -name: dhero-fusion, count: 2, attribute: [H1 dhero ] -name: urara, count: 2, attribute: [M handtrap ] -name: huai-shou, count: 1, attribute: [M huai-shou ] -name: others, count: 7 - -w-creation: name==w-creation -Hand-Trap: attr=handtrap -Witches-High-Monster: attr~w*ch?s && attr=M && !attr=low -w-red: name==w-red -w-green: name==w-green -w-black: name==w-black -w-yellow: name==w-yellow -w-demo: name==w-demo -w-white: name==w-white -w-grey: name==w-grey -w-blue: name==w-blue -w-sabo: name==w-sabo -w-colab: name==w-colab -w-wind: name==w-wind -w-street: name==w-street -w-scroll: name==w-scroll -sato: name==sato -DHERO-Fusion: name==dhero-fusion -dhero-fusion: name==dhero-fusion -urara: name==urara -huai-shou: name==huai-shou -others: name==others -Witches: attr~w*ch?s -Witches-Monster: attr~w*ch?s && attr=M -Witches-Low-Monster: attr~w*ch?s && attr=M && attr=low -Witches-Magic: attr~w*ch?s && attr~H? -Witches-Search: name==w-creation -Witches-Start: attr=start -Field: name==sato - -Expand: witches1: Witches-Start Witches-Magic -witches2: Witches-High-Monster w-demo Witches-Magic -dhero: DHERO-Fusion - -Field: field: Field - -Resist: hand-trap: Hand-Trap -huai-shou: huai-shou - - -Simulate 50000 times... -Time used: 2329ms +Simulate 1000 times... +Time used: 91ms Topic: Expand -Turn 1 total: 74.25% witches1: 60.59% witches2: 6.49% dhero: 23.54% -Turn 2 total: 83.54% witches1: 71.60% witches2: 10.81% dhero: 27.88% -Turn 3 total: 90.04% witches1: 80.17% witches2: 15.69% dhero: 32.15% -Turn 4 total: 93.95% witches1: 86.49% witches2: 20.84% dhero: 36.16% -Turn 5 total: 96.51% witches1: 91.03% witches2: 26.15% dhero: 40.15% -Turn 6 total: 98.03% witches1: 94.10% witches2: 31.48% dhero: 44.03% +Turn 1 average success rate: 76.00% average score: 0.99 + witches1: 62.10% witches2: 6.20% dhero: 23.10% + +Turn 2 average success rate: 84.70% average score: 1.11 + witches1: 72.20% witches2: 10.50% dhero: 26.20% + +Turn 3 average success rate: 90.60% average score: 1.22 + witches1: 80.80% witches2: 15.40% dhero: 31.20% + +Turn 4 average success rate: 95.00% average score: 1.29 + witches1: 88.60% witches2: 20.90% dhero: 34.50% + +Turn 5 average success rate: 97.10% average score: 1.35 + witches1: 92.10% witches2: 25.50% dhero: 38.10% + +Turn 6 average success rate: 98.40% average score: 1.41 + witches1: 94.90% witches2: 30.70% dhero: 42.40% + Topic: Field -Turn 1 total: 42.98% field: 42.98% -Turn 2 total: 49.54% field: 49.54% -Turn 3 total: 55.28% field: 55.28% -Turn 4 total: 60.84% field: 60.84% -Turn 5 total: 65.68% field: 65.68% -Turn 6 total: 70.06% field: 70.06% +Turn 1 average success rate: 39.70% average score: 0.40 + field: 39.70% + +Turn 2 average success rate: 45.90% average score: 0.46 + field: 45.90% + +Turn 3 average success rate: 51.90% average score: 0.52 + field: 51.90% + +Turn 4 average success rate: 57.30% average score: 0.57 + field: 57.30% + +Turn 5 average success rate: 62.60% average score: 0.63 + field: 62.60% + +Turn 6 average success rate: 67.50% average score: 0.68 + field: 67.50% + Topic: Resist -Turn 1 total: 33.83% hand-trap: 23.63% huai-shou: 12.56% -Turn 2 total: 39.47% hand-trap: 27.99% huai-shou: 15.06% -Turn 3 total: 44.80% hand-trap: 32.22% huai-shou: 17.52% -Turn 4 total: 49.58% hand-trap: 36.13% huai-shou: 19.94% -Turn 5 total: 54.30% hand-trap: 40.11% huai-shou: 22.43% -Turn 6 total: 58.76% hand-trap: 44.03% huai-shou: 24.94% +Turn 1 average success rate: 33.70% average score: 0.34 + hand-trap: 24.20% huai-shou: 12.30% + +Turn 2 average success rate: 38.70% average score: 0.39 + hand-trap: 27.90% huai-shou: 14.50% + +Turn 3 average success rate: 43.30% average score: 0.43 + hand-trap: 31.80% huai-shou: 16.10% + +Turn 4 average success rate: 48.60% average score: 0.49 + hand-trap: 36.10% huai-shou: 18.40% + +Turn 5 average success rate: 53.00% average score: 0.53 + hand-trap: 39.40% huai-shou: 21.10% + +Turn 6 average success rate: 57.60% average score: 0.58 + hand-trap: 43.40% huai-shou: 23.40% + ``` diff --git a/test/example.yml b/test/example.yml index 0d5b5dc..407d567 100644 --- a/test/example.yml +++ b/test/example.yml @@ -52,7 +52,7 @@ deck: attribute: ['M', 'huai-shou'] others: count: -1 - classes: + conditions: Witches: A:w*ch?s Witches-Monster: Witches a:M Witches-Low-Monster: Witches a:M a:low @@ -76,7 +76,7 @@ simulate: - w-demo - Witches-Magic dhero: - score: 1.5 + score: 2.0 conditions: - dhero-fusion Field: diff --git a/test/sushi.yml b/test/sushi.yml index c978b27..ac0235a 100644 --- a/test/sushi.yml +++ b/test/sushi.yml @@ -8,7 +8,7 @@ deck: count: 3 attribute: ['M', 'sushi', 'rice', 'rice-like'] sushi-ikura: - count: 2 + count: 3 attribute: ['M', 'sushi'] sushi-shirauo: count: 3 @@ -57,7 +57,7 @@ deck: others: count: 2 - classes: + conditions: Sushi: a:sushi A:M? Sushi5: a:sushi a:M2 Sushi4-Non-Rice: a:sushi a:M !a:rice @@ -70,58 +70,71 @@ simulate: tests: Expand: A1: - score: 1.0 + score: 3.5 #freshia(1.5) + 4 hand-card(0.5) + action: "draw" conditions: - a:rice - a:rice-like A3: - score: 3.6 + score: 5.6 #freshia(1.5) + 0.6*trip(1.0) + sera(2.0) + 3*hand-card(0.5) conditions: - a:rice - a:rice-like - Kowakuma - a:T B1: - score: 0.0 + score: 1.5 #freshia(1.5) + 3 hand(0.5) conditions: - sushi-ikura - a:rice-like B2: - score: 1.5 + score: 3.2 #kuubo(0.2) + 4 hand(0.5) + kimagure (1.0) conditions: - sushi-shirauo - a:rice-like B3: - score: 2.5 + score: 4.7 #kuubo(0.2) + freshia(1.5) + 4 hand(0.5) + kimagure(1.0) conditions: - sushi-ikura - sushi-shirauo - a:rice-like B4: - score: 3.5 #shirauo 1.5 + sera 2.0 + score: 5.7 #kuubo(0.2) + sera(2.0) + trip(1.0) + 3 hand(0.5) + kimagure(1.0) conditions: - sushi-ikura - sushi-shirauo - a:rice-like - a:T C1: - score: 1.0 + score: 3.0 #r5(0.5) + 5 hand(0.5) conditions: - Sushi5 - a:rice-like C2: - score: 2.0 + score: 3.5 #r5(0.5) + 3 hand(0.5) + fureshia(1.5) conditions: - Sushi5 - a:rice-like - Sushi4-Non-Rice C3: - score: 3.6 #r5 1 + trion 0.6 + sera 2.0 + score: 4.6 #r5(0.5) + 3 hand(0.5) + 0.6*trip(1.0) + sera 2.0 conditions: - Sushi5 - a:rice-like - Kowakuma - a:T + HandTrip: + HT1: + score: 1.0 + conditions: + - a:hand-trip + HT2: + score: 2.0 + conditions: + - a:hand-trip + - a:hand-trip + + diff --git a/ygo-calc.cpp b/ygo-calc.cpp index 32a1f8e..4c517da 100644 --- a/ygo-calc.cpp +++ b/ygo-calc.cpp @@ -53,14 +53,14 @@ int main(int argc, char **argv) { context.addCardNameCondition(card); } - YAML::Node classes = root["deck"]["classes"]; - if (classes.IsDefined()) + YAML::Node conditions = root["deck"]["conditions"]; + if (conditions.IsDefined()) { - for (auto it = classes.begin(); it != classes.end(); ++it) + for (auto it = conditions.begin(); it != conditions.end(); ++it) { - auto className = it->first.as(); + auto conditionName = it->first.as(); auto condition = it->second.as(); - context.addCondition(className, Utils::parse(context, condition)); + context.addCondition(conditionName, Utils::parse(context, condition)); } } context.print(cout);