<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[انجمن های تخصصی علوم رایانه و هنرهای دیجیتال - حل تمرین و مسئله های هوش مصنوعی]]></title>
		<link>https://www.forum.cgaria.com/</link>
		<description><![CDATA[انجمن های تخصصی علوم رایانه و هنرهای دیجیتال - https://www.forum.cgaria.com]]></description>
		<pubDate>Sun, 20 Sep 2026 21:47:11 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[کد معمای 8 با الگوریتم ژنتیک در سی شارپ]]></title>
			<link>https://www.forum.cgaria.com/thread-691.html</link>
			<pubDate>Fri, 23 Jan 2015 02:06:57 +0330</pubDate>
			<dc:creator><![CDATA[<a href="https://www.forum.cgaria.com/member.php?action=profile&uid=5">Mohsen Omidvar</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.forum.cgaria.com/thread-691.html</guid>
			<description><![CDATA[<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">معمای 8  یا  پازل 8-puzzle</span></span></span></span></span></span><br />
<br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">دوستانی که در  رشته های کامپیوتر، فناوری اطلاعات و هوش مصنوعی تحصیل می کنند حتما با <span style="font-weight: bold;" class="mycode_b">بازی پازل 8</span> آشنایی  دارند. این بازی  تقریبا پای ثابت اکثر معماها در آموزش ابتدایی  هوش مصنوعی است.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">این معما از یک جدول 3 در 3 تشکیل شده است که می شود 9 خانه.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">حالا در این جدول اعداد یک تا هشت قرار می گیرند و همچنین یکی از خانه ها خالی است.این معما شامل حالت اولیه و حالت نهایی است که باید به آن برسیم.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">حالت اولیه :</span></span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">در این حالت اعداد می توانند به هر ترتیبی در جدول قرار گیرند.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">حالت نهایی :</span></span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">حالتی است که از ما می خواهند به آن برسیم و این کار با حرکت خانه خالی میسر می شود. و باید از طریق قوانین زیر به آن رسید:</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">1- اگر سمت چپ خانه خالي ، عدد باشد حرکت خانه خالي به سمت چپ</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">2- اگر سمت راست خانه خالي ، عدد باشد حرکت خانه خالي به سمت راست</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">3- اگر سمت بالا خانه خالي ، عدد باشد حرکت خانه خالي به سمت بالا</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">4- اگر سمت پايين خانه خالي ، عدد باشد حرکت خانه خالي به سمت پايين</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"> </span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size">الگوریتم های متعددی برای این کار وجود دارد که یکی از آنها <span style="font-weight: bold;" class="mycode_b">الگوریتم ژنتیک </span>است.که در واقع این برنامه توسط این الگوریتم هوش مصنوعی و زبان برنامه نویسی سی شارپ پیاده سازی شده است.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"> </span></span></span><br />
<div class="codeblock"><div class="title">کد: </div><div class="body" dir="ltr"><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace _8
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }
       int[,] first = new int[3, 3];
       int[,] final = new int[3, 3];
       int[, ,] temp = new int[3, 3, 10000];
       string[] tempstaus = new string[10000];
       int[,] realtemp = new int[3, 3];
       int[,] qu = new int[3, 10000];

       private void showtemp(int qun)        
       {
           string s = "";
           listBox2.Items.Clear();
           for (int i = 0; i &lt;= qun; i++)
           {
               for (int j = 0; j &lt; 3; j++)
               {
                   for (int k = 0; k &lt; 3; k++)
                   {                        
                       s += temp[j, k, i].ToString() + "  ";                        
                   }
                   listBox2.Items.Add(s);
                   s = "";
               }
               listBox2.Items.Add(tempstaus[i]);
               listBox2.Items.Add("=====================");    
               
           }

       
       }
       private void insertff()
       {
           first[0, 0] = Convert.ToInt32(textBox1.Text);
           first[0, 1] = Convert.ToInt32(textBox2.Text);
           first[0, 2] = Convert.ToInt32(textBox3.Text);
           first[1, 0] = Convert.ToInt32(textBox4.Text);
           first[1, 1] = Convert.ToInt32(textBox5.Text);
           first[1, 2] = Convert.ToInt32(textBox6.Text);
           first[2, 0] = Convert.ToInt32(textBox7.Text);
           first[2, 1] = Convert.ToInt32(textBox8.Text);
           first[2, 2] = Convert.ToInt32(textBox9.Text);
           final[0, 0] = Convert.ToInt32(textBox18.Text);
           final[0, 1] = Convert.ToInt32(textBox17.Text);
           final[0, 2] = Convert.ToInt32(textBox16.Text);
           final[1, 0] = Convert.ToInt32(textBox15.Text);
           final[1, 1] = Convert.ToInt32(textBox14.Text);
           final[1, 2] = Convert.ToInt32(textBox13.Text);
           final[2, 0] = Convert.ToInt32(textBox12.Text);
           final[2, 1] = Convert.ToInt32(textBox11.Text);
           final[2, 2] = Convert.ToInt32(textBox10.Text);
       }
       private int h1(int n)
       {
           int h = 0;
           for (int i = 0; i &lt; 3; i++)
               for (int j = 0; j &lt; 3; j++)
                   if (temp[i, j, n] != final[i, j])
                   {
                       if(temp[i, j, n] !=0)
                       h++;
                   }
           int x=0;
           foreach(char  s in tempstaus[n])
                if (s == '/')
                   x++;

    
               return h+x ;
       }
       private void run()
       {
           #region first node
           for (int i = 0; i &lt; 3; i++)
               for (int j = 0; j &lt; 3; j++)
                   temp[i, j, 0] = first[i, j];
           tempstaus[0] = "0";
           int qun = 0;
           qu[0, qun] = qun ;
           qu[1, qun] = h1(qun);
           qu[2, qun] = 0;
           listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
           Application.DoEvents();
#endregion
           while (true)
           {
                   int min=0;
                   int minmain = 0;
               for (int i = 0; i &lt;= qun ; i++)// peyda kardane avvalin onsore peymude nashode
               {
                   if(qu[2,i]==0)
                   {
                       min = qu[1, i];
                       minmain = i;
                       break;
                   }
               }
            for (int i = 0; i &lt;= qun; i++)// peyda kardane kuchiktarin onsor
               {
                   if (qu[1, i] &lt; min &amp;&amp; qu[2, i]==0)
                   {
                       min = qu[1, i];
                       minmain = i;
                   }
               }
              // MessageBox.Show("min= " + min.ToString() + "  minmain =  " + minmain.ToString() + "  qun=" + qun.ToString());

               int r=0, c=0;
               for (int i = 0; i &lt; 3; i++)//peyda kardane khune khali
                   for (int j = 0; j &lt; 3; j++)
                       if (temp[i, j, minmain] == 0)
                       {
                           r = i;
                           c = j;
                           break;                       
                       }
               for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                   for (int j = 0; j &lt; 3; j++)
                       realtemp[i, j] = temp[i, j, minmain];
             // MessageBox.Show(minmain.ToString());
               qu[2, minmain] = 1;
               /////////////////////////////////////////////tolide farzandan////////////////////////////////////////////////
               showtemp(qun);
               int x = 0;
               foreach (char s in tempstaus[minmain ])
                   if (s == '/')
                       x++;
               if (h1(minmain)-x  == 0)
               {
                   MessageBox.Show("found !!!     masir  = "+tempstaus[minmain].ToString());
                   break;
               }
               #region  tolide farzand
               //===================================check resltemp != jadd===================================

               //-----------------l
               if (c &gt; 0)
               {
                   qun++;
                   realtemp[r, c] = realtemp[r, c - 1];
                   realtemp[r, c - 1]=0;
                   tempstaus[qun] =tempstaus[minmain]+ "/left";
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
               //-----------------r
               if (c &lt; 2)
               {
                   for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                       for (int j = 0; j &lt; 3; j++)
                           realtemp[i, j] = temp[i, j, minmain];
                   qun++;
                   realtemp[r, c] = realtemp[r, c+1];
                   realtemp[r, c+ 1] = 0;
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   tempstaus[qun] = tempstaus[minmain] + "/right";
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
               //-----------------up
               if (r&gt;0)
               {
                   for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                       for (int j = 0; j &lt; 3; j++)
                           realtemp[i, j] = temp[i, j, minmain];
                   qun++;
                   realtemp[r, c] = realtemp[r-1, c ];
                   realtemp[r-1, c ] = 0;
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   tempstaus[qun] = tempstaus[minmain] + "/up";
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
               //-----------------down
               if (r &lt; 2)
               {
                   for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                       for (int j = 0; j &lt; 3; j++)
                           realtemp[i, j] = temp[i, j, minmain];
                   qun++;
                   realtemp[r, c] = realtemp[r + 1, c];
                   realtemp[r + 1, c] = 0;
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   tempstaus[qun] = tempstaus[minmain] + "/down";
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
#endregion
           }
       }
       private void button1_Click(object sender, EventArgs e)
       {
           listBox1.Items.Clear();
           listBox2.Items.Clear();
           insertff();
           run();
       }
       private void button2_Click(object sender, EventArgs e)
       {
           System.Diagnostics.Process.Start("http://www.sourcecodes.ir");
       }

   }
}</code></div></div>]]></description>
			<content:encoded><![CDATA[<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">معمای 8  یا  پازل 8-puzzle</span></span></span></span></span></span><br />
<br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">دوستانی که در  رشته های کامپیوتر، فناوری اطلاعات و هوش مصنوعی تحصیل می کنند حتما با <span style="font-weight: bold;" class="mycode_b">بازی پازل 8</span> آشنایی  دارند. این بازی  تقریبا پای ثابت اکثر معماها در آموزش ابتدایی  هوش مصنوعی است.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">این معما از یک جدول 3 در 3 تشکیل شده است که می شود 9 خانه.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">حالا در این جدول اعداد یک تا هشت قرار می گیرند و همچنین یکی از خانه ها خالی است.این معما شامل حالت اولیه و حالت نهایی است که باید به آن برسیم.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">حالت اولیه :</span></span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">در این حالت اعداد می توانند به هر ترتیبی در جدول قرار گیرند.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">حالت نهایی :</span></span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">حالتی است که از ما می خواهند به آن برسیم و این کار با حرکت خانه خالی میسر می شود. و باید از طریق قوانین زیر به آن رسید:</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">1- اگر سمت چپ خانه خالي ، عدد باشد حرکت خانه خالي به سمت چپ</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">2- اگر سمت راست خانه خالي ، عدد باشد حرکت خانه خالي به سمت راست</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">3- اگر سمت بالا خانه خالي ، عدد باشد حرکت خانه خالي به سمت بالا</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font">4- اگر سمت پايين خانه خالي ، عدد باشد حرکت خانه خالي به سمت پايين</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"> </span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"><span style="font-family: tahoma, geneva, sans-serif;" class="mycode_font"><span style="font-size: small;" class="mycode_size">الگوریتم های متعددی برای این کار وجود دارد که یکی از آنها <span style="font-weight: bold;" class="mycode_b">الگوریتم ژنتیک </span>است.که در واقع این برنامه توسط این الگوریتم هوش مصنوعی و زبان برنامه نویسی سی شارپ پیاده سازی شده است.</span></span></span></span></span><br />
<span style="color: #000000;" class="mycode_color"><span style="font-size: x-small;" class="mycode_size"><span style="font-family: Tahoma, Geneva, sans-serif;" class="mycode_font"> </span></span></span><br />
<div class="codeblock"><div class="title">کد: </div><div class="body" dir="ltr"><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace _8
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }
       int[,] first = new int[3, 3];
       int[,] final = new int[3, 3];
       int[, ,] temp = new int[3, 3, 10000];
       string[] tempstaus = new string[10000];
       int[,] realtemp = new int[3, 3];
       int[,] qu = new int[3, 10000];

       private void showtemp(int qun)        
       {
           string s = "";
           listBox2.Items.Clear();
           for (int i = 0; i &lt;= qun; i++)
           {
               for (int j = 0; j &lt; 3; j++)
               {
                   for (int k = 0; k &lt; 3; k++)
                   {                        
                       s += temp[j, k, i].ToString() + "  ";                        
                   }
                   listBox2.Items.Add(s);
                   s = "";
               }
               listBox2.Items.Add(tempstaus[i]);
               listBox2.Items.Add("=====================");    
               
           }

       
       }
       private void insertff()
       {
           first[0, 0] = Convert.ToInt32(textBox1.Text);
           first[0, 1] = Convert.ToInt32(textBox2.Text);
           first[0, 2] = Convert.ToInt32(textBox3.Text);
           first[1, 0] = Convert.ToInt32(textBox4.Text);
           first[1, 1] = Convert.ToInt32(textBox5.Text);
           first[1, 2] = Convert.ToInt32(textBox6.Text);
           first[2, 0] = Convert.ToInt32(textBox7.Text);
           first[2, 1] = Convert.ToInt32(textBox8.Text);
           first[2, 2] = Convert.ToInt32(textBox9.Text);
           final[0, 0] = Convert.ToInt32(textBox18.Text);
           final[0, 1] = Convert.ToInt32(textBox17.Text);
           final[0, 2] = Convert.ToInt32(textBox16.Text);
           final[1, 0] = Convert.ToInt32(textBox15.Text);
           final[1, 1] = Convert.ToInt32(textBox14.Text);
           final[1, 2] = Convert.ToInt32(textBox13.Text);
           final[2, 0] = Convert.ToInt32(textBox12.Text);
           final[2, 1] = Convert.ToInt32(textBox11.Text);
           final[2, 2] = Convert.ToInt32(textBox10.Text);
       }
       private int h1(int n)
       {
           int h = 0;
           for (int i = 0; i &lt; 3; i++)
               for (int j = 0; j &lt; 3; j++)
                   if (temp[i, j, n] != final[i, j])
                   {
                       if(temp[i, j, n] !=0)
                       h++;
                   }
           int x=0;
           foreach(char  s in tempstaus[n])
                if (s == '/')
                   x++;

    
               return h+x ;
       }
       private void run()
       {
           #region first node
           for (int i = 0; i &lt; 3; i++)
               for (int j = 0; j &lt; 3; j++)
                   temp[i, j, 0] = first[i, j];
           tempstaus[0] = "0";
           int qun = 0;
           qu[0, qun] = qun ;
           qu[1, qun] = h1(qun);
           qu[2, qun] = 0;
           listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
           Application.DoEvents();
#endregion
           while (true)
           {
                   int min=0;
                   int minmain = 0;
               for (int i = 0; i &lt;= qun ; i++)// peyda kardane avvalin onsore peymude nashode
               {
                   if(qu[2,i]==0)
                   {
                       min = qu[1, i];
                       minmain = i;
                       break;
                   }
               }
            for (int i = 0; i &lt;= qun; i++)// peyda kardane kuchiktarin onsor
               {
                   if (qu[1, i] &lt; min &amp;&amp; qu[2, i]==0)
                   {
                       min = qu[1, i];
                       minmain = i;
                   }
               }
              // MessageBox.Show("min= " + min.ToString() + "  minmain =  " + minmain.ToString() + "  qun=" + qun.ToString());

               int r=0, c=0;
               for (int i = 0; i &lt; 3; i++)//peyda kardane khune khali
                   for (int j = 0; j &lt; 3; j++)
                       if (temp[i, j, minmain] == 0)
                       {
                           r = i;
                           c = j;
                           break;                       
                       }
               for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                   for (int j = 0; j &lt; 3; j++)
                       realtemp[i, j] = temp[i, j, minmain];
             // MessageBox.Show(minmain.ToString());
               qu[2, minmain] = 1;
               /////////////////////////////////////////////tolide farzandan////////////////////////////////////////////////
               showtemp(qun);
               int x = 0;
               foreach (char s in tempstaus[minmain ])
                   if (s == '/')
                       x++;
               if (h1(minmain)-x  == 0)
               {
                   MessageBox.Show("found !!!     masir  = "+tempstaus[minmain].ToString());
                   break;
               }
               #region  tolide farzand
               //===================================check resltemp != jadd===================================

               //-----------------l
               if (c &gt; 0)
               {
                   qun++;
                   realtemp[r, c] = realtemp[r, c - 1];
                   realtemp[r, c - 1]=0;
                   tempstaus[qun] =tempstaus[minmain]+ "/left";
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
               //-----------------r
               if (c &lt; 2)
               {
                   for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                       for (int j = 0; j &lt; 3; j++)
                           realtemp[i, j] = temp[i, j, minmain];
                   qun++;
                   realtemp[r, c] = realtemp[r, c+1];
                   realtemp[r, c+ 1] = 0;
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   tempstaus[qun] = tempstaus[minmain] + "/right";
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
               //-----------------up
               if (r&gt;0)
               {
                   for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                       for (int j = 0; j &lt; 3; j++)
                           realtemp[i, j] = temp[i, j, minmain];
                   qun++;
                   realtemp[r, c] = realtemp[r-1, c ];
                   realtemp[r-1, c ] = 0;
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   tempstaus[qun] = tempstaus[minmain] + "/up";
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
               //-----------------down
               if (r &lt; 2)
               {
                   for (int i = 0; i &lt; 3; i++) // enteghal tempe morede nazar be tempreal
                       for (int j = 0; j &lt; 3; j++)
                           realtemp[i, j] = temp[i, j, minmain];
                   qun++;
                   realtemp[r, c] = realtemp[r + 1, c];
                   realtemp[r + 1, c] = 0;
                   for (int i = 0; i &lt; 3; i++)
                       for (int j = 0; j &lt; 3; j++)
                           temp[i, j, qun] = realtemp[i, j];
                   tempstaus[qun] = tempstaus[minmain] + "/down";
                   qu[0, qun] = qun;
                   qu[1, qun] = h1(qun);
                   qu[2, qun] = 0;
                   listBox1.Items.Add(qu[0, qun].ToString() + "         h1= " + qu[1, qun].ToString() + "       " + tempstaus[qun]);
                   Application.DoEvents();
               }
#endregion
           }
       }
       private void button1_Click(object sender, EventArgs e)
       {
           listBox1.Items.Clear();
           listBox2.Items.Clear();
           insertff();
           run();
       }
       private void button2_Click(object sender, EventArgs e)
       {
           System.Diagnostics.Process.Start("http://www.sourcecodes.ir");
       }

   }
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[مسئله فروشنده دوره‌گرد (Travelling salesman problem : TSP )]]></title>
			<link>https://www.forum.cgaria.com/thread-666.html</link>
			<pubDate>Fri, 12 Dec 2014 19:39:12 +0330</pubDate>
			<dc:creator><![CDATA[<a href="https://www.forum.cgaria.com/member.php?action=profile&uid=5">Mohsen Omidvar</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.forum.cgaria.com/thread-666.html</guid>
			<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
		</item>
	</channel>
</rss>