亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? problemgenerator.cs

?? 英國幾乎所有的報紙都刊登數獨游戲
?? CS
字號:
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;


namespace SuDokuSolution
{
	/// <summary>
	/// Class for generating problems
	/// </summary>
	public class ProblemGenerator
	{
		internal int [,] completeGrid;
		internal int [,] problemGrid;
		internal static bool complete;
		private SuDokuSolution.MainForm mainForm;
		private int level;
		private ProcessingSplash processingSplash;
		
		public ProblemGenerator(SuDokuSolution.MainForm  m)
		{
			problemGrid=new int [Constants.nbOfCells,Constants.nbOfCells];
			completeGrid=new int [Constants.nbOfCells,Constants.nbOfCells];
			this.mainForm=m;
		}
	
		/// <summary>
		/// method for generating complete grid
		/// </summary>
		/// <returns>true if operation is successful</returns>
		private bool creatCompleteGrid()
		{
			for(int row =0;row<9;row++)
			{
				for(int col=0;col<9;col++)
				{ 
					this.problemGrid[row,col]=Constants.NoNumber;
					this.completeGrid[row,col]=Constants.NoNumber;					
				}
			}

			ArrayList freeCols=new ArrayList(9);    
			ArrayList filledPoints=new ArrayList(9); 			//for storing positions of filled ponts so that making roll back easy          

			Random rand=new Random();
			for(int count=1;count<=9;count++)           
			{          
				int repetitions=0;
				filledPoints.Clear();
				for(int row =0;row<9;row+=2)
				{ 
					//rows are being filled at a diff of two, at the end it rolls off to start
					repetitions++;
					if(repetitions==150)
					{
						return false;
					}
					freeCols.Clear();                        
					foreach (int number in new int[9]{0,1,2,3,4,5,6,7,8})
					{
						freeCols.Add(number);
					}       
					int col=0;
					bool repeat=true;
					while(repeat) //find a position in current row for placing current count
					{
						repeat=false;                        
						if(freeCols.Count==0)
						{ 
							//remove no. filled already
							for(int rollBack=0;rollBack<filledPoints.Count;rollBack++)
							{
								Point p=(Point)filledPoints[rollBack];
								completeGrid[p.X,p.Y]=Constants.NoNumber;
							}
							row=-2;
							repeat=true;
							break;
						}
                         
						//select a new column at random and get its value                        
						col=rand.Next(0,freeCols.Count);                      
						col=(int)freeCols[col];
						if(this.completeGrid[row,col]!=Constants.NoNumber)
						{
							freeCols.Remove(col);
							repeat=true;
							continue;
						}                   
                   
						int HB=(int)(row/3);
						int VB=(int) (col/3);
                    
						for(int i=0;i<9;i++)
						{
							if(completeGrid[i,col] ==count)
							{
								freeCols.Remove(col);
								repeat=true;
							}
						}
                    
						if(repeat)
							continue;
                          
						for(int i=HB*3;i<(HB+1)*3;i++)
						{
							for(int j=VB*3;j<(VB+1)*3;j++)
							{
								if(completeGrid[i,j] ==count)
								{
									freeCols.Remove(col);
									repeat=true;
								}
							}
						}                      
					}

					//if while loop is broken and repeat is true than start from row zero again
					if(repeat)
						continue;
                   
					this.completeGrid[row,col]=count;
					filledPoints.Add(new Point(row,col));
					this.problemGrid[row,col]=this.completeGrid[row,col];
					if(row==8) 
						row=-1;
				}               
			}
			return true;
		}


		/// <summary>
		/// for generating probem grid
		/// </summary>
		/// <returns>true if operation is successful</returns>
		private bool creatProblemGrid()
		{
			Random rand=new Random();
			int [,]solArray=new int[Constants.nbOfCells,Constants.nbOfCells];
          
			ArrayList points=new ArrayList();
			for(int row=0;row<Constants.nbOfCells;row++)
			{
				for(int col=0;col<Constants.nbOfCells;col++)
				{
					points.Add(new Point(row,col));
				}
			}
         
			for(int count =0;count<this.level;count++)
			{
				if(points.Count==0)
					return false;

				int pRand=rand.Next(0,points.Count);
				Point p=(Point)points[pRand]; 
				int row=p.X;
				int col=p.Y;
             
				this.problemGrid[row,col]=Constants.NoNumber;
				if(!(hasSolution(problemGrid,ref solArray,true)==true 
					&& areEqualArray(solArray,completeGrid)==true ))
				{                   
					this.problemGrid[row,col]=this.completeGrid[row,col];                  
					count--;                    
					points.RemoveAt(pRand);
					continue;
				}    
				points.RemoveAt(pRand);
              
				this.processingSplash.progressBar.PerformStep();
			}
			return true;
		}

		#region Alternative Solution for hasSolution
		/// <summary>
		/// Chhecks if the problem grid passed is solvable
		/// </summary>
		/// <param name="underProcessingGrid">The problem grid under observation</param>
		/// <param name="returnArray">The  solution array if toReturnArray==true</param>
		/// <param name="toReturnSolution">If true the return array argument has the solution of the problem </param>
		/// <returns>True if problem is solvable</returns>
		public static bool hasSolution1(int [,] underProcessingGrid,ref int [,] returnArray,bool toReturnSolution)
		{
			int [,] solution=new int [9,9];
			for(int row=0;row<9;row++)
			{
				for(int col=0;col<9;col++)
				{
					solution[row,col]=underProcessingGrid[row,col];
				}
			}
			complete=false;
			bool canSolve=true;
			bool makeChoice=false;
			while(complete==false)
			{
				if(canSolve==false && makeChoice==true)
					return canSolve;

				else if(canSolve==false && makeChoice==false )
					//MessageBox.Show("a");
					makeChoice=true;
                           
				canSolve=false;
				complete=true;
                
				for(int row=0;row<9;row++)
				{
					for(int col=0;col<9;col++)
					{
						int HB=(int)(row/3);
						int VB=(int) (col/3);
						ArrayList candidateNb=new ArrayList(9);
						foreach (int number in new int[9]{1,2,3,4,5,6,7,8,9})
						{
							candidateNb.Add(number);
						}       
						if(solution[row,col]==Constants.NoNumber)
						{
							complete=false;                            
							for(int i=0;i<9;i++)
							{
								candidateNb.Remove(solution[row,i]);
								candidateNb.Remove(solution[i,col]);
							}
                          
							for(int i=HB*3;i<(HB+1)*3;i++)
							{
								for(int j=VB*3;j<(VB+1)*3;j++)
								{
									candidateNb.Remove(solution[i,j]);                                    
								}
							}
							if(candidateNb.Count==1)
							{
								canSolve=true;      
								solution[row,col]=(int)candidateNb[0];
							}    

							else if(candidateNb.Count==2 && makeChoice==true)
							{
								solution[row,col]=(int)candidateNb[0];
								if(hasSolution1(solution,ref solution,false))
								{
									solution[row,col]=(int)candidateNb[1];
									if(hasSolution1(solution,ref solution,false))  
										return false; //solution is not unique
								
									solution[row,col]=(int)candidateNb[0];
									hasSolution1(solution,ref solution,false); //unique solution retrieve it
									makeChoice=false;
									canSolve=true;
								}
								else
								{
									solution[row,col]=(int)candidateNb[1];
									if(hasSolution1(solution,ref solution,true))
									{
										makeChoice=false;
										canSolve=true;
									}
									else
										solution[row,col]=Constants.NoNumber;
								}
							}
						}                        
					}
				}
			}
			if(toReturnSolution)
				returnArray=solution;
			return true;
		}

		#endregion 

		/// <summary>
		/// Checks if the problem grid passed is solvable
		/// </summary>
		/// <param name="underProcessingGrid">The problem grid under observation</param>
		/// <param name="returnArray">The  solution array if toReturnArray==true</param>
		/// <param name="toReturnSolution">If true the return array argument has the solution of the problem </param>
		/// <returns>True if problem is solvable</returns>
		internal static bool hasSolution(int [,] underProcessingGrid,ref int [,] returnArray,bool toReturnSolution)
		{
            CellData [,] solution=new CellData[Constants.nbOfCells,Constants.nbOfCells];
			for(int row=0;row<Constants.nbOfCells;row++)
			{
				for(int col=0;col<Constants.nbOfCells;col++)
				{
					solution[row,col]=new CellData();
					solution[row,col].candidateNb.Clear();
					solution[row,col].originalNb=underProcessingGrid[row,col];
				}
			}
            
			#region search for candidate nbs and_ set the candidate nb list of each unfilled cell
			for(int row=0;row<Constants.nbOfCells;row++)
			{
				for(int col=0;col<Constants.nbOfCells;col++)
				{
					if(solution[row,col].originalNb!=Constants.NoNumber)
						continue;            
					int HB=(int)(row/Constants.nbOfLines);
					int VB=(int) (col/Constants.nbOfLines);
					ArrayList candidateNb=new ArrayList(9);
					foreach (int number in new int[9]{1,2,3,4,5,6,7,8,9})
					{
						candidateNb.Add(number);
					}                   
            
					for(int i=0;i<9;i++)
					{
						candidateNb.Remove(solution[row,i].originalNb);
						candidateNb.Remove(solution[i,col].originalNb);
					}
                          
					for(int i=HB*3;i<(HB+1)*3;i++)
					{
						for(int j=VB*3;j<(VB+1)*3;j++)
						{
							candidateNb.Remove(solution[i,j].originalNb);                                    
						}
					}
					for(int i=0;i<candidateNb.Count;i++)
						solution[row,col].candidateNb.Add(candidateNb[i]);
				}
			}
			#endregion
            
			bool complete=false;
			bool canSolve=true;
			while(!complete)
			{  
				if(!canSolve)
					return false;
				complete=true;
				canSolve=false;
				for(int row=0;row<Constants.nbOfCells;row++)
				{
					for(int col=0;col<Constants.nbOfCells;col++)
					{
						if(solution[row,col].originalNb==Constants.NoNumber)						
						{
							if(complete)
								complete=false;
						}
						else
							continue;
						int HB=(int)(row/Constants.nbOfLines);
						int VB=(int) (col/Constants.nbOfLines);
						if(solution[row,col].candidateNb.Count==1)
						{
							canSolve=true;
							int nb=solution[row,col].originalNb=(int)solution[row,col].candidateNb[0];
							solution[row,col].candidateNb.Clear();
							//now modify other cell's  candidates
							for(int i=0;i<Constants.nbOfCells;i++)
							{
								solution[row,i].candidateNb.Remove(nb);
								solution[i,col].candidateNb.Remove(nb);
							}
                          
							for(int i=HB*3;i<(HB+1)*3;i++)
							{
								for(int j=VB*3;j<(VB+1)*3;j++)
								{
									solution[i,j].candidateNb.Remove(nb);
								}
							}
						}
                        
						else  //find nb that cannot come into any cell of that block
						{
							for(int index=0;index<solution[row,col].candidateNb.Count;index++)
							{
								int number=(int)solution[row,col].candidateNb[index];
								bool found=false;
								for(int i=HB*Constants.nbOfLines;i<(HB+1)*Constants.nbOfLines;i++)                                
									for(int j=VB*Constants.nbOfLines;j<(VB+1)*Constants.nbOfLines;j++)                                    
										if(solution[i,j].candidateNb.Contains(number) && !(i==row && j==col))
										{
											j=(VB+1)*Constants.nbOfLines; //exit from loop
											i=(HB+1)*Constants.nbOfLines;
											found=true;
										}   
                                
								if(!found)
								{
									//the candidate  nb is found
									solution[row,col].originalNb=number;
									canSolve=true;
									solution[row,col].candidateNb.Clear();
									for(int i=0;i<9;i++) //remove that num from other lists
									{
										solution[row,i].candidateNb.Remove(number);
										solution[i,col].candidateNb.Remove(number);
									}
									index=100; //exit from loop
								}
							}
						}
					}
				}              
			}

			if(toReturnSolution)
				for(int row=0;row<9;row++)
				{
					for(int col=0;col<9;col++)
					{
						returnArray[row,col]=solution[row,col].originalNb;
						solution[row,col].Dispose(true);
					}
				}                      
			return true;
		}

       
		/// <summary>
        /// Checks if the two array passed are equal
        /// </summary>
        /// <param name="first">The first array</param>
        /// <param name="second">Second array</param>
        /// <returns>True if the two array passed are equal</returns>
		private bool areEqualArray(int [,]first,int [,]second)
		{
			if(first.Length!=second.Length)
				return false;
			
			for(int row=0;row<Constants.nbOfCells;row++)
			{
				for(int col=0;col<Constants.nbOfCells;col++)
				{
					if(first[row,col]!=second[row,col])
					{
						//MessageBox.Show("Method areequal returning false ");
						return false;
					}
				}
			}
			return true;
		}


		/// <summary>
		/// Generates the problem and return true if success
		/// </summary>
		public bool GenerateProblem()
		{
			processingSplash =new ProcessingSplash();
			mainForm.Enabled=false;                

			//this.statusBar1.Text="Creating Puzzle";
			try
			{
				using(SuDokuSolution.difficultyDialog dd=new SuDokuSolution.difficultyDialog())
				{
					dd.ShowDialog();
					this.level=dd.Level;
					if(this.level==0)
						return false;
				}

				//clearClicked(sender,e);
				//if(autoFillItem.Checked==true)
				//	showcandItem_Click(autoFillItem,e);
				processingSplash.Show();
				processingSplash.Update();
				this.processingSplash.progressBar.Maximum=this.level;
                
				processingSplash.progressBar.Value=0;
				
				while(! this.creatCompleteGrid())
					System.GC.Collect();
				//MessageBox.Show("No Problem");
                
				while(!this.creatProblemGrid())
				{
					problemGrid=(int[,])completeGrid.Clone();
					processingSplash.progressBar.Value=0;
					processingSplash.progressBar.Refresh();
				}    
			}
			catch(Exception ex)
			{
				MessageBox.Show("Some error has occured to the application"
					+",Retry or close the program and start again\n"+ex.Message,"Error");
			}
			finally
			{  
				this.processingSplash.progressBar.Value=processingSplash.progressBar.Maximum;
				processingSplash.Close();
				mainForm.TopMost=true;
				mainForm.TopMost=false;
				processingSplash.Dispose();
				System.GC.Collect();
				mainForm.Enabled=true;
			}
			return true;
		}

	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成人免费在线观看| 亚洲一区二区欧美日韩| 欧美国产精品中文字幕| 亚洲高清不卡在线| 成人午夜又粗又硬又大| 日韩一区二区三区视频在线| 综合久久综合久久| 国产精品亚洲综合一区在线观看| 欧美日韩国产一区二区三区地区| 国产精品乱码一区二区三区软件| 精品一区精品二区高清| 欧美高清视频www夜色资源网| 一色桃子久久精品亚洲| 国产一区二区三区最好精华液| 欧美三级一区二区| 亚洲桃色在线一区| 国产成人av一区二区| 精品毛片乱码1区2区3区| 亚洲成人av一区二区三区| 色综合天天综合网天天狠天天 | 久久久亚洲午夜电影| 日韩成人午夜电影| 制服丝袜激情欧洲亚洲| 亚洲第一狼人社区| 在线观看av不卡| 亚洲日本护士毛茸茸| 99久久久精品| 亚洲人成在线观看一区二区| 99久久伊人网影院| 最近日韩中文字幕| 色综合天天天天做夜夜夜夜做| 国产精品电影一区二区| 91在线视频在线| 一区二区三区精品在线| 欧亚一区二区三区| 亚洲国产精品人人做人人爽| 欧美人妖巨大在线| 天天色综合天天| 日韩一区二区三区高清免费看看| 日韩激情视频网站| 精品国产成人系列| 国产成人免费在线视频| 最新高清无码专区| 欧美日韩黄色影视| 日本不卡视频在线观看| 精品国产网站在线观看| 岛国一区二区在线观看| 中文字幕欧美一| 在线视频一区二区免费| 日韩福利电影在线| 久久久亚洲高清| 91丝袜美女网| 午夜免费欧美电影| 久久久精品2019中文字幕之3| eeuss鲁片一区二区三区在线看| 亚洲激情六月丁香| 日韩欧美久久久| 91在线精品一区二区三区| 亚洲图片自拍偷拍| 日韩视频一区二区三区在线播放| 国产激情视频一区二区在线观看| 国产精品久99| 日韩欧美一区二区免费| 成人综合日日夜夜| 亚洲成人免费观看| 国产日韩欧美综合一区| 欧美视频一二三区| 国产激情精品久久久第一区二区| 亚洲少妇30p| 日韩欧美在线网站| 91国内精品野花午夜精品| 青青草国产成人av片免费| 成人免费小视频| 欧美成人精品二区三区99精品| eeuss鲁一区二区三区| 久草这里只有精品视频| 老司机一区二区| 中文字幕精品在线不卡| 91精品国产麻豆| 91丨porny丨国产入口| 韩国在线一区二区| 亚洲不卡在线观看| 国产精品二三区| 久久免费看少妇高潮| 91精品欧美福利在线观看| 99国产精品久| 国产成人av福利| 六月婷婷色综合| 五月综合激情网| 一区二区三区四区不卡在线 | 欧美激情在线观看视频免费| 欧美精品一卡二卡| 99精品欧美一区二区三区小说| 激情欧美一区二区| 青青草91视频| 亚洲电影激情视频网站| 亚洲美女在线一区| 亚洲欧美一区二区三区久本道91 | 26uuu欧美| 日韩欧美一区二区免费| 91精品国产综合久久婷婷香蕉| 欧美四级电影网| 日本高清不卡视频| 91麻豆国产福利在线观看| 国产91富婆露脸刺激对白 | 香蕉av福利精品导航| 亚洲精品一二三区| 国产毛片精品视频| 美腿丝袜亚洲三区| 久久狠狠亚洲综合| 免费三级欧美电影| 日本欧美大码aⅴ在线播放| 亚洲va国产va欧美va观看| 亚洲综合久久久久| 亚洲午夜一二三区视频| 亚洲风情在线资源站| 亚洲综合激情另类小说区| 一区二区三区精品| 亚洲444eee在线观看| 日韩高清一区二区| 另类欧美日韩国产在线| 国产一区二区三区国产| 粉嫩嫩av羞羞动漫久久久 | 在线电影国产精品| 91精品视频网| 精品少妇一区二区| 久久久99久久| 中文字幕在线一区| 一区二区三区不卡在线观看| 五月天激情综合| 韩国精品在线观看| 成人精品小蝌蚪| 欧美中文一区二区三区| 日韩欧美色电影| 国产精品女同互慰在线看| 亚洲久草在线视频| 日韩成人免费看| 国产成人午夜视频| 91官网在线观看| 日韩欧美亚洲一区二区| 中文字幕成人av| 亚洲第一主播视频| 国产福利一区二区| 欧美系列一区二区| 久久综合久久综合亚洲| 综合激情成人伊人| 五月天一区二区三区| 国产盗摄女厕一区二区三区| 91免费观看视频在线| 欧美一区二区三区免费观看视频| 久久人人97超碰com| 亚洲国产视频直播| 国产乱国产乱300精品| 91国产免费看| 欧美国产一区二区| 午夜精品久久久久久久99水蜜桃 | 成人av在线资源网站| 777欧美精品| 国产精品第一页第二页第三页| 日韩电影一区二区三区四区| 北岛玲一区二区三区四区| 91麻豆精品国产91久久久久久久久 | 蜜桃91丨九色丨蝌蚪91桃色| 成人免费精品视频| 欧美一级日韩免费不卡| 国产精品久久久久久久岛一牛影视| 图片区小说区国产精品视频| 成人免费高清视频在线观看| 欧美一区欧美二区| 一区二区三区不卡视频| 国产电影精品久久禁18| 日韩欧美中文一区| 亚洲成va人在线观看| 91免费精品国自产拍在线不卡| 久久新电视剧免费观看| 日韩成人免费电影| 欧美色倩网站大全免费| 国产精品美女视频| 国产福利一区在线观看| 亚洲精品一线二线三线无人区| 五月天亚洲精品| 欧美午夜片在线看| 亚洲欧美日韩国产手机在线| 国产成人精品亚洲777人妖 | 一区二区三区在线视频免费观看| 国产精品一区二区无线| 久久众筹精品私拍模特| 久久国产剧场电影| 日韩免费成人网| 精品中文字幕一区二区| 欧美一区二区三区视频在线观看| 亚洲大尺度视频在线观看| 欧洲亚洲精品在线| 亚洲宅男天堂在线观看无病毒| 日韩欧美在线不卡| 黄网站免费久久| 久久婷婷综合激情| 成人中文字幕合集| 亚洲免费观看高清完整| 91国偷自产一区二区三区观看|