internal static void Debuff(DragonAStarNode node) { node.KnightAttack -= node.TestCase.Debuff; if (node.KnightAttack < 0) { node.KnightAttack = 0; } node.PreviousAction = "Debuff"; }
static void Copy(DragonAStarNode source, DragonAStarNode dest) { AStarNode.Copy(source, dest); dest.DragonHealth = source.DragonHealth; dest.DragonAttack = source.DragonAttack; dest.KnightHealth = source.KnightHealth; dest.KnightAttack = source.KnightAttack; dest.TestCase = source.TestCase; }
internal DragonAStarNode MakeNeighbor(Action <DragonAStarNode> Action) { DragonAStarNode neighbor = new DragonAStarNode(TestCase); Copy(this, neighbor); neighbor.PreviousNode = this; Action(neighbor); neighbor.DragonHealth -= neighbor.KnightAttack; if (neighbor.IsLosingState()) { return(null); } neighbor.ComputeDistances(); return(neighbor); }
public override IEnumerable <AStarNode> GetNeighbors() { DragonAStarNode node = this; if (node.DragonHealth <= 0 || node.KnightHealth <= 0) { yield break; } //if (node.KnightAttack == 0) { DragonAStarNode n1 = node.MakeNeighbor(DragonAStarNode.Attack); if (n1 != null) { yield return(n1); } //} if (TestCase.Buff > 0) { DragonAStarNode n2 = node.MakeNeighbor(DragonAStarNode.Buff); if (n2 != null) { yield return(n2); } } DragonAStarNode n3 = node.MakeNeighbor(DragonAStarNode.Cure); if (n3 != null) { yield return(n3); } if (TestCase.Debuff > 0 && node.KnightAttack > 0) { DragonAStarNode n4 = node.MakeNeighbor(DragonAStarNode.Debuff); if (n4 != null) { yield return(n4); } } }
protected override string Solve(ITestCase testCase2) { TestCase testCase = (TestCase)testCase2; AStar algorithm = new AStar(); DragonAStarNode startState = new DragonAStarNode(testCase); List <AStarNode> path = algorithm.FindShortestPath(startState); if (path == null) { return("IMPOSSIBLE"); } else { //Console.WriteLine("\n=============================\n"); foreach (AStarNode node2 in path) { DragonAStarNode node = (DragonAStarNode)node2; node.Print(); Console.WriteLine(); } return((path.Count - 1).ToString()); } }
internal static void Cure(DragonAStarNode node) { node.DragonHealth = node.TestCase.DragonHealth; node.PreviousAction = "Cure"; }
internal static void Buff(DragonAStarNode node) { node.DragonAttack += node.TestCase.Buff; node.PreviousAction = "Buff"; }
internal static void Attack(DragonAStarNode node) { node.KnightHealth -= node.DragonAttack; node.PreviousAction = "Attack"; }