⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 8数码难题 深、广、a*
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// label4
			// 
			this.label4.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.label4.Font = new System.Drawing.Font("SimSun", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label4.Location = new System.Drawing.Point(24, 80);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(56, 48);
			this.label4.TabIndex = 5;
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.label3.Font = new System.Drawing.Font("SimSun", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label3.Location = new System.Drawing.Point(152, 24);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 48);
			this.label3.TabIndex = 4;
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.label2.Font = new System.Drawing.Font("SimSun", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label2.Location = new System.Drawing.Point(88, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 48);
			this.label2.TabIndex = 3;
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.label1.Font = new System.Drawing.Font("SimSun", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label1.Location = new System.Drawing.Point(24, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 48);
			this.label1.TabIndex = 2;
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.textBox10);
			this.groupBox3.Controls.Add(this.textBox11);
			this.groupBox3.Controls.Add(this.textBox12);
			this.groupBox3.Controls.Add(this.textBox13);
			this.groupBox3.Controls.Add(this.textBox14);
			this.groupBox3.Controls.Add(this.textBox15);
			this.groupBox3.Controls.Add(this.textBox16);
			this.groupBox3.Controls.Add(this.textBox17);
			this.groupBox3.Controls.Add(this.textBox18);
			this.groupBox3.Location = new System.Drawing.Point(8, 160);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(192, 104);
			this.groupBox3.TabIndex = 4;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Finalization Numbers";
			// 
			// textBox10
			// 
			this.textBox10.Location = new System.Drawing.Point(112, 72);
			this.textBox10.Name = "textBox10";
			this.textBox10.Size = new System.Drawing.Size(40, 21);
			this.textBox10.TabIndex = 8;
			this.textBox10.Text = "5";
			// 
			// textBox11
			// 
			this.textBox11.Location = new System.Drawing.Point(64, 72);
			this.textBox11.Name = "textBox11";
			this.textBox11.Size = new System.Drawing.Size(40, 21);
			this.textBox11.TabIndex = 7;
			this.textBox11.Text = "6";
			// 
			// textBox12
			// 
			this.textBox12.Location = new System.Drawing.Point(16, 72);
			this.textBox12.Name = "textBox12";
			this.textBox12.Size = new System.Drawing.Size(40, 21);
			this.textBox12.TabIndex = 6;
			this.textBox12.Text = "7";
			// 
			// textBox13
			// 
			this.textBox13.Location = new System.Drawing.Point(112, 48);
			this.textBox13.Name = "textBox13";
			this.textBox13.Size = new System.Drawing.Size(40, 21);
			this.textBox13.TabIndex = 5;
			this.textBox13.Text = "4";
			// 
			// textBox14
			// 
			this.textBox14.Location = new System.Drawing.Point(64, 48);
			this.textBox14.Name = "textBox14";
			this.textBox14.Size = new System.Drawing.Size(40, 21);
			this.textBox14.TabIndex = 4;
			this.textBox14.Text = "0";
			// 
			// textBox15
			// 
			this.textBox15.Location = new System.Drawing.Point(16, 48);
			this.textBox15.Name = "textBox15";
			this.textBox15.Size = new System.Drawing.Size(40, 21);
			this.textBox15.TabIndex = 3;
			this.textBox15.Text = "8";
			// 
			// textBox16
			// 
			this.textBox16.Location = new System.Drawing.Point(112, 24);
			this.textBox16.Name = "textBox16";
			this.textBox16.Size = new System.Drawing.Size(40, 21);
			this.textBox16.TabIndex = 2;
			this.textBox16.Text = "3";
			// 
			// textBox17
			// 
			this.textBox17.Location = new System.Drawing.Point(64, 24);
			this.textBox17.Name = "textBox17";
			this.textBox17.Size = new System.Drawing.Size(40, 21);
			this.textBox17.TabIndex = 1;
			this.textBox17.Text = "2";
			// 
			// textBox18
			// 
			this.textBox18.Location = new System.Drawing.Point(16, 24);
			this.textBox18.Name = "textBox18";
			this.textBox18.Size = new System.Drawing.Size(40, 21);
			this.textBox18.TabIndex = 0;
			this.textBox18.Text = "1";
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "宽度优先",
														   "深度优先",
														   "A*算法"});
			this.comboBox1.Location = new System.Drawing.Point(8, 8);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(96, 20);
			this.comboBox1.TabIndex = 5;
			this.comboBox1.Text = "宽度优先";
			// 
			// label10
			// 
			this.label10.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.label10.Location = new System.Drawing.Point(232, 272);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(224, 16);
			this.label10.TabIndex = 6;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(464, 301);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		private void InitTextBox()
		{
			tb1=new TextBox[3][];
			tb1[0]=new TextBox[3];
			tb1[0][0]=textBox1;
			tb1[0][1]=textBox2;
			tb1[0][2]=textBox3;
			tb1[1]=new TextBox[3];
			tb1[1][0]=textBox4;
			tb1[1][1]=textBox5;
			tb1[1][2]=textBox6;
			tb1[2]=new TextBox[3];
			tb1[2][0]=textBox7;
			tb1[2][1]=textBox8;
			tb1[2][2]=textBox9;

			tb2=new TextBox[3][];
			tb2[0]=new TextBox[3];
			tb2[0][0]=textBox18;
			tb2[0][1]=textBox17;
			tb2[0][2]=textBox16;
			tb2[1]=new TextBox[3];
			tb2[1][0]=textBox15;
			tb2[1][1]=textBox14;
			tb2[1][2]=textBox13;
			tb2[2]=new TextBox[3];
			tb2[2][0]=textBox12;
			tb2[2][1]=textBox11;
			tb2[2][2]=textBox10;
		}

		private void InitLabel()
		{
			lb=new Label[3][];
			lb[0]=new Label[3];
			lb[0][0]=label1;
			lb[0][1]=label2;
			lb[0][2]=label3;
			lb[1]=new Label[3];
			lb[1][0]=label4;
			lb[1][1]=label5;
			lb[1][2]=label6;
			lb[2]=new Label[3];
			lb[2][0]=label7;
			lb[2][1]=label8;
			lb[2][2]=label9;
		}

		private void InitArray()
		{
			array1=new int[3][];
			array2=new int[3][];
			for(int i=0;i<=2;i++)
			{
				array1[i]=new int[3];
				array2[i]=new int[3];
				for(int j=0;j<=2;j++)
				{
					array1[i][j]=int.Parse(tb1[i][j].Text);
					array2[i][j]=int.Parse(tb2[i][j].Text);
				}
			}
		}
		
		
		private void UpdateLabel()
		{
			
		}
		private bool ValidateTextBox()
		{
			bool re=true;
			return re;
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			label10.Text="";
			if(ValidateTextBox())
			{
				for(int i=0;i<=2;i++)
				{
						for(int j=0;j<=2;j++)
					{
						lb[i][j].Text=tb1[i][j].Text;
						tb1[i][j].Enabled=false;
						tb2[i][j].Enabled=false;
					}
				}
				InitArray();
			}
			else 
			{
				MessageBox.Show("请正确填入初始化数据");
			}
			
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			Thread th=new Thread(new ThreadStart(PThread));
			th.Start();
			
			for(int i=0;i<=2;i++)
				for(int j=0;j<=2;j++)
				{
					tb1[i][j].Enabled=true;
					tb2[i][j].Enabled=true;
				}
		}
		private void PThread()
		{
			label10.Text="计算时间中...";
			ChessAlg alg=new ChessAlg(array1,array2); 
			DateTime dt1=DateTime.Now;
			if(alg.Run(comboBox1.Text)==true)
			{
				DateTime dt2=DateTime.Now;
				label10.Text="耗时:"+((TimeSpan)(dt2-dt1)).ToString()+"  步数:"+alg.Result.Count.ToString();
				for(int i=alg.Result.Count-1;i>=0;i--)
				{
					PaintLabel(((Node)alg.Result[i]).arrayNodeString);
					Thread.Sleep(200);
				}
			}
			else 
			{
				MessageBox.Show("深度为25的条件下找不到答案");	
				label10.Text="";
			}
			
		}
		private void PaintLabel(String s)
		{
			int i,j;
			for(i=0;i<=2;i++)
				for(j=0;j<=2;j++)
				lb[i][j].Text=s[3*i+j].ToString();
		}		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -