用单元测试来调试SilverFish AI
- [TestFixture]
- public class AiTest
- {
- [Test]
- public void Test()
- {
- Settings.Instance.LogFolderPath = @"C:\repository\GitHub\ChuckLu\Test\HearthbuddyRelease\Logs";
- Settings.Instance.DataFolderPath =
- @"C:\repository\GitHub\ChuckLu\Test\HearthbuddyRelease\Routines\DefaultRoutine\SilverFish\Data\";
- if (Hrtprozis.Instance.settings == null)
- {
- Hrtprozis.Instance.setInstances();
- ComboBreaker.Instance.setInstances();
- PenalityManager.Instance.setInstances();
- }
- //-mode: 0-all, 1-lethalcheck, 2-normal
- Ai ai = Ai.Instance;
- ai.autoTester(true, string.Empty, );
- }
- }
- if (mode == || mode == )
- {
- doallmoves(false, true);
- calcTime = (DateTime.Now - strt).TotalSeconds;
- help.logg("calculated " + calcTime);
- retval.Add(calcTime);
- }
- if (Settings.Instance.berserkIfCanFinishNextTour > && bestmoveValue > )
- {
- }
- else if (bestmoveValue < )
- {
- // normal
- if (mode == || mode == )
- {
- posmoves.Clear();
- pMain = new Playfield();
- pMain.print = printstuff;
- posmoves.Add(pMain);
- strt = DateTime.Now;
- doallmoves(false, false);
- calcTime = (DateTime.Now - strt).TotalSeconds;
- help.logg("calculated " + calcTime);
- retval.Add(calcTime);
- }
- }
发现格雷迈恩的效果,不知道怎么触发的,需要直接运行exe调试
在 routine.Tick();设置断点,F11之后会加载DefaultRoutine.dll
- // Triton.Bot.RoutineManager
- // Token: 0x060011C9 RID: 4553 RVA: 0x000B65BC File Offset: 0x000B47BC
- public static void Tick(IRoutine routine)
- {
- RoutineManager.smethod_0(routine, RoutineManager.routineEvent_2);
- try
- {
- routine.Tick();
- }
- catch (Exception exception)
- {
- RoutineManager.ilog_0.Error("Exception during routine Tick.", exception);
- }
- RoutineManager.smethod_0(routine, RoutineManager.routineEvent_3);
- }
- // HREngine.Bots.Ai
- // Token: 0x06000061 RID: 97 RVA: 0x00009000 File Offset: 0x00007200
- private void doallmoves(bool test, bool isLethalCheck)
- {
- foreach (EnemyTurnSimulator ets in this.enemyTurnSim)
- {
- ets.setMaxwide(true);
- }
- foreach (EnemyTurnSimulator ets2 in this.enemySecondTurnSim)
- {
- ets2.setMaxwide(true);
- }
- this.posmoves[].isLethalCheck = isLethalCheck;
- this.mainTurnSimulator.doallmoves(this.posmoves[]);
- this.bestplay = this.mainTurnSimulator.bestboard;
- float bestval = this.mainTurnSimulator.bestmoveValue;
- this.help.loggonoff(true);
- this.help.logg("-------------------------------------");
- bool flag = this.bestplay.ruleWeight != ;
- if (flag)
- {
- this.help.logg("ruleWeight " + this.bestplay.ruleWeight * -);
- }
- bool flag2 = this.settings.printRules > ;
- if (flag2)
- {
- string[] rulesStr = this.bestplay.rulesUsed.Split(new char[]
- {
- '@'
- });
- foreach (string rs in rulesStr)
- {
- bool flag3 = rs == "";
- if (!flag3)
- {
- this.help.logg("rule: " + rs);
- }
- }
- }
- this.help.logg("value of best board " + bestval);
- this.bestActions.Clear();
- this.bestmove = null;
- ActionNormalizer an = new ActionNormalizer();
- bool flag4 = this.settings.adjustActions > ;
- if (flag4)
- {
- an.adjustActions(this.bestplay, isLethalCheck);
- }
- foreach (Action a in this.bestplay.playactions)
- {
- this.bestActions.Add(new Action(a));
- a.print(false);
- }
- bool flag5 = this.bestActions.Count >= ;
- if (flag5)
- {
- this.bestmove = this.bestActions[];
- this.bestActions.RemoveAt();
- }
- this.bestmoveValue = bestval;
- bool flag6 = this.bestmove != null && this.bestmove.actionType > actionEnum.endturn;
- if (flag6)
- {
- this.nextMoveGuess = new Playfield();
- this.nextMoveGuess.doAction(this.bestmove);
- }
- else
- {
- this.nextMoveGuess.mana = -;
- }
- if (isLethalCheck)
- {
- this.lethalMissing = this.bestplay.enemyHero.armor + this.bestplay.enemyHero.Hp;
- this.help.logg("missing dmg to lethal " + this.lethalMissing);
- }
- }
- // HREngine.Bots.MiniSimulator
- // Token: 0x060000E0 RID: 224 RVA: 0x00018480 File Offset: 0x00016680
- public float doallmoves(Playfield playf)
- {
- this.print = playf.print;
- this.isLethalCheck = playf.isLethalCheck;
- this.enoughCalculations = false;
- this.botBase = Ai.Instance.botBase;
- this.posmoves.Clear();
- this.twoturnfields.Clear();
- this.addToPosmoves(playf);
- bool havedonesomething = true;
- List<Playfield> temp = new List<Playfield>();
- int deep = ;
- this.calculated = ;
- Playfield bestold = null;
- this.bestoldval = -2E+07f;
- while (havedonesomething)
- {
- bool flag = this.printNormalstuff;
- if (flag)
- {
- Helpfunctions.Instance.logg("ailoop");
- }
- GC.Collect();
- temp.Clear();
- temp.AddRange(this.posmoves);
- this.posmoves.Clear();
- havedonesomething = false;
- this.threadnumberGlobal = ;
- bool flag2 = this.print;
- if (flag2)
- {
- this.startEnemyTurnSimThread(temp, , temp.Count);
- }
- else
- {
- Parallel.ForEach<Tuple<int, int>>(Partitioner.Create(, temp.Count), delegate(Tuple<int, int> range)
- {
- this.startEnemyTurnSimThread(temp, range.Item1, range.Item2);
- });
- }
- foreach (Playfield p in temp)
- {
- bool flag3 = this.totalboards > ;
- if (flag3)
- {
- this.calculated += p.nextPlayfields.Count;
- }
- bool flag4 = this.calculated <= this.totalboards;
- if (flag4)
- {
- this.posmoves.AddRange(p.nextPlayfields);
- p.nextPlayfields.Clear();
- }
- float pVal = this.botBase.getPlayfieldValue(p);
- bool flag5 = pVal > this.bestoldval;
- if (flag5)
- {
- this.bestoldval = pVal;
- bestold = p;
- this.bestoldDuplicates.Clear();
- }
- else
- {
- bool flag6 = pVal == this.bestoldval;
- if (flag6)
- {
- this.bestoldDuplicates.Add(p);
- }
- }
- }
- bool flag7 = this.isLethalCheck && this.bestoldval >= 10000f;
- if (flag7)
- {
- this.posmoves.Clear();
- }
- bool flag8 = this.posmoves.Count > ;
- if (flag8)
- {
- havedonesomething = true;
- }
- bool flag9 = this.printNormalstuff;
- if (flag9)
- {
- int donec = ;
- foreach (Playfield p2 in this.posmoves)
- {
- bool complete = p2.complete;
- if (complete)
- {
- donec++;
- }
- }
- Helpfunctions.Instance.logg(string.Concat(new object[]
- {
- "deep ",
- deep,
- " len ",
- this.posmoves.Count,
- " dones ",
- donec
- }));
- }
- this.cuttingposibilities(this.isLethalCheck);
- bool flag10 = this.printNormalstuff;
- if (flag10)
- {
- Helpfunctions.Instance.logg("cut to len " + this.posmoves.Count);
- }
- deep++;
- temp.Clear();
- bool flag11 = this.calculated > this.totalboards;
- if (flag11)
- {
- this.enoughCalculations = true;
- }
- bool flag12 = deep >= this.maxdeep;
- if (flag12)
- {
- this.enoughCalculations = true;
- }
- }
- bool flag13 = this.dirtyTwoTurnSim > && !this.twoturnfields.Contains(bestold);
- if (flag13)
- {
- this.twoturnfields.Add(bestold);
- }
- this.posmoves.Clear();
- this.posmoves.Add(bestold);
- this.posmoves.AddRange(this.bestoldDuplicates);
- bool flag14 = !this.isLethalCheck && this.bestoldval < 10000f;
- if (flag14)
- {
- this.doDirtyTwoTurnsim();
- }
- bool flag15 = this.posmoves.Count >= ;
- float result;
- if (flag15)
- {
- this.posmoves.Sort((Playfield a, Playfield b) => this.botBase.getPlayfieldValue(b).CompareTo(this.botBase.getPlayfieldValue(a)));
- Playfield bestplay = this.posmoves[];
- float bestval = this.botBase.getPlayfieldValue(bestplay);
- int pcount = this.posmoves.Count;
- for (int i = ; i < pcount; i++)
- {
- float val = this.botBase.getPlayfieldValue(this.posmoves[i]);
- bool flag16 = bestval > val;
- if (flag16)
- {
- break;
- }
- bool flag17 = this.posmoves[i].cardsPlayedThisTurn > bestplay.cardsPlayedThisTurn;
- if (!flag17)
- {
- bool flag18 = this.posmoves[i].cardsPlayedThisTurn == bestplay.cardsPlayedThisTurn;
- if (flag18)
- {
- bool flag19 = bestplay.optionsPlayedThisTurn > this.posmoves[i].optionsPlayedThisTurn;
- if (flag19)
- {
- goto IL_57A;
- }
- bool flag20 = bestplay.optionsPlayedThisTurn == this.posmoves[i].optionsPlayedThisTurn && bestplay.enemyHero.Hp <= this.posmoves[i].enemyHero.Hp;
- if (flag20)
- {
- goto IL_57A;
- }
- }
- bestplay = this.posmoves[i];
- bestval = val;
- }
- IL_57A:;
- }
- this.bestmove = bestplay.getNextAction();
- this.bestmoveValue = bestval;
- this.bestboard = new Playfield(bestplay);
- this.bestboard.guessingHeroHP = bestplay.guessingHeroHP;
- this.bestboard.value = bestplay.value;
- this.bestboard.hashcode = bestplay.hashcode;
- this.bestoldDuplicates.Clear();
- result = bestval;
- }
- else
- {
- this.bestmove = null;
- this.bestmoveValue = -100000f;
- this.bestboard = playf;
- result = -10000f;
- }
- return result;
- }
- // HREngine.Bots.MiniSimulatorNextTurn
- // Token: 0x060000EE RID: 238 RVA: 0x00019890 File Offset: 0x00017A90
- public float doallmoves(Playfield playf, bool print = false)
- {
- bool isLethalCheck = playf.isLethalCheck;
- int totalboards = Settings.Instance.nextTurnTotalBoards;
- int maxwide = Settings.Instance.nextTurnMaxWide;
- int maxdeep = Settings.Instance.nextTurnDeep;
- bool playaround = Settings.Instance.playaround;
- int playaroundprob = Settings.Instance.playaroundprob;
- int playaroundprob2 = Settings.Instance.playaroundprob2;
- this.botBase = Ai.Instance.botBase;
- this.posmoves.Clear();
- this.posmoves.Add(new Playfield(playf));
- bool havedonesomething = true;
- List<Playfield> temp = new List<Playfield>();
- int deep = ;
- this.calculated = ;
- Playfield bestold = null;
- float bestoldval = -2E+07f;
- while (havedonesomething)
- {
- temp.Clear();
- temp.AddRange(this.posmoves);
- havedonesomething = false;
- foreach (Playfield p in temp)
- {
- bool flag = p.complete || p.ownHero.Hp <= ;
- if (!flag)
- {
- List<Action> actions = this.movegen.getMoveList(p, this.usePenalityManager, this.useCutingTargets, true);
- foreach (Action a2 in actions)
- {
- havedonesomething = true;
- Playfield pf = new Playfield(p);
- pf.doAction(a2);
- bool flag2 = pf.ownHero.Hp > ;
- if (flag2)
- {
- this.posmoves.Add(pf);
- }
- bool flag3 = totalboards > ;
- if (flag3)
- {
- this.calculated++;
- }
- }
- p.endTurn();
- bool flag4 = !isLethalCheck;
- if (flag4)
- {
- this.startEnemyTurnSim(p, this.simulateSecondTurn, false, playaround, playaroundprob, playaroundprob2);
- }
- bool flag5 = this.botBase.getPlayfieldValue(p) > bestoldval;
- if (flag5)
- {
- bestoldval = this.botBase.getPlayfieldValue(p);
- bestold = p;
- }
- this.posmoves.Remove(p);
- bool flag6 = this.calculated > totalboards;
- if (flag6)
- {
- break;
- }
- }
- }
- this.cuttingposibilities(maxwide);
- deep++;
- bool flag7 = this.calculated > totalboards;
- if (flag7)
- {
- break;
- }
- bool flag8 = deep >= maxdeep;
- if (flag8)
- {
- break;
- }
- }
- this.posmoves.Add(bestold);
- foreach (Playfield p2 in this.posmoves)
- {
- bool flag9 = !p2.complete;
- if (flag9)
- {
- p2.endTurn();
- bool flag10 = !isLethalCheck;
- if (flag10)
- {
- this.startEnemyTurnSim(p2, this.simulateSecondTurn, false, playaround, playaroundprob, playaroundprob2);
- }
- }
- }
- bool flag11 = this.posmoves.Count >= ;
- float result;
- if (flag11)
- {
- this.posmoves.Sort((Playfield a, Playfield b) => this.botBase.getPlayfieldValue(b).CompareTo(this.botBase.getPlayfieldValue(a)));
- Playfield bestplay = this.posmoves[];
- float bestval = this.botBase.getPlayfieldValue(bestplay);
- int pcount = this.posmoves.Count;
- for (int i = ; i < pcount; i++)
- {
- float val = this.botBase.getPlayfieldValue(this.posmoves[i]);
- bool flag12 = bestval > val;
- if (flag12)
- {
- break;
- }
- bool flag13 = bestplay.playactions.Count <= this.posmoves[i].playactions.Count;
- if (!flag13)
- {
- bestplay = this.posmoves[i];
- bestval = val;
- }
- }
- this.bestmove = bestplay.getNextAction();
- this.bestmoveValue = bestval;
- this.bestboard = new Playfield(bestplay);
- result = bestval;
- }
- else
- {
- this.bestmove = null;
- this.bestmoveValue = -100000f;
- this.bestboard = playf;
- result = -10000f;
- }
- return result;
- }
用单元测试来调试SilverFish AI的更多相关文章
- HearthBuddy Ai 调试实战2 在使用海巨人的时候,少召唤了一个图腾(费用是对的)
问题 游戏面板 8是青玉之爪13是海巨人17是恐狼前锋 64是萨满 66是圣骑士63,99,46,是微型木乃伊[其中99和46都是2血3攻,63是2血1攻]57是鱼人木乃伊 微型木乃伊 "L ...
- HearthBuddy Ai调试实战1-->出牌的时候,少召唤了图腾就结束回合
期望通过ai的调试,来搞明白出牌的逻辑. 55是投火无面者63是恐狼前锋34是风怒36是自动漩涡打击装置13是空灵召唤者, "LocStringZhCn": "<b ...
- 【vue】在VS Code中调试Jest单元测试
在VS Code中调试Jest单元测试 添加调试任务 打开 vscode launch.json 文件,在 configurations 内加入下面代码 "configurations&qu ...
- HearthBuddy炉石兄弟 如何调试ai
Sepefeets's update to botmaker's Silverfish AI This AI is a Custom Class for Hearthranger and Hearth ...
- ASP.NET 系列:单元测试
单元测试可以有效的可以在编码.设计.调试到重构等多方面显著提升我们的工作效率和质量.github上可供参考和学习的各种开源项目众多,NopCommerce.Orchard等以及微软的asp.net m ...
- Unity 单元测试(NUnit,UnityTestTools)
在软件开发中单元测试是非常重要的一个环节, =.=盘子脸去了几家公司都没有单元测试这个概念. 我们的系统虽然从代码看上是分离的, 在多数情况下都需要依赖于其他模块来运行.(单元测试部分内容教我解决这个 ...
- 使用 xUnit 编写 ASP.NET Core 单元测试
还记得 .NET Framework 的 ASP.NET WebForm 吗?那个年代如果要在 Web 层做单元测试简直就是灾难啊..NET Core 吸取教训,在设计上考虑到了可测试性,就连 ASP ...
- 学习笔记之Python调试 - pdb
python调试神器——pdb - 软谋python https://mp.weixin.qq.com/s/w3Xw8I_zh7MFq2dx5kdQXw 优秀开发者必备技能包:Python调试器 - ...
- .net持续集成单元测试篇之单元测试简介以及在visual studio中配置Nunit使用环境
系列目录 单元测试及测试驱动开发简介 什么是单元测试 单元测试是一段自动化的代码,这段代码调用被测试的工作单元,之后对这个单元的单个最终结果的某些假设进行检验.单元测试几乎都是用单元测试框架编写的.单 ...
随机推荐
- Newtonsoft.Json基本用法
1.将一个 Object 序列化成 JSON: DataSet detail = sqlDB.GetDataSet(string.Format("select * from student ...
- 基于Groovy编写Ngrinder脚本常用方法
1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStringUtils.randomNumeric(lengt ...
- oracle数据库(实例)的导出与导入
Oracle数据导入导出常用两种方式: 1.是通过plsql-->tool-->export/import进行dmp文件的导入与导出: 2.使用命令imp/exp执行oracle数据导入与 ...
- 安卓开发之获取SD卡空间数据
package com.lidaochen.getsdcardspace; import android.os.Environment; import android.support.v7.app.A ...
- 介绍两个好玩的和Github相关的Chrome扩展
1. Octotree 默认的github网页里的代码显示没有我们在IDE里看到的直观,即代码文件所在的文件夹无法以树形层级结构显示在屏幕左边. 安装Octotree之后: 方便多了. 2. Isom ...
- Spring的启动流程
spring的启动是建筑在servlet容器之上的,所有web工程的初始位置就是web.xml,它配置了servlet的上下文(context)和监听器(Listener),下面就来看看web.xml ...
- 2019年C题 视觉情报信息分析
2019 年第十六届中国研究生数学建模竞赛C 题 任务1中 图三:图3 中拍照者距离地面的高度 目录: 0.试题分析: 1.构建摄像机模型 2.摄像机参数假定 3.像平面坐标计算 4.图像标定及数值测 ...
- sed原理及sed命令格式 ,缓存区,模式空间
4.1 Sed工作原理 sed是一个非交互式的流编辑器.所谓非交互式,是指使用sed只能在命令行下输入编辑命令来编辑文本,然后在屏幕上查看输出:而所谓流编辑器,是指sed每次只从 ...
- 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 -*- ...
- Java web中文乱码
1.设置工程的编码方式 window-preferences-general-workspace 改成uef-8 2.设置html的编码方式 <meta http-equiv="Con ...