当前位置:编程学习 > C#/ASP.NET >>

A*寻路算法基于C#实现

玩过即时战略,RPG等类型的游戏的朋友一定会知道,当我们用鼠标选取某些单位并命令其到达地图上确定的位置时,这些单位总是可以自动的选择最短的路径到达。这个时候我们就会联想到大名鼎鼎的A*寻路算法,下文简略介绍算法实现原理,并附上C#实现方法。

    算法原理请见:http://data.gameres.com/message.asp?TopicID=25439

 

\代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication2
{
class Program
{





static void Main(string[] args)
{



test mytest = new test();

//定义出发位置
Point pa = new Point();
pa.x = 1;
pa.y = 1;

//定义目的地
Point pb = new Point();
pb.x = 8;
pb.y = 8;

mytest.FindWay(pa, pb);

mytest.PrintMap();
Console.ReadLine();
}
}
class test
{

//数组用1表示可通过,0表示障碍物
byte[,] R = new byte[10, 10] {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{ 1,
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,