用A算法解决十五数码问题

更新时间:2023-12-04 20:27:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

一、15数码问题的描述及其状态空间法表示

(1)15数码问题描述

15数码问题又叫移棋盘问题,是人工智能中的一个经典问题。所谓的15数码问题:就是在一个4×4的16宫格棋盘上,摆放有15个将牌,每一个将牌都刻有1~15中的某一个数码。棋盘中留有一个空格,允许其周围的某一个将牌向空格移动,这样通过移动将牌就可以不断改变将牌的布局。这种求解的问题是:给定一种初始的将牌布局或结构(称初始状态)和一个目标布局(称目标状态),问如何移动数码,实现从初始状态到目标状态的转变,如图1所示 。问题的实质就是寻找一个合法的动作序列

5 13 14 1 12 6 2 15 11 3 7 4 10 9 8 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 (a)初始状态 (b)目标状态

图1 15数码问题的一个实例

(2)状态空间法表示

人工智能问题的求解是以知识表示为基础的。如何将已获得的有关知识以计算机内部代

[1]

码形式加以合理地描述、存储、有效地利用便是表示应解决的问题。目前的知识表示方法有十余种,如:一阶谓词逻辑表示法、产生式表示法、状态空间表示法、语义网格表示法、框架表示法、脚本表示法、面向对象表示法等。任何一个给定的问题可能存在多种知识表示方法,人们可以根据待求解问题的领域知识选择适当的知识表示方法。这里我们只强调状态空间表示法。

把求解的问题表示成问题状态、操作、约束、初始状态和目标状态。状态空间就是所有可能的状态的集合。求解一个问题就是从初始状态出发,不断应用可应用的操作,在满足约束的条件下达到目标状态。问题求解过程就可以看成是问题状态在状态空间的移动。

状态是为描述某类不同事物间的差别而引入的一组最少变量q0,q1,?,qn的有序集合。问题的状态空间是一个表示该问题全部可能状态及其关系的图。记为三元状态(S、F、G),其中S所有可能的问题初始状态集合,F操作符集合,G目标状态集合。十五数码的状态空间法:

初始状态S[4][4]={5,12,11,4,13,6,3,10,14,2,7,9,1,15,0,8};(0表示空格) 目标状态G[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}; 操作符集合F={空格上移,空格下移,空格左移,空格右移}

状态空间的一个解:是一个有限的操作算子序列,它使初始状态转化为目标状态:S0-f1->S1-f2->...fk->G。

二、A* 算法的基本原理、算法步骤、流程图

(1)A*算法基本原理

A算法是一种有序搜索算法,其特点在于对评价函数的定义上。对于一般的有序搜索,总是选择f值最小的节点作为扩展节点。因此,f是根据需要找到一条最小代价路径的观点来估算节点的,可考虑将每个节点n的估价函数值分解为两个分量:从起始节点到节点n的最小代价路径的代价与从节点n到目标节点的最小代价路径的代价之和,也就是说f(n)是约束通

*

过节点n的一条最小代价路径的代价的一个估计。再定义一个函数f,使得在任意一个节点n

*

上的函数值f(n)就是从节点S到节点n的一条最佳路径的实际代价加上从节点n到目标节点的一条最佳路径的代价之和,即:

***

f(n) =g (n)+h (n)

*

评价函数f是f的一个估计,这个估计可由下式给出:

f(n)=g(n)+h(n)

***

其中g是g的估计,h是h的估计。g (n)的估计g(n)就是搜索树中从初始节点到当前节点n的这段路径的代价,这一代价可以由从初始节点到当前节点n寻找路径时,把遇到的各段

*

路径的代价加起来给出。h (n) 的估计h(n)依赖于有关问题的领域的启发信息,于是被称作启发函数。在启发函数中,应用的启发信息(问题知识)越多,扩展的节点就越少,这样就能更快地搜索到目标节点 。

*

(2)A*算法基本步骤

1)生成一个只包含开始节点n0的搜索图G,把n0放在一个叫OPEN的列表上。 2)生成一个列表CLOSED,它的初始值为空。 3)如果OPEN表为空,则失败退出。

4)选择OPEN上的第一个节点,把它从OPEN中移入CLPSED,称该节点为n。

5)如果n是目标节点,顺着G中,从n到n0的指针找到一条路径,获得解决方案,成功退出(该指针定义了一个搜索树,在第7步建立)。

6)扩展节点n,生成其后继结点集M,在G中,n的祖先不能在M中。在G中安置M的成员,使他们成为n的后继。

7)从M的每一个不在G中的成员建立一个指向n的指针(例如,既不在OPEN中,也不在CLOSED中)。把M1的这些成员加到OPEN中。对M的每一个已在OPEN中或CLOSED中的成员m,如果到目前为止找到的到达m的最好路径通过n,就把它的指针指向n。对已在CLOSED中的M的每一个成员,重定向它在G中的每一个后继,以使它们顺着到目前为止发现的最好路径指向它们的祖先。

**

8)按递增f值,重排OPEN(相同最小f值可根据搜索树中的最深节点来解决)。 9)返回第3步。

在第7步中,如果搜索过程发现一条路径到达一个节点的代价比现存的路径代价低,就要重定向指向该节点的指针。已经在CLOSED中的节点子孙的重定向保存了后面的搜索结果,但是可能需要指数级的计算代价。

(3)流程图如下所示:

开始把n0放入OPEN表,记f=h定义CLOSED表,初始值为空OPEN为空?Y失败退出N选取OPEN表上具有最小f值的节点n放入CLOSED表n是目标节点?Y成功N扩展n节点,产生其后继节点successor建立从successor返回n的指针计算g(suc)=g(n)+c(n,suc)Yn属于OPEN表?Nsuccessor=m,把它添加到n的后继节点列表中Yn属于CLOSED表?Ng(suc)

(1)本文采用C#基于对话框的程序设计,在图形界面上显示出十五数码格局并可以随意设置数码的位置。确定初始状态格局后,使用

A算法进行搜索。本方法实现的程序中用到的估价函数如下:f(n)=h(n)+g(n)。其中,h(n)代表搜索树中节点n的深度,根节点深度是0。启发函数g(n)定义为当前节点与其目标节点相应位置不相同元素的个数。点击初始化按钮,开始执行搜索,成功或失败后提示。

*

(2)程序实例展示

1)0步:初始状态,输入0~16的数码

输入完毕后,点击初始化,呈下图所示:

2)10步:初始态如下图所示:

0数码经过上移一次、左移三次、下移三次,右移三次到达目标状态,如下图:

(3)性能指标

空格不计,则16宫图的某状态为数1到15的一个排列,记为

n0nln2n3n4n5n6n7n8n9n10n11n12n13n14n15。两个状态之间是否可达可以通过计算两者的逆序数来判断,若两者逆序数的奇偶性相同则可达,否则不可达。也即对于任一个目标状态节点,有(1/2)×16 !=10461394944000个状态可达该节点。据统计,单纯用A*算法要花费几个小时时间才能判断出不能达到目标状态,这时CLOSED表长度为10461394944000。但由于本程序缺陷甚多,所以算法的时间复杂度会更高。

四、个人体会

初学人工智能时,最先联想到的便是机器人,一直感觉机器人是非常智能且非常神秘的,这也令人工智能在我的思想里笼罩了一层非同寻常的面纱,非常迫切的想要了解它的内涵。经过十几学时的学习,我对人工智能已有了初步了解,也深深的被它吸引,尤其通过本次程序设计,对人工智能的学习兴趣更加浓厚了!

15数码问题是人工智能的一个经典的问题。本文中通过设计一个基于A*算法的状态空间搜索程序,对于给定的初始状态,采用f(n)=h(n)+g(n)表示以当前节点与其目标节点相应位置不相同元素的个数与搜索深度之和作为启发函数的度量,并用可视化编程语言C#来实现该问题。

在程序的设计与实现过程中,遇到了很多的问题。首先由于初学人工智能,理解上有一定的困难,对A*算法的深入学习是一个曲折的过程。其次,在程序真正的设计及实现过程中,的确需要花费大量的精力来思考,反复试验。所设计的程序能够运行,但缺陷还是非常之大的,如其中重排OPEN表时,没有进行真正意义上的重新排列,只是选出代价最小的放在最先的位置,这实际上对程序的运行效率有很大的影响。

同时通过输入大量的初始状态和目标状态发现,在一般情况下都可以找到最优的动作序列。但对某些稍微复杂的初始状态虽能得到正确解却不能完全得到最短的搜索路径,对于某些极其复杂的状态,甚至得不到解。这是有待进一步学习并改进的地方。

但本程序还是有些值得肯定之处。界面设计比较友好,容易操作。而且在程序开始时,就判断目标状态是否可达,这样可节约大量的时间。虽然很多地方设计的不尽如意,但这是针对十五数码这个具体问题的一点优化。

附录:

//Program using System;

using System.Collections.Generic; using System.Windows.Forms; namespace _15Digital {

static class Program {

///

/// 应用程序的主入口点。 ///

[STAThread] static void Main() {

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

//Form1

using System;

using System.Collections;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;

using System.Windows.Forms;

using System.Windows.Forms.ComponentModel; using System.Reflection; namespace _15Digital {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private ArrayList result;//存储初始状态到目标状态的各个变换过程的状态 private static int currentIndex = 0;//记录初始状态到目标状态共需要的步数 ///

/// 对初始状态和目标状态矩阵进行初始化,其中的16个数码为0~15 ///

private void initialize() {

//定义初始态和目标态矩阵

int[][] Start_Matrix = new int[4][]; int[][] End_Matrix = new int[4][]; for (int i = 0; i < 4; i++) {

Start_Matrix[i] = new int[4]; End_Matrix[i] = new int[4]; }

//目标状态矩阵的赋值 for (int i = 0; i < 4; i++) {

for (int j = 0; j < 4; j++) {

End_Matrix[i][j] = 4 * i + j + 1; } }

End_Matrix[3][3] = 0; //获取初始状态矩阵 for (int i = 0; i < 4; i++) {

for (int j = 0; j < 4; j++) {

int k = 4 * i + j + 1;

TextBox tbox = (TextBox)this.findTextbox(\ int k2 = 16 + 4 * i + j + 1;

((TextBox)this.findTextbox(\tbox.Text.ToString ();

if (tbox.Text == \ {

MessageBox.Show(\请将所有空格填写完整!\ return; }

Start_Matrix[i][j] = Convert.ToInt32(tbox.Text); } }

//计算能否在50飞、步之内搜索到目标状态

_15Digital fifteen = new _15Digital(Start_Matrix, End_Matrix); if (fifteen.searchObject() == true) {

MessageBox.Show(\成功找到目标状态!\

result = fifteen.findResult(); button1.Enabled = true; } else

MessageBox.Show(\在50步以内没有您所要的结果!\ }

//将初始状态矩阵与显示窗口中的16数码矩阵相对应 private TextBox findTextbox(string name) {

foreach (Control temp in this.Controls) {

if (temp is System.Windows.Forms.TextBox) {

TextBox tb = (TextBox)temp; if (tb.Name == name) return tb; } }

return null; }

//在“目标态的显示窗口”中逐步实现,直到达到目标态为止 private void button1_Click(object sender, EventArgs e) {

_15DigitalNode currentNode = (_15DigitalNode)result[currentIndex]; for (int i = 0; i < 4; i++) {

for (int j = 0; j < 4; j++) {

int k2 = 16 + 4 * i + j + 1;

TextBox tbox2 = (TextBox)this.findTextbox(\ tbox2.Text = currentNode.matrix[i][j].ToString(); } }

currentIndex = (++currentIndex) % result.Count; if (currentIndex == 0)

this.button1.Enabled = false; }

//初始化

private void button2_Click(object sender, EventArgs e) {

initialize(); } } }

//Form1.Designer namespace _15Digital {

partial class Form1 {

///

/// 必需的设计器变量。 ///

private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。 ///

///

if (disposing && (components != null)) {

components.Dispose(); }

base.Dispose(disposing); }

#region Windows 窗体设计器生成的代码 ///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。 ///

private void InitializeComponent() {

this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.textBox4 = new System.Windows.Forms.TextBox(); this.textBox5 = new System.Windows.Forms.TextBox(); this.textBox6 = new System.Windows.Forms.TextBox(); this.textBox7 = new System.Windows.Forms.TextBox(); this.textBox8 = new System.Windows.Forms.TextBox(); this.textBox9 = new System.Windows.Forms.TextBox(); this.textBox10 = new System.Windows.Forms.TextBox(); this.textBox11 = new System.Windows.Forms.TextBox(); this.textBox12 = new System.Windows.Forms.TextBox(); this.textBox13 = new System.Windows.Forms.TextBox(); this.textBox14 = new System.Windows.Forms.TextBox(); this.textBox15 = new System.Windows.Forms.TextBox();

this.textBox16 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();

this.textBox17 = new System.Windows.Forms.TextBox(); this.textBox18 = new System.Windows.Forms.TextBox(); this.textBox19 = new System.Windows.Forms.TextBox(); this.textBox20 = new System.Windows.Forms.TextBox(); this.textBox21 = new System.Windows.Forms.TextBox(); this.textBox22 = new System.Windows.Forms.TextBox(); this.textBox23 = new System.Windows.Forms.TextBox(); this.textBox24 = new System.Windows.Forms.TextBox(); this.textBox25 = new System.Windows.Forms.TextBox(); this.textBox26 = new System.Windows.Forms.TextBox(); this.textBox27 = new System.Windows.Forms.TextBox(); this.textBox28 = new System.Windows.Forms.TextBox(); this.textBox29 = new System.Windows.Forms.TextBox(); this.textBox30 = new System.Windows.Forms.TextBox(); this.textBox31 = new System.Windows.Forms.TextBox(); this.textBox32 = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.SuspendLayout(); //

// textBox1 //

this.textBox1.Location = new System.Drawing.Point(6, 145); this.textBox1.Name = \

this.textBox1.Size = new System.Drawing.Size(21, 21); this.textBox1.TabIndex = 0; //

// textBox2 //

this.textBox2.Location = new System.Drawing.Point(27, 145); this.textBox2.Name = \

this.textBox2.Size = new System.Drawing.Size(21, 21); this.textBox2.TabIndex = 1; //

// textBox3 //

this.textBox3.Location = new System.Drawing.Point(48, 145);

this.textBox3.Name = \

this.textBox3.Size = new System.Drawing.Size(21, 21); this.textBox3.TabIndex = 2; //

// textBox4 //

this.textBox4.Location = new System.Drawing.Point(69, 145); this.textBox4.Name = \

this.textBox4.Size = new System.Drawing.Size(21, 21); this.textBox4.TabIndex = 3; //

// textBox5 //

this.textBox5.Location = new System.Drawing.Point(6, 166); this.textBox5.Name = \

this.textBox5.Size = new System.Drawing.Size(21, 21); this.textBox5.TabIndex = 4; //

// textBox6 //

this.textBox6.Location = new System.Drawing.Point(27, 166); this.textBox6.Name = \

this.textBox6.Size = new System.Drawing.Size(21, 21); this.textBox6.TabIndex = 5; //

// textBox7 //

this.textBox7.Location = new System.Drawing.Point(48, 166); this.textBox7.Name = \

this.textBox7.Size = new System.Drawing.Size(21, 21); this.textBox7.TabIndex = 6; //

// textBox8 //

this.textBox8.Location = new System.Drawing.Point(69, 166); this.textBox8.Name = \

this.textBox8.Size = new System.Drawing.Size(21, 21); this.textBox8.TabIndex = 7; //

// textBox9 //

this.textBox9.Location = new System.Drawing.Point(6, 187); this.textBox9.Name = \

this.textBox9.Size = new System.Drawing.Size(21, 21);

this.textBox9.TabIndex = 8; //

// textBox10 //

this.textBox10.Location = new System.Drawing.Point(27, 187); this.textBox10.Name = \

this.textBox10.Size = new System.Drawing.Size(21, 21); this.textBox10.TabIndex = 9; //

// textBox11 //

this.textBox11.Location = new System.Drawing.Point(48, 187); this.textBox11.Name = \

this.textBox11.Size = new System.Drawing.Size(21, 21); this.textBox11.TabIndex = 10; //

// textBox12 //

this.textBox12.Location = new System.Drawing.Point(69, 187); this.textBox12.Name = \

this.textBox12.Size = new System.Drawing.Size(21, 21); this.textBox12.TabIndex = 11; //

// textBox13 //

this.textBox13.Location = new System.Drawing.Point(6, 208); this.textBox13.Name = \

this.textBox13.Size = new System.Drawing.Size(21, 21); this.textBox13.TabIndex = 12; //

// textBox14 //

this.textBox14.Location = new System.Drawing.Point(27, 208); this.textBox14.Name = \

this.textBox14.Size = new System.Drawing.Size(21, 21); this.textBox14.TabIndex = 13; //

// textBox15 //

this.textBox15.Location = new System.Drawing.Point(48, 208); this.textBox15.Name = \

this.textBox15.Size = new System.Drawing.Size(21, 21); this.textBox15.TabIndex = 14; //

// textBox16 //

this.textBox16.Location = new System.Drawing.Point(69, 208); this.textBox16.Name = \

this.textBox16.Size = new System.Drawing.Size(21, 21); this.textBox16.TabIndex = 15; //

// button1 //

this.button1.Enabled = false;

this.button1.Location = new System.Drawing.Point(113, 185); this.button1.Name = \

this.button1.Size = new System.Drawing.Size(87, 23); this.button1.TabIndex = 32; this.button1.Text = \逐步实现\

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click); //

// button2 //

this.button2.Location = new System.Drawing.Point(113, 156); this.button2.Name = \

this.button2.Size = new System.Drawing.Size(87, 23); this.button2.TabIndex = 33; this.button2.Text = \初始化\

this.button2.UseVisualStyleBackColor = true;

this.button2.Click += new System.EventHandler(this.button2_Click); //

// label1 //

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(10, 30); this.label1.Name = \

this.label1.Size = new System.Drawing.Size(257, 12); this.label1.TabIndex = 34;

this.label1.Text = \、请您任意输入1~15个数字,剩余一位请输入0\ //

// label2 //

this.label2.AutoSize = true;

this.label2.Location = new System.Drawing.Point(10, 9); this.label2.Name = \

this.label2.Size = new System.Drawing.Size(77, 12); this.label2.TabIndex = 35;

this.label2.Text = \操作方法如下\ //

// label3 //

this.label3.AutoSize = true;

this.label3.Location = new System.Drawing.Point(10, 54); this.label3.Name = \

this.label3.Size = new System.Drawing.Size(227, 12); this.label3.TabIndex = 36;

this.label3.Text = \、初入初始数据以后,请点击初始化按钮\ //

// label4 //

this.label4.AutoSize = true;

this.label4.Location = new System.Drawing.Point(10, 78); this.label4.Name = \

this.label4.Size = new System.Drawing.Size(227, 12); this.label4.TabIndex = 37;

this.label4.Text = \、点击逐步实现按钮,直至出现目标状态\ //

// textBox17 //

this.textBox17.Location = new System.Drawing.Point(222, 145); this.textBox17.Name = \

this.textBox17.Size = new System.Drawing.Size(21, 21); this.textBox17.TabIndex = 38; //

// textBox18 //

this.textBox18.Location = new System.Drawing.Point(243, 145); this.textBox18.Name = \

this.textBox18.Size = new System.Drawing.Size(21, 21); this.textBox18.TabIndex = 39; //

// textBox19 //

this.textBox19.Location = new System.Drawing.Point(264, 145); this.textBox19.Name = \

this.textBox19.Size = new System.Drawing.Size(21, 21); this.textBox19.TabIndex = 40; //

// textBox20 //

this.textBox20.Location = new System.Drawing.Point(285, 145);

this.textBox20.Name = \

this.textBox20.Size = new System.Drawing.Size(21, 21); this.textBox20.TabIndex = 41; //

// textBox21 //

this.textBox21.Location = new System.Drawing.Point(222, 166); this.textBox21.Name = \

this.textBox21.Size = new System.Drawing.Size(21, 21); this.textBox21.TabIndex = 42; //

// textBox22 //

this.textBox22.Location = new System.Drawing.Point(243, 166); this.textBox22.Name = \

this.textBox22.Size = new System.Drawing.Size(21, 21); this.textBox22.TabIndex = 43; //

// textBox23 //

this.textBox23.Location = new System.Drawing.Point(264, 166); this.textBox23.Name = \

this.textBox23.Size = new System.Drawing.Size(21, 21); this.textBox23.TabIndex = 44; //

// textBox24 //

this.textBox24.Location = new System.Drawing.Point(285, 166); this.textBox24.Name = \

this.textBox24.Size = new System.Drawing.Size(21, 21); this.textBox24.TabIndex = 45; //

// textBox25 //

this.textBox25.Location = new System.Drawing.Point(222, 187); this.textBox25.Name = \

this.textBox25.Size = new System.Drawing.Size(21, 21); this.textBox25.TabIndex = 46; //

// textBox26 //

this.textBox26.Location = new System.Drawing.Point(243, 187); this.textBox26.Name = \

this.textBox26.Size = new System.Drawing.Size(21, 21);

this.textBox26.TabIndex = 47; //

// textBox27 //

this.textBox27.Location = new System.Drawing.Point(264, 187); this.textBox27.Name = \

this.textBox27.Size = new System.Drawing.Size(21, 21); this.textBox27.TabIndex = 48; //

// textBox28 //

this.textBox28.Location = new System.Drawing.Point(285, 187); this.textBox28.Name = \

this.textBox28.Size = new System.Drawing.Size(21, 21); this.textBox28.TabIndex = 49; //

// textBox29 //

this.textBox29.Location = new System.Drawing.Point(222, 208); this.textBox29.Name = \

this.textBox29.Size = new System.Drawing.Size(21, 21); this.textBox29.TabIndex = 50; //

// textBox30 //

this.textBox30.Location = new System.Drawing.Point(243, 208); this.textBox30.Name = \

this.textBox30.Size = new System.Drawing.Size(21, 21); this.textBox30.TabIndex = 51; //

// textBox31 //

this.textBox31.Location = new System.Drawing.Point(264, 208); this.textBox31.Name = \

this.textBox31.Size = new System.Drawing.Size(21, 21); this.textBox31.TabIndex = 52; //

// textBox32 //

this.textBox32.Location = new System.Drawing.Point(285, 208); this.textBox32.Name = \

this.textBox32.Size = new System.Drawing.Size(21, 21); this.textBox32.TabIndex = 53; //

// label8 //

this.label8.AutoSize = true;

this.label8.Location = new System.Drawing.Point(28, 121); this.label8.Name = \

this.label8.Size = new System.Drawing.Size(41, 12); this.label8.TabIndex = 57; this.label8.Text = \初始态\ //

// label5 //

this.label5.AutoSize = true;

this.label5.Location = new System.Drawing.Point(215, 121); this.label5.Name = \

this.label5.Size = new System.Drawing.Size(101, 12); this.label5.TabIndex = 58;

this.label5.Text = \变化过程及目标态\ //

// Form1 //

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(317, 250); this.Controls.Add(this.label5); this.Controls.Add(this.label8); this.Controls.Add(this.textBox32); this.Controls.Add(this.textBox31); this.Controls.Add(this.textBox30); this.Controls.Add(this.textBox29); this.Controls.Add(this.textBox28); this.Controls.Add(this.textBox27); this.Controls.Add(this.textBox26); this.Controls.Add(this.textBox25); this.Controls.Add(this.textBox24); this.Controls.Add(this.textBox23); this.Controls.Add(this.textBox22); this.Controls.Add(this.textBox21); this.Controls.Add(this.textBox20); this.Controls.Add(this.textBox19); this.Controls.Add(this.textBox18); this.Controls.Add(this.textBox17); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.label2);

this.Controls.Add(this.label1); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.textBox16); this.Controls.Add(this.textBox15); this.Controls.Add(this.textBox14); this.Controls.Add(this.textBox13); this.Controls.Add(this.textBox12); this.Controls.Add(this.textBox11); this.Controls.Add(this.textBox10); this.Controls.Add(this.textBox9); this.Controls.Add(this.textBox8); this.Controls.Add(this.textBox7); this.Controls.Add(this.textBox6); this.Controls.Add(this.textBox5); this.Controls.Add(this.textBox4); this.Controls.Add(this.textBox3); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Name = \ this.Text = \数码\ this.ResumeLayout(false); this.PerformLayout(); }

#endregion

private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.TextBox textBox4; private System.Windows.Forms.TextBox textBox5; private System.Windows.Forms.TextBox textBox6; private System.Windows.Forms.TextBox textBox7; private System.Windows.Forms.TextBox textBox8; private System.Windows.Forms.TextBox textBox9; private System.Windows.Forms.TextBox textBox10; private System.Windows.Forms.TextBox textBox11; private System.Windows.Forms.TextBox textBox12; private System.Windows.Forms.TextBox textBox13; private System.Windows.Forms.TextBox textBox14; private System.Windows.Forms.TextBox textBox15; private System.Windows.Forms.TextBox textBox16; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4;

private System.Windows.Forms.TextBox textBox17; private System.Windows.Forms.TextBox textBox18; private System.Windows.Forms.TextBox textBox19; private System.Windows.Forms.TextBox textBox20; private System.Windows.Forms.TextBox textBox21; private System.Windows.Forms.TextBox textBox22; private System.Windows.Forms.TextBox textBox23; private System.Windows.Forms.TextBox textBox24; private System.Windows.Forms.TextBox textBox25; private System.Windows.Forms.TextBox textBox26; private System.Windows.Forms.TextBox textBox27; private System.Windows.Forms.TextBox textBox28; private System.Windows.Forms.TextBox textBox29; private System.Windows.Forms.TextBox textBox30; private System.Windows.Forms.TextBox textBox31; private System.Windows.Forms.TextBox textBox32; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label5; } }

//_15Digital using System;

using System.Collections.Generic; using System.Text;

using System.Collections;

namespace _15Digital {

struct digitalPosition {

public int x;//存储矩阵中元素的横坐标 public int y;//存储矩阵中元素的纵坐标 }

class _15DigitalNode {

//记录本节点由其父节点得来的方式,上、下、左、右 int mode;

// 存储零数码的位置

private digitalPosition[] digitalPos = new digitalPosition[16]; // 获得当前节点矩阵中各个数码的位置 public digitalPosition[] findDigitalPosition()

本文来源:https://www.bwwdw.com/article/nvbt.html

Top