//================================================================
//
Copyright (C) Team Saluka
All Rights Reserved
//
Author: Goblin Balous
//
Summary: Here are 3 heuristic factors that determine the accuracy of the search and CPU overhead
//
//================================================================
Using System;
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
Namespace Saruka
{
<summary>
Heuristic factors
</summary>
Public abstract class heuristics
{
public abstract float Getheuristics (Navnode startnode, Navnode TargetNode);
}
<summary>
Manhattan Distance
</summary>
public class Manhattandistance:heuristics
{
public override float Getheuristics (Navnode startnode, Navnode TargetNode)
{
Return Mathf.abs (STARTNODE.GRIDX-TARGETNODE.GRIDX) + mathf.abs (startnode.gridy-targetnode.gridy);
}
}
<summary>
Euclidean distance
</summary>
public class Euclideandistance:heuristics
{
public override float Getheuristics (Navnode startnode, Navnode TargetNode)
{
int disx = STARTNODE.GRIDX-TARGETNODE.GRIDX;
int disy = Startnode.gridy-targetnode.gridy;
Return mathf.sqrt (DISX * disx + disy * disy);
}
}
<summary>
Happo Distance
</summary>
public class Eightdirectionsdistance:heuristics
{
public override float Getheuristics (Navnode startnode, Navnode TargetNode)
{
int disx = Mathf.abs (STARTNODE.GRIDX-TARGETNODE.GRIDX);
int disy = Mathf.abs (Startnode.gridy-targetnode.gridy);
if (Disx > Disy) return 1.414213562f * Disy + (Disx-disy);
Return 1.414213562f * DISX + (DISY-DISX);
}
}
}
The perfect game room for goblins--ai, A * algorithm, inspiring factor chapter