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

📄 winhrd.cs

📁 十分完善的华容道程序,有多种布局的求解!
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.nupLayoutsPerLine.TabIndex = 16;
			this.nupLayoutsPerLine.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.nupLayoutsPerLine.Value = new System.Decimal(new int[] {
																			4,
																			0,
																			0,
																			0});
			// 
			// label1
			// 
			this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label1.Location = new System.Drawing.Point(184, 522);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 17;
			this.label1.Text = "每行显示";
			// 
			// label2
			// 
			this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label2.Location = new System.Drawing.Point(288, 522);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.TabIndex = 18;
			this.label2.Text = "个结果";
			// 
			// btnStop
			// 
			this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnStop.Enabled = false;
			this.btnStop.Location = new System.Drawing.Point(96, 512);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new System.Drawing.Size(80, 32);
			this.btnStop.TabIndex = 19;
			this.btnStop.Text = "停止(&S)";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// stbInfo
			// 
			this.stbInfo.Location = new System.Drawing.Point(0, 551);
			this.stbInfo.Name = "stbInfo";
			this.stbInfo.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																					   this.statusBarPanel1,
																					   this.statusBarPanel2,
																					   this.statusBarPanel3});
			this.stbInfo.ShowPanels = true;
			this.stbInfo.Size = new System.Drawing.Size(792, 22);
			this.stbInfo.TabIndex = 20;
			// 
			// statusBarPanel1
			// 
			this.statusBarPanel1.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
			this.statusBarPanel1.MinWidth = 200;
			this.statusBarPanel1.Text = "吕震宇 Email:zhenyulu@163.com";
			this.statusBarPanel1.Width = 200;
			// 
			// statusBarPanel2
			// 
			this.statusBarPanel2.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.statusBarPanel2.Text = " http://www.cnblogs.com/zhenyulu";
			this.statusBarPanel2.Width = 512;
			// 
			// statusBarPanel3
			// 
			this.statusBarPanel3.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
			this.statusBarPanel3.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
			this.statusBarPanel3.Text = "2005-2-1";
			this.statusBarPanel3.Width = 64;
			// 
			// frmMain
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.Add(this.stbInfo);
			this.Controls.Add(this.btnStop);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.nupLayoutsPerLine);
			this.Controls.Add(this.lblInfo);
			this.Controls.Add(this.optLayout10);
			this.Controls.Add(this.optLayout9);
			this.Controls.Add(this.optLayout7);
			this.Controls.Add(this.optLayout8);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnBegin);
			this.Controls.Add(this.optLayout5);
			this.Controls.Add(this.optLayout6);
			this.Controls.Add(this.optLayout3);
			this.Controls.Add(this.optLayout4);
			this.Controls.Add(this.optLayout2);
			this.Controls.Add(this.optLayout1);
			this.Controls.Add(this.txtResult);
			this.MinimumSize = new System.Drawing.Size(592, 410);
			this.Name = "frmMain";
			this.Text = "华容道自动解题";
			((System.ComponentModel.ISupportInitialize)(this.nupLayoutsPerLine)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmMain());
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void optLayout_CheckedChanged(object sender, System.EventArgs e)
		{
			if(optLayout1.Checked)
				this.layoutFactory = new LayoutFactory1();
			else if(optLayout2.Checked)
				this.layoutFactory = new LayoutFactory2();
			else if(optLayout3.Checked)
				this.layoutFactory = new LayoutFactory3();
			else if(optLayout4.Checked)
				this.layoutFactory = new LayoutFactory4();
			else if(optLayout5.Checked)
				this.layoutFactory = new LayoutFactory5();
			else if(optLayout6.Checked)
				this.layoutFactory = new LayoutFactory6();
			else if(optLayout7.Checked)
				this.layoutFactory = new LayoutFactory7();
			else if(optLayout8.Checked)
				this.layoutFactory = new LayoutFactory8();
			else if(optLayout9.Checked)
				this.layoutFactory = new LayoutFactory9();
			else
				this.layoutFactory = new LayoutFactory10();
		}

		private void btnBegin_Click(object sender, System.EventArgs e)
		{
			layoutFactory.mediator = mediator;
			mediator.circleList = new CircularLinkedList(layoutFactory);
			mediator.resultHandler = this;

			mediator.Init(1000);

			Thread trd = new Thread(new ThreadStart(this.Process));
			trd.Priority = ThreadPriority.BelowNormal;
			trd.IsBackground = true;
			trd.Start();
		}

		private void btnStop_Click(object sender, System.EventArgs e)
		{
			mediator.Stop();
			this.txtResult.Text += "\r\n用户终止了程序的运行!";
		}

		private void Process()
		{
			txtResult.Text = "正在求解,请等待......";
			btnBegin.Enabled = false;
			btnStop.Enabled = true;
			SetOptionsButtonEnabled(false);
			this.Refresh();

			DateTime begin = DateTime.Now;

			if(!mediator.BeginProcess())
				this.txtResult.Text = "此题无解!";

			DateTime end = DateTime.Now;

			TimeSpan t = end - begin;
			this.lblInfo.Text += String.Format(" , 用时 {0:F3} 秒", t.TotalMilliseconds/1000);

			btnBegin.Enabled = true;
			btnStop.Enabled = false;
			SetOptionsButtonEnabled(true);
			mediator.Release();	// 及时释放内存;
		}

		private void SetOptionsButtonEnabled(bool state)
		{
			optLayout1.Enabled = state;
			optLayout2.Enabled = state;
			optLayout3.Enabled = state;
			optLayout4.Enabled = state;
			optLayout5.Enabled = state;
			optLayout6.Enabled = state;
			optLayout7.Enabled = state;
			optLayout8.Enabled = state;
			optLayout9.Enabled = state;
			optLayout10.Enabled = state;
		}

		#region IResultHandler 接口实现

		public void HandleResult(ChessStep[] steps)
		{
			StringBuilder sb = new StringBuilder();
			string[][] result = new String[steps.Length][];

			// 将结果载入数组
			for(int i=0; i<steps.Length - 1; i++)
			{
				result[i] = new string[13];

				result[i][0] = String.Format("({0})  ", i + 1);
				ResultHelper.MakeLayout(result[i], steps[i].layout);
				result[i][12] = String.Format("Move {0} {1} ", steps[i].chessmanNum, steps[i].moveMethod);

			}

			result[steps.Length - 1] = new string[13];
			result[steps.Length - 1][0] = String.Format("Got the Answer!");
			ResultHelper.MakeLayout(result[steps.Length - 1], steps[steps.Length -1].layout);
			result[steps.Length - 1][12] = "";

			// 处理一行显示多个结果
			int layoutsPerLine = (int)this.nupLayoutsPerLine.Value;
			int stepsLeft = steps.Length;
			int lines = (steps.Length - 1)/layoutsPerLine;

			for(int i = 0; i<lines; i++)
			{
				for(int j=0; j<13; j++)
				{
					for(int k=0; k<layoutsPerLine; k++)
						sb.Append(result[layoutsPerLine * i + k][j].PadRight(22, ' '));

					sb.Append("\r\n");
				}

				sb.Append("\r\n");
			}

			int m = (steps.Length - 1) % layoutsPerLine;
			if( m != 0)
			{
				for(int j=0; j<13; j++)
				{
					for(int k=0; k<m; k++)
						sb.Append(result[layoutsPerLine * lines + k][j].PadRight(22, ' '));

					sb.Append("\r\n");
				}
			}

			sb.Append("\r\n");
			sb.Append('-',layoutsPerLine*22);
			sb.Append("\r\n\r\n");

			for(int j=0; j<13; j++)
				sb.Append(result[steps.Length - 1][j] + "\r\n");

			sb.Append("\r\n");

			this.txtResult.Text = sb.ToString();
			sb.Remove(0, sb.Length);
			
			return;
		}

		public void HandleInfo(int currentStep)
		{
			this.lblInfo.Text = "搜索深度: " + currentStep.ToString();
			this.lblInfo.Refresh();
		}

		#endregion


	}
}

⌨️ 快捷键说明

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