資源簡介
自己寫的八數碼求解的C#程序 使用雙向廣搜算法求解

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?八數碼
{
????public?partial?class?Form1?:?Form
????{
????????private?const?int?DEEP_SIZE?=?16;
????????private?const?int?Queue_Size?=?400000;
????????int[]?x?=?{?1?0?0?0?1?2?2?2?1?};
????????int[]?y?=?{?1?0?1?2?2?2?1?0?0?};
????????int[?]?steps?=?new?int[80?3?3];
????????int?step_num;
????????int[]?state?=?new?int[]?{?{?0?0?0?}?{?0?0?0?}?{?0?0?0?}?};
????????int?loc_x?loc_y;
????????int?complete_flag?=?0;??????????//表示當前的求解狀態(tài),0為未選擇算法,1為無解,2為有解
????????int?now_step?=?0;
????????struct?Node
????????{
????????public?int[]?state;
????????????public?int?num;
????????????public?int?loc_x?loc_y;
????????????public?int?deep;
????????????public?int?index;
????????????public?int?parent_index;
????????};
????????struct?SqQueue
????????{
????????public?Node[]?base;
????????public?int?front?rear;
????????};
????????SqQueue?start_queue?=?new?SqQueue();
????????SqQueue?goal_queue?=?new?SqQueue();
????????void?print(int?start_index?int?goal_index)
????????{
????????????int?i?j?count;
????????????//cout?<se[start_index].deep?<“?“?<se[goal_index].deep?<????????????step_num?=?start_queue.base[start_index].deep?+?goal_queue.base[goal_index].deep;
????????????Node?node_to_record?=?start_queue.base[start_index];
????????????for?(count?=?start_queue.base[start_index].deep;?count?>=?0;?count--)
????????????{
????????????????for?(i?=?0;?i?3;?i++)
????????????????????for?(j?=?0;?j?3;?j++)
????????????????????????steps[countij]?=?node_to_record.state[i?j];
????????????????node_to_record?=?start_queue.base[node_to_record.parent_index];
????????????}
????????????node_to_record?=?goal_queue.base[goal_index];
????????????for?(count?=?start_queue.base[start_index].deep;?count?<=?step_num;?count++)
????????????{
????????????????for?(i?=?0;?i?3;?i++)
????????????????????for?(j?=?0;?j?3;?j++)
????????????????????????steps[countij]?=?node_to_record.state[ij];
????????????????node_to_record?=?goal_queue.base[node_to_record.parent_index];
????????????}
????????}
????????int?CheckStart(Node?node_to_check)
????????{
????????int?i;
????????for(i?=?0?;?i? ????????{
????????if(node_to_check.num?==?start_queue.base[i].num)
????????return?i; //在歷史中找到相同節(jié)點
????????}
????????return?-1;
????????}
????????int?CheckGoal(Node?node_to_check)
????????{
????????int?i;
????????for(i?=?0?;?i? ????????{
????????if(node_to_check.num?==?goal_queue.base[i].num)
????????return?i; //在歷史中找到相同節(jié)點
????????}
????????return?-1;
????????}
????????int?state_to_num(int[]?state)
????????{
????????int?num?=?0?i?j;
??????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-11-06?17:07??八數碼\
?????目錄???????????0??2013-11-06?17:59??八數碼\八數碼\
?????文件?????????917??2013-11-06?17:07??八數碼\八數碼.sln
?????文件???????34304??2013-11-20?21:33??八數碼\八數碼.v11.suo
?????文件????????4728??2013-11-06?17:22??八數碼\八數碼\1.png
?????文件?????????187??2013-11-06?17:07??八數碼\八數碼\App.config
?????目錄???????????0??2013-11-06?17:07??八數碼\八數碼\bin\
?????目錄???????????0??2013-11-21?21:32??八數碼\八數碼\bin\Debug\
?????文件????????2926??2013-11-06?17:27??八數碼\八數碼\bin\Debug\0.png
?????文件????????4728??2013-11-06?17:22??八數碼\八數碼\bin\Debug\1.png
?????文件????????5690??2013-11-06?17:22??八數碼\八數碼\bin\Debug\2.png
?????文件????????5835??2013-11-06?17:22??八數碼\八數碼\bin\Debug\3.png
?????文件????????5357??2013-11-06?17:23??八數碼\八數碼\bin\Debug\4.png
?????文件????????5555??2013-11-06?17:23??八數碼\八數碼\bin\Debug\5.png
?????文件????????6019??2013-11-06?17:23??八數碼\八數碼\bin\Debug\6.png
?????文件????????5198??2013-11-06?17:23??八數碼\八數碼\bin\Debug\7.png
?????文件????????6167??2013-11-06?17:23??八數碼\八數碼\bin\Debug\8.png
?????文件???????17920??2013-11-20?21:29??八數碼\八數碼\bin\Debug\八數碼.exe
?????文件?????????187??2013-11-06?17:07??八數碼\八數碼\bin\Debug\八數碼.exe.config
?????文件???????36352??2013-11-20?21:29??八數碼\八數碼\bin\Debug\八數碼.pdb
?????文件???????22984??2013-11-20?21:18??八數碼\八數碼\bin\Debug\八數碼.vshost.exe
?????文件?????????187??2013-11-06?17:07??八數碼\八數碼\bin\Debug\八數碼.vshost.exe.config
?????文件?????????490??2010-03-17?22:39??八數碼\八數碼\bin\Debug\八數碼.vshost.exe.manifest
?????文件???????18944??2013-11-21?21:32??八數碼\八數碼\bin\Debug\八數碼_Astar.exe
?????文件???????16689??2013-11-20?21:29??八數碼\八數碼\Form1.cs
?????文件???????12285??2013-11-12?17:12??八數碼\八數碼\Form1.Designer.cs
?????文件????????5817??2013-11-12?17:12??八數碼\八數碼\Form1.resx
?????目錄???????????0??2013-11-06?17:07??八數碼\八數碼\obj\
?????目錄???????????0??2013-11-20?21:29??八數碼\八數碼\obj\Debug\
?????文件????????1308??2013-11-11?21:02??八數碼\八數碼\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????7043??2013-11-06?17:08??八數碼\八數碼\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此處省略19個文件信息
評論
共有 條評論