資源簡(jiǎn)介
在實(shí)例中把尋路算法寫成了一個(gè)專門的類。使用非常方便。效率很高。可以直接顯示路徑看結(jié)果,也可以讓它一步步顯示出搜索的過(guò)程。鼠標(biāo)在界面上畫出一些黑點(diǎn)可以作為障礙,來(lái)考驗(yàn)它的能力,呵呵

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?AI
{
????///?
????///?用于構(gòu)成把需要尋路的地圖抽像成地圖副本(StepNode類型的二維數(shù)組)
????///?
????public?class?StepNode
????{
????????public?int?RowIndex;
????????public?int?ColIndex;
????????public?StepNode?FartherNode;
????????public?int?F
????????{
????????????get?{?return?G?+?H;?}
????????}
????????public?int?G;
????????public?int?H;
????????public?int?State;
????}
????public?delegate?void?SearchPathNotifactionEventHandle(int?RowIndexint?ColunmIndex);
????public?class?AIPath
????{
????????public?bool?IsOpenNotification?=?false;
????????public?SearchPathNotifactionEventHandle?StepReachEvent;
????????public?SearchPathNotifactionEventHandle?StepWantToBlockCollectEvent;
????????StepNode?StartNode?=?null;
????????StepNode?EndNode?=?null;
????????public?List?OpenNode?=?new?List();
????????public?List?FootPath?=?new?List();
????????int?RowCount;
????????int?ColCount;
????????public?StepNode[]?SubMap;
????????///?
????????///?創(chuàng)建一個(gè)指定(像素或“格式”等)行列數(shù)量智能搜索程序(注意行與列與圖片的長(zhǎng)寬的對(duì)應(yīng)關(guān)系)
????????///?
????????///?行數(shù)量
????????///?列數(shù)量
????????public?AIPath(int?rowcountint?colcount)
????????{
????????????RowCount?=?rowcount;
????????????ColCount?=?colcount;
????????????SubMap?=?new?StepNode[RowCountColCount];
????????????for?(int?i?=?0;?i?????????????{
????????????????for?(int?j?=?0;?j?????????????????{
????????????????????SubMap[i?j]?=?new?StepNode();
????????????????????SubMap[i?j].ColIndex?=?j;
????????????????????SubMap[i?j].RowIndex?=?i;
????????????????????SubMap[i?j].State?=?0;
????????????????????SubMap[i?j].H?=?0;
????????????????????SubMap[i?j].G?=?0;
????????????????}
????????????}
????????}
????????///?
????????///?將搜索程序重置到初始狀態(tài),清除之前搜索過(guò)程中產(chǎn)生的數(shù)據(jù)
????????///?
????????public?void?ReSet()
????????{
????????????this.OpenNode.Clear();
????????????this.FootPath.Clear();
????????????for?(int?i?=?0;?i?????????????{
????????????????for?(int?j?=?0;?j?????????????????{
????????????????????if?(SubMap[i?j].State?==?5)?
????????????????????{
????????????????????????SubMap[i?j].State?=?0;
????????????????????????SubMap[i?j].H?=?0;
????????????????????????SubMap[i?j].G?=?0;
????????????????????????SubMap[i?j].FartherNode?=?null;
????????????????????}
????????????????}
????????????}
????????}
????????///?
????????///?設(shè)置地圖副本中起始點(diǎn)和結(jié)束點(diǎn)(本程序地圖副本用的是一個(gè)數(shù)組用來(lái)表示地圖上的“格子”)
????????///?
????????///?起始點(diǎn)的行索引
????????///?起始點(diǎn)的列索引
????????///?結(jié)束點(diǎn)的行索引
????????///?結(jié)束點(diǎn)的列索引
????????public?void?SetStartEnd(int?SR?int?SC?int?ER?int?EC)
????????{
????????????this.StartNode?=?SubMap[SR?SC];
??
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????3767??2011-09-27?19:33??AI\AI\AI.csproj
?????文件??????10427??2011-09-27?22:49??AI\AI\AIPath.cs
?????文件?????177152??2011-09-27?22:57??AI\AI\bin\Debug\AI.exe
?????文件??????36352??2011-09-27?22:57??AI\AI\bin\Debug\AI.pdb
?????文件??????14328??2011-09-27?23:31??AI\AI\bin\Debug\AI.vshost.exe
?????文件???????5856??2011-09-27?22:57??AI\AI\mainForm.cs
?????文件???????8668??2011-09-27?22:54??AI\AI\mainForm.Designer.cs
?????文件?????245224??2011-09-27?22:54??AI\AI\mainForm.resx
?????文件????????380??2011-09-27?23:31??AI\AI\obj\Debug\AI.csproj.FileListAbsolute.txt
?????文件????????850??2011-09-27?22:56??AI\AI\obj\Debug\AI.csproj.GenerateResource.Cache
?????文件?????177152??2011-09-27?22:57??AI\AI\obj\Debug\AI.exe
?????文件?????159972??2011-09-27?22:56??AI\AI\obj\Debug\AI.mainForm.resources
?????文件??????36352??2011-09-27?22:57??AI\AI\obj\Debug\AI.pdb
?????文件????????180??2011-09-27?22:04??AI\AI\obj\Debug\AI.Properties.Resources.resources
?????文件????????486??2011-09-27?19:25??AI\AI\Program.cs
?????文件???????1336??2011-09-27?19:24??AI\AI\Properties\AssemblyInfo.cs
?????文件???????2854??2011-09-27?19:24??AI\AI\Properties\Resources.Designer.cs
?????文件???????5612??2011-09-27?19:24??AI\AI\Properties\Resources.resx
?????文件???????1087??2011-09-27?19:24??AI\AI\Properties\Settings.Designer.cs
?????文件????????249??2011-09-27?19:24??AI\AI\Properties\Settings.settings
?????文件????????896??2011-09-27?19:24??AI\AI.sln
????..A..H.?????13824??2011-09-27?23:31??AI\AI.suo
?????目錄??????????0??2011-09-27?19:25??AI\AI\obj\Debug\Refactor
?????目錄??????????0??2011-09-27?19:24??AI\AI\obj\Debug\TempPE
?????目錄??????????0??2011-09-27?22:04??AI\AI\bin\Debug
?????目錄??????????0??2011-09-27?22:57??AI\AI\obj\Debug
?????目錄??????????0??2011-09-27?19:25??AI\AI\bin
?????目錄??????????0??2011-09-27?19:24??AI\AI\obj
?????目錄??????????0??2011-09-27?19:24??AI\AI\Properties
?????目錄??????????0??2011-09-27?22:57??AI\AI
............此處省略4個(gè)文件信息
評(píng)論
共有 條評(píng)論