The perfect game room for goblins--ai, A * algorithm, inspiring factor chapter

Source: Internet
Author: User
Tags abs

//================================================================
//
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.