【发布时间】:2015-06-24 15:31:43
【问题描述】:
我正在为我的回合制策略游戏创建 AI,我的想法是像国际象棋中那样有图块,而这些图块可以包含单位。
在我的课堂上,我保留了一个敌方单位列表,并希望根据他们的“威胁等级”对它们进行排序。
/// <summary>
/// Enemy unit
/// </summary>
public Unit Unit { get; private set; }
/// <summary>
/// Distance towards other side of the board / victory
/// </summary>
public float Distance { get; private set; }
/// <summary>
/// Allied Unit covering the lane
/// </summary>
public Unit CoveringUnit { get; set; }
但是我的 if 语句有点吃力:
public int CompareTo(AiEnemyUnit pOther)
{
if (CoveringUnit == null && pOther.CoveringUnit == null)
return Distance.CompareTo(pOther.Distance);
if (CoveringUnit != null && pOther.CoveringUnit == null)
return 1;
if (CoveringUnit == null && pOther.CoveringUnit != null)
return -1;
// coverunits are both not null
Unit lvWinningUnit = GameManager.Instance.WhoWouldWin(this.Unit, this.CoveringUnit);
Unit lvWinningOtherUnit = GameManager.Instance.WhoWouldWin(pOther.Unit, pOther.CoveringUnit);
if ((lvWinningUnit == null && lvWinningOtherUnit == null) ||
lvWinningUnit == this.Unit && lvWinningOtherUnit == pOther.Unit)
return Distance.CompareTo(pOther.Distance);
if (lvWinningUnit == this.CoveringUnit && lvWinningOtherUnit != pOther.CoveringUnit)
return -1;
if (lvWinningUnit != this.CoveringUnit && lvWinningOtherUnit == pOther.CoveringUnit)
return 1;
Debug.Log("CompareTo AiEnemyUnit couldn't compare??");
return Distance.CompareTo(pOther.Distance);
}
CoveringUnit是已经覆盖敌方单位所在车道的单位(应该是一个列表,但我们),所以如果这个对象有一个CoverUnit 和 Other object 没有,那么 Other 对象应该具有优先权,因为它需要生成一个单位来覆盖该车道。
它一直给我 Debug 消息,但我无法使用 Unity 进行调试。
所以我的问题是:
是否有工具或在线网站可以帮助处理 if 语句以查看我缺少的内容?
提前致谢。
EDIT1:@paqogomez 建议改写:
我的 CompareTo 函数中缺少什么?
【问题讨论】:
-
调试信息是什么?此外,索取工具或异地资源对 SO 来说是无关紧要的。请改写您的问题,以使其更多地指向如何解决您的困境。
-
@paqogomez 就像格兰特温尼所说的那样,它确实是我代码的倒数第二行。而且我不介意改写我的问题,但这基本上是我要求修复我的 CompareTo 方法,因为我太密集而无法自己完成,而且该工具或异地资源将来会很有用。跨度>
-
为什么不能调试? Mono 和 VisualStudio 都能够调试你的 c# 代码,尽管对于 VS 你需要插件 (unityvs.com)
-
我确实安装了 UnityVs,它可以在我的笔记本电脑上运行,但由于某种原因不能在我的家用电脑上运行。我会尝试重新安装看看是否有帮助。
-
应用恐怖调试器原理:在每一行代码之后Debug.Log,打印出ifs中用到的对象/值。就像 aradil 的回答一样。
标签: c# debugging if-statement helper