资源简介
详细描述见我的一篇博文
http://blog.csdn.net/davied9/article/details/51921723

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
/// 本程序主要的完成目标为:
/// 导入地图数据(2维矩阵,每个元素表示该位置的类型)
/// 0 可通行 1 墙面 2 起始点 3 终止点
/// 输出寻址结果(估价结果、寻址结果)
namespace PathSearch
{
class Program
{
///
/// 玩成地图寻址功能(A*逆向搜索),作为结果备份,所以完整抄录
///
///
static void Main(string[] args) // string 中仅含有一个有效参数,就是地图文件的文件名
{
Map mapRead;
if (1 == args.Length)
mapRead = new Map(args[0]);
else
return;
if(mapRead.empty)
{
System.Diagnostics.Debug.WriteLine(“PathSearch.Program.Main >>> File read FAILED!!!“);
return;
}
Coord2 beginNode = new Coord2(1 1);
Coord2 endNode = new Coord2(5 7);
if (!(mapRead.IsInMap(beginNode) && mapRead.IsInMap(endNode)))
{
System.Diagnostics.Debug.WriteLine(“PathSearch.Program.Main >>> Map-file is not available!!!“);
return;
}
Coord2 sizeMap = new Coord2(mapRead.Size());
List openList = new List();
MapData cost = new MapData(sizeMap costInitValue);
Coord2[] NSOffsets = new Coord2[8]
{
new Coord2(-1-1)new Coord2( 0-1)new Coord2( 1-1)
new Coord2(-1 0) new Coord2( 1 0)
new Coord2(-1 1)new Coord2( 0 1)new Coord2( 1 1)
};
int[] NSPrice = new int[8]
{
141014
10 10
141014
};
Coord2 currentNode = new Coord2(endNode);
cost[currentNode] = 0;
Coord2 checkNode = new Coord2();
openList.Add(currentNode);// 注意区别
int nodePrice = 0;
Coord2 minSpaceNode = new Coord2();
int minSpaceCost = 0; // 节点空间中估价最小的节点
while(0 != openList.Count)
{
openList.Remove(currentNode);
for(int ix_Space = 0; ix_Space < 8; ++ix_Space)
{
checkNode = currentNode + NSOffsets[ix_Space];
if (!mapRead.IsInMap(checkNode)) continue;
if (costInitValue != cost[checkNode] || mapRead.IsObs(checkNode)) continue;
nodePrice = NSPrice[ix_Space];
cost[checkNode] = cost[currentNode] + nodePrice;
if (beginNode == checkNode) goto search_tag;
openList.Add(new Coord2(checkNode));// 注意区别
}
minSpaceNode = openList.ElementAt(0);
minSpaceCost = cost[minSpaceNode];
foreach(Coord2 minCheckNode in openList)
{
if( cost[minCheckNode] < minSpaceCost)
{
minSpaceNode = minCheckNode;
minSpaceCost = cost[minSpaceNode];
}
}
currentNode = minSpaceNode;
}
search_tag:
if (costInitValue == cost[beginNode])
{
System.Diagnostics.Debug.WriteLine(“PathSearch.Program.Main >>> Path NOT found!!!“);
return;
}
List pathList = new List();
currentNode = new Coord2(beginNode);
while (endNode != currentNode)
{
pathList.Add(new Coord2(currentNode));
minSpaceNode = currentNode;
minSpaceCost = cost[currentNode];
foreach(Coord2 offset in NSOffsets)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 193 2016-07-16 13:24 PathSearchPackages\Map.txt
文件 8555 2016-07-16 13:23 PathSearchPackages\Program.cs
文件 4606146 2016-07-16 11:40 PathSearchPackages\whole.jpg
目录 0 2016-07-16 13:25 PathSearchPackages
----------- --------- ---------- ----- ----
4614894 4
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论