1. [TestFixture]
  2. public class AiTest
  3. {
  4. [Test]
  5. public void Test()
  6. {
  7. Settings.Instance.LogFolderPath = @"C:\repository\GitHub\ChuckLu\Test\HearthbuddyRelease\Logs";
  8. Settings.Instance.DataFolderPath =
  9. @"C:\repository\GitHub\ChuckLu\Test\HearthbuddyRelease\Routines\DefaultRoutine\SilverFish\Data\";
  10. if (Hrtprozis.Instance.settings == null)
  11. {
  12. Hrtprozis.Instance.setInstances();
  13. ComboBreaker.Instance.setInstances();
  14. PenalityManager.Instance.setInstances();
  15. }
  16.  
  17. //-mode: 0-all, 1-lethalcheck, 2-normal
  18. Ai ai = Ai.Instance;
  19. ai.autoTester(true, string.Empty, );
  20.  
  21. }
  22. }
  1. if (mode == || mode == )
  2. {
  3. doallmoves(false, true);
  4. calcTime = (DateTime.Now - strt).TotalSeconds;
  5. help.logg("calculated " + calcTime);
  6. retval.Add(calcTime);
  7. }
  8.  
  9. if (Settings.Instance.berserkIfCanFinishNextTour > && bestmoveValue > )
  10. {
  11.  
  12. }
  13. else if (bestmoveValue < )
  14. {
  15. // normal
  16. if (mode == || mode == )
  17. {
  18. posmoves.Clear();
  19. pMain = new Playfield();
  20. pMain.print = printstuff;
  21. posmoves.Add(pMain);
  22. strt = DateTime.Now;
  23. doallmoves(false, false);
  24. calcTime = (DateTime.Now - strt).TotalSeconds;
  25. help.logg("calculated " + calcTime);
  26. retval.Add(calcTime);
  27. }
  28. }

发现格雷迈恩的效果,不知道怎么触发的,需要直接运行exe调试

在    routine.Tick();设置断点,F11之后会加载DefaultRoutine.dll

  1. // Triton.Bot.RoutineManager
  2. // Token: 0x060011C9 RID: 4553 RVA: 0x000B65BC File Offset: 0x000B47BC
  3. public static void Tick(IRoutine routine)
  4. {
  5. RoutineManager.smethod_0(routine, RoutineManager.routineEvent_2);
  6. try
  7. {
  8. routine.Tick();
  9. }
  10. catch (Exception exception)
  11. {
  12. RoutineManager.ilog_0.Error("Exception during routine Tick.", exception);
  13. }
  14. RoutineManager.smethod_0(routine, RoutineManager.routineEvent_3);
  15. }
  1. // HREngine.Bots.Ai
  2. // Token: 0x06000061 RID: 97 RVA: 0x00009000 File Offset: 0x00007200
  3. private void doallmoves(bool test, bool isLethalCheck)
  4. {
  5. foreach (EnemyTurnSimulator ets in this.enemyTurnSim)
  6. {
  7. ets.setMaxwide(true);
  8. }
  9. foreach (EnemyTurnSimulator ets2 in this.enemySecondTurnSim)
  10. {
  11. ets2.setMaxwide(true);
  12. }
  13. this.posmoves[].isLethalCheck = isLethalCheck;
  14. this.mainTurnSimulator.doallmoves(this.posmoves[]);
  15. this.bestplay = this.mainTurnSimulator.bestboard;
  16. float bestval = this.mainTurnSimulator.bestmoveValue;
  17. this.help.loggonoff(true);
  18. this.help.logg("-------------------------------------");
  19. bool flag = this.bestplay.ruleWeight != ;
  20. if (flag)
  21. {
  22. this.help.logg("ruleWeight " + this.bestplay.ruleWeight * -);
  23. }
  24. bool flag2 = this.settings.printRules > ;
  25. if (flag2)
  26. {
  27. string[] rulesStr = this.bestplay.rulesUsed.Split(new char[]
  28. {
  29. '@'
  30. });
  31. foreach (string rs in rulesStr)
  32. {
  33. bool flag3 = rs == "";
  34. if (!flag3)
  35. {
  36. this.help.logg("rule: " + rs);
  37. }
  38. }
  39. }
  40. this.help.logg("value of best board " + bestval);
  41. this.bestActions.Clear();
  42. this.bestmove = null;
  43. ActionNormalizer an = new ActionNormalizer();
  44. bool flag4 = this.settings.adjustActions > ;
  45. if (flag4)
  46. {
  47. an.adjustActions(this.bestplay, isLethalCheck);
  48. }
  49. foreach (Action a in this.bestplay.playactions)
  50. {
  51. this.bestActions.Add(new Action(a));
  52. a.print(false);
  53. }
  54. bool flag5 = this.bestActions.Count >= ;
  55. if (flag5)
  56. {
  57. this.bestmove = this.bestActions[];
  58. this.bestActions.RemoveAt();
  59. }
  60. this.bestmoveValue = bestval;
  61. bool flag6 = this.bestmove != null && this.bestmove.actionType > actionEnum.endturn;
  62. if (flag6)
  63. {
  64. this.nextMoveGuess = new Playfield();
  65. this.nextMoveGuess.doAction(this.bestmove);
  66. }
  67. else
  68. {
  69. this.nextMoveGuess.mana = -;
  70. }
  71. if (isLethalCheck)
  72. {
  73. this.lethalMissing = this.bestplay.enemyHero.armor + this.bestplay.enemyHero.Hp;
  74. this.help.logg("missing dmg to lethal " + this.lethalMissing);
  75. }
  76. }
  1. // HREngine.Bots.MiniSimulator
  2. // Token: 0x060000E0 RID: 224 RVA: 0x00018480 File Offset: 0x00016680
  3. public float doallmoves(Playfield playf)
  4. {
  5. this.print = playf.print;
  6. this.isLethalCheck = playf.isLethalCheck;
  7. this.enoughCalculations = false;
  8. this.botBase = Ai.Instance.botBase;
  9. this.posmoves.Clear();
  10. this.twoturnfields.Clear();
  11. this.addToPosmoves(playf);
  12. bool havedonesomething = true;
  13. List<Playfield> temp = new List<Playfield>();
  14. int deep = ;
  15. this.calculated = ;
  16. Playfield bestold = null;
  17. this.bestoldval = -2E+07f;
  18. while (havedonesomething)
  19. {
  20. bool flag = this.printNormalstuff;
  21. if (flag)
  22. {
  23. Helpfunctions.Instance.logg("ailoop");
  24. }
  25. GC.Collect();
  26. temp.Clear();
  27. temp.AddRange(this.posmoves);
  28. this.posmoves.Clear();
  29. havedonesomething = false;
  30. this.threadnumberGlobal = ;
  31. bool flag2 = this.print;
  32. if (flag2)
  33. {
  34. this.startEnemyTurnSimThread(temp, , temp.Count);
  35. }
  36. else
  37. {
  38. Parallel.ForEach<Tuple<int, int>>(Partitioner.Create(, temp.Count), delegate(Tuple<int, int> range)
  39. {
  40. this.startEnemyTurnSimThread(temp, range.Item1, range.Item2);
  41. });
  42. }
  43. foreach (Playfield p in temp)
  44. {
  45. bool flag3 = this.totalboards > ;
  46. if (flag3)
  47. {
  48. this.calculated += p.nextPlayfields.Count;
  49. }
  50. bool flag4 = this.calculated <= this.totalboards;
  51. if (flag4)
  52. {
  53. this.posmoves.AddRange(p.nextPlayfields);
  54. p.nextPlayfields.Clear();
  55. }
  56. float pVal = this.botBase.getPlayfieldValue(p);
  57. bool flag5 = pVal > this.bestoldval;
  58. if (flag5)
  59. {
  60. this.bestoldval = pVal;
  61. bestold = p;
  62. this.bestoldDuplicates.Clear();
  63. }
  64. else
  65. {
  66. bool flag6 = pVal == this.bestoldval;
  67. if (flag6)
  68. {
  69. this.bestoldDuplicates.Add(p);
  70. }
  71. }
  72. }
  73. bool flag7 = this.isLethalCheck && this.bestoldval >= 10000f;
  74. if (flag7)
  75. {
  76. this.posmoves.Clear();
  77. }
  78. bool flag8 = this.posmoves.Count > ;
  79. if (flag8)
  80. {
  81. havedonesomething = true;
  82. }
  83. bool flag9 = this.printNormalstuff;
  84. if (flag9)
  85. {
  86. int donec = ;
  87. foreach (Playfield p2 in this.posmoves)
  88. {
  89. bool complete = p2.complete;
  90. if (complete)
  91. {
  92. donec++;
  93. }
  94. }
  95. Helpfunctions.Instance.logg(string.Concat(new object[]
  96. {
  97. "deep ",
  98. deep,
  99. " len ",
  100. this.posmoves.Count,
  101. " dones ",
  102. donec
  103. }));
  104. }
  105. this.cuttingposibilities(this.isLethalCheck);
  106. bool flag10 = this.printNormalstuff;
  107. if (flag10)
  108. {
  109. Helpfunctions.Instance.logg("cut to len " + this.posmoves.Count);
  110. }
  111. deep++;
  112. temp.Clear();
  113. bool flag11 = this.calculated > this.totalboards;
  114. if (flag11)
  115. {
  116. this.enoughCalculations = true;
  117. }
  118. bool flag12 = deep >= this.maxdeep;
  119. if (flag12)
  120. {
  121. this.enoughCalculations = true;
  122. }
  123. }
  124. bool flag13 = this.dirtyTwoTurnSim > && !this.twoturnfields.Contains(bestold);
  125. if (flag13)
  126. {
  127. this.twoturnfields.Add(bestold);
  128. }
  129. this.posmoves.Clear();
  130. this.posmoves.Add(bestold);
  131. this.posmoves.AddRange(this.bestoldDuplicates);
  132. bool flag14 = !this.isLethalCheck && this.bestoldval < 10000f;
  133. if (flag14)
  134. {
  135. this.doDirtyTwoTurnsim();
  136. }
  137. bool flag15 = this.posmoves.Count >= ;
  138. float result;
  139. if (flag15)
  140. {
  141. this.posmoves.Sort((Playfield a, Playfield b) => this.botBase.getPlayfieldValue(b).CompareTo(this.botBase.getPlayfieldValue(a)));
  142. Playfield bestplay = this.posmoves[];
  143. float bestval = this.botBase.getPlayfieldValue(bestplay);
  144. int pcount = this.posmoves.Count;
  145. for (int i = ; i < pcount; i++)
  146. {
  147. float val = this.botBase.getPlayfieldValue(this.posmoves[i]);
  148. bool flag16 = bestval > val;
  149. if (flag16)
  150. {
  151. break;
  152. }
  153. bool flag17 = this.posmoves[i].cardsPlayedThisTurn > bestplay.cardsPlayedThisTurn;
  154. if (!flag17)
  155. {
  156. bool flag18 = this.posmoves[i].cardsPlayedThisTurn == bestplay.cardsPlayedThisTurn;
  157. if (flag18)
  158. {
  159. bool flag19 = bestplay.optionsPlayedThisTurn > this.posmoves[i].optionsPlayedThisTurn;
  160. if (flag19)
  161. {
  162. goto IL_57A;
  163. }
  164. bool flag20 = bestplay.optionsPlayedThisTurn == this.posmoves[i].optionsPlayedThisTurn && bestplay.enemyHero.Hp <= this.posmoves[i].enemyHero.Hp;
  165. if (flag20)
  166. {
  167. goto IL_57A;
  168. }
  169. }
  170. bestplay = this.posmoves[i];
  171. bestval = val;
  172. }
  173. IL_57A:;
  174. }
  175. this.bestmove = bestplay.getNextAction();
  176. this.bestmoveValue = bestval;
  177. this.bestboard = new Playfield(bestplay);
  178. this.bestboard.guessingHeroHP = bestplay.guessingHeroHP;
  179. this.bestboard.value = bestplay.value;
  180. this.bestboard.hashcode = bestplay.hashcode;
  181. this.bestoldDuplicates.Clear();
  182. result = bestval;
  183. }
  184. else
  185. {
  186. this.bestmove = null;
  187. this.bestmoveValue = -100000f;
  188. this.bestboard = playf;
  189. result = -10000f;
  190. }
  191. return result;
  192. }
  1. // HREngine.Bots.MiniSimulatorNextTurn
  2. // Token: 0x060000EE RID: 238 RVA: 0x00019890 File Offset: 0x00017A90
  3. public float doallmoves(Playfield playf, bool print = false)
  4. {
  5. bool isLethalCheck = playf.isLethalCheck;
  6. int totalboards = Settings.Instance.nextTurnTotalBoards;
  7. int maxwide = Settings.Instance.nextTurnMaxWide;
  8. int maxdeep = Settings.Instance.nextTurnDeep;
  9. bool playaround = Settings.Instance.playaround;
  10. int playaroundprob = Settings.Instance.playaroundprob;
  11. int playaroundprob2 = Settings.Instance.playaroundprob2;
  12. this.botBase = Ai.Instance.botBase;
  13. this.posmoves.Clear();
  14. this.posmoves.Add(new Playfield(playf));
  15. bool havedonesomething = true;
  16. List<Playfield> temp = new List<Playfield>();
  17. int deep = ;
  18. this.calculated = ;
  19. Playfield bestold = null;
  20. float bestoldval = -2E+07f;
  21. while (havedonesomething)
  22. {
  23. temp.Clear();
  24. temp.AddRange(this.posmoves);
  25. havedonesomething = false;
  26. foreach (Playfield p in temp)
  27. {
  28. bool flag = p.complete || p.ownHero.Hp <= ;
  29. if (!flag)
  30. {
  31. List<Action> actions = this.movegen.getMoveList(p, this.usePenalityManager, this.useCutingTargets, true);
  32. foreach (Action a2 in actions)
  33. {
  34. havedonesomething = true;
  35. Playfield pf = new Playfield(p);
  36. pf.doAction(a2);
  37. bool flag2 = pf.ownHero.Hp > ;
  38. if (flag2)
  39. {
  40. this.posmoves.Add(pf);
  41. }
  42. bool flag3 = totalboards > ;
  43. if (flag3)
  44. {
  45. this.calculated++;
  46. }
  47. }
  48. p.endTurn();
  49. bool flag4 = !isLethalCheck;
  50. if (flag4)
  51. {
  52. this.startEnemyTurnSim(p, this.simulateSecondTurn, false, playaround, playaroundprob, playaroundprob2);
  53. }
  54. bool flag5 = this.botBase.getPlayfieldValue(p) > bestoldval;
  55. if (flag5)
  56. {
  57. bestoldval = this.botBase.getPlayfieldValue(p);
  58. bestold = p;
  59. }
  60. this.posmoves.Remove(p);
  61. bool flag6 = this.calculated > totalboards;
  62. if (flag6)
  63. {
  64. break;
  65. }
  66. }
  67. }
  68. this.cuttingposibilities(maxwide);
  69. deep++;
  70. bool flag7 = this.calculated > totalboards;
  71. if (flag7)
  72. {
  73. break;
  74. }
  75. bool flag8 = deep >= maxdeep;
  76. if (flag8)
  77. {
  78. break;
  79. }
  80. }
  81. this.posmoves.Add(bestold);
  82. foreach (Playfield p2 in this.posmoves)
  83. {
  84. bool flag9 = !p2.complete;
  85. if (flag9)
  86. {
  87. p2.endTurn();
  88. bool flag10 = !isLethalCheck;
  89. if (flag10)
  90. {
  91. this.startEnemyTurnSim(p2, this.simulateSecondTurn, false, playaround, playaroundprob, playaroundprob2);
  92. }
  93. }
  94. }
  95. bool flag11 = this.posmoves.Count >= ;
  96. float result;
  97. if (flag11)
  98. {
  99. this.posmoves.Sort((Playfield a, Playfield b) => this.botBase.getPlayfieldValue(b).CompareTo(this.botBase.getPlayfieldValue(a)));
  100. Playfield bestplay = this.posmoves[];
  101. float bestval = this.botBase.getPlayfieldValue(bestplay);
  102. int pcount = this.posmoves.Count;
  103. for (int i = ; i < pcount; i++)
  104. {
  105. float val = this.botBase.getPlayfieldValue(this.posmoves[i]);
  106. bool flag12 = bestval > val;
  107. if (flag12)
  108. {
  109. break;
  110. }
  111. bool flag13 = bestplay.playactions.Count <= this.posmoves[i].playactions.Count;
  112. if (!flag13)
  113. {
  114. bestplay = this.posmoves[i];
  115. bestval = val;
  116. }
  117. }
  118. this.bestmove = bestplay.getNextAction();
  119. this.bestmoveValue = bestval;
  120. this.bestboard = new Playfield(bestplay);
  121. result = bestval;
  122. }
  123. else
  124. {
  125. this.bestmove = null;
  126. this.bestmoveValue = -100000f;
  127. this.bestboard = playf;
  128. result = -10000f;
  129. }
  130. return result;
  131. }

用单元测试来调试SilverFish AI的更多相关文章

  1. HearthBuddy Ai 调试实战2 在使用海巨人的时候,少召唤了一个图腾(费用是对的)

    问题 游戏面板 8是青玉之爪13是海巨人17是恐狼前锋 64是萨满 66是圣骑士63,99,46,是微型木乃伊[其中99和46都是2血3攻,63是2血1攻]57是鱼人木乃伊 微型木乃伊 "L ...

  2. HearthBuddy Ai调试实战1-->出牌的时候,少召唤了图腾就结束回合

    期望通过ai的调试,来搞明白出牌的逻辑. 55是投火无面者63是恐狼前锋34是风怒36是自动漩涡打击装置13是空灵召唤者, "LocStringZhCn": "<b ...

  3. 【vue】在VS Code中调试Jest单元测试

    在VS Code中调试Jest单元测试 添加调试任务 打开 vscode launch.json 文件,在 configurations 内加入下面代码 "configurations&qu ...

  4. HearthBuddy炉石兄弟 如何调试ai

    Sepefeets's update to botmaker's Silverfish AI This AI is a Custom Class for Hearthranger and Hearth ...

  5. ASP.NET 系列:单元测试

    单元测试可以有效的可以在编码.设计.调试到重构等多方面显著提升我们的工作效率和质量.github上可供参考和学习的各种开源项目众多,NopCommerce.Orchard等以及微软的asp.net m ...

  6. Unity 单元测试(NUnit,UnityTestTools)

    在软件开发中单元测试是非常重要的一个环节, =.=盘子脸去了几家公司都没有单元测试这个概念. 我们的系统虽然从代码看上是分离的, 在多数情况下都需要依赖于其他模块来运行.(单元测试部分内容教我解决这个 ...

  7. 使用 xUnit 编写 ASP.NET Core 单元测试

    还记得 .NET Framework 的 ASP.NET WebForm 吗?那个年代如果要在 Web 层做单元测试简直就是灾难啊..NET Core 吸取教训,在设计上考虑到了可测试性,就连 ASP ...

  8. 学习笔记之Python调试 - pdb

    python调试神器——pdb - 软谋python https://mp.weixin.qq.com/s/w3Xw8I_zh7MFq2dx5kdQXw 优秀开发者必备技能包:Python调试器 - ...

  9. .net持续集成单元测试篇之单元测试简介以及在visual studio中配置Nunit使用环境

    系列目录 单元测试及测试驱动开发简介 什么是单元测试 单元测试是一段自动化的代码,这段代码调用被测试的工作单元,之后对这个单元的单个最终结果的某些假设进行检验.单元测试几乎都是用单元测试框架编写的.单 ...

随机推荐

  1. Newtonsoft.Json基本用法

    1.将一个 Object 序列化成 JSON: DataSet detail = sqlDB.GetDataSet(string.Format("select * from student ...

  2. 基于Groovy编写Ngrinder脚本常用方法

    1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStringUtils.randomNumeric(lengt ...

  3. oracle数据库(实例)的导出与导入

    Oracle数据导入导出常用两种方式: 1.是通过plsql-->tool-->export/import进行dmp文件的导入与导出: 2.使用命令imp/exp执行oracle数据导入与 ...

  4. 安卓开发之获取SD卡空间数据

    package com.lidaochen.getsdcardspace; import android.os.Environment; import android.support.v7.app.A ...

  5. 介绍两个好玩的和Github相关的Chrome扩展

    1. Octotree 默认的github网页里的代码显示没有我们在IDE里看到的直观,即代码文件所在的文件夹无法以树形层级结构显示在屏幕左边. 安装Octotree之后: 方便多了. 2. Isom ...

  6. Spring的启动流程

    spring的启动是建筑在servlet容器之上的,所有web工程的初始位置就是web.xml,它配置了servlet的上下文(context)和监听器(Listener),下面就来看看web.xml ...

  7. 2019年C题 视觉情报信息分析

    2019 年第十六届中国研究生数学建模竞赛C 题 任务1中 图三:图3 中拍照者距离地面的高度 目录: 0.试题分析: 1.构建摄像机模型 2.摄像机参数假定 3.像平面坐标计算 4.图像标定及数值测 ...

  8. sed原理及sed命令格式 ,缓存区,模式空间

    4.1            Sed工作原理 sed是一个非交互式的流编辑器.所谓非交互式,是指使用sed只能在命令行下输入编辑命令来编辑文本,然后在屏幕上查看输出:而所谓流编辑器,是指sed每次只从 ...

  9. Python网络编程常用代码

    服务器端代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # -*- coding: cp936 -*- ...

  10. Java web中文乱码

    1.设置工程的编码方式 window-preferences-general-workspace 改成uef-8 2.设置html的编码方式 <meta http-equiv="Con ...