Artificial Intelligence - هوش مصنوعی

Artificial Intelligence - هوش مصنوعی (http://artificial.ir/intelligence/)
-   حل مسائل معروف هوش مصنوعي (http://artificial.ir/intelligence/forum102.html)
-   -   حل معماي 8 (8puzzle) به روش هاي مختلف (http://artificial.ir/intelligence/thread1195.html)

shadi67 ۰۱-۱۵-۱۳۹۰ ۰۹:۱۲ بعد از ظهر

سلام اگه امکان داره حل این برنامه رو با الگوریتم رقابت استعماری بذارید؟

mohammad.eshkiti ۰۱-۲۱-۱۳۹۰ ۰۷:۱۶ قبل از ظهر

puzzel 8
 
ba salam b dustaye azizam,,mikhastam khahesh konam darbare puzzel 8 ravesh haye mokhtalete algoritmesh moarefi va rahnami konid.ba tashakor

maryam20 ۰۱-۲۳-۱۳۹۰ ۱۱:۲۳ قبل از ظهر

8puzzle
 
salam.man halle 8puzzle be ravesh A* be zabane c++ mikham mamnoon misham age kesi dashte bashe

mz123 ۰۲-۷-۱۳۹۰ ۰۲:۱۵ بعد از ظهر

9puzzle
 
سلام دوستان
کسی هست که کد جاوای 9 پازل رو با روش ida* داشته باشه ؟
(9 پازل همون بازی 8پازلی است که خانه ی خالی ندارد و اعداد 1 تا 9 را شامل می شود)
تابع هیوریستیک اونو چه تابعی باید بگیرم؟
ممنون می شم اگه زودتر کسی جوابم رو بده

soodeh1010 ۰۲-۱۷-۱۳۹۰ ۰۵:۳۰ قبل از ظهر

سلام . عزیز چیزی که میخوای توی همین تاپیک هست اما بدون توضیح هست و من که کامپایل کردم error میده....

soodeh1010 ۰۲-۱۹-۱۳۹۰ ۰۵:۳۱ قبل از ظهر

سلام . لطفا بگین برنامه هایی که گذاشتین تو چه ورژنی اجرا میشه؟


كد:

#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <list>


typedef char puzzle_t[3][3];

puzzle_t _puzzle_start = { {1, 2, 3},
                          {4, 5, 6},
                          {7, 8, 0}
                        };
puzzle_t _puzzle_stop =        {  {1, 2, 3},
                          {4, 0, 5},
                          {6, 7, 8}
                        };
struct        context_t {
        std::list<puzzle_t*> abort_states;
        std::list<std::string> solution;
        int max_depth;
};


std::ostream& operator<<(std::ostream &s, const puzzle_t &p)
{
        for (int y=0; y<3; ++y)        {
                for (int x=0; x<3; ++x)        {
                        s << (int)p[y][x] << " ";
                }
                s << std::endl;
        }
        return s;
}

bool solver_rec(puzzle_t& start, const puzzle_t& stop, int y0, int x0, int depth, context_t &ctx)
{
        // enough CPU cycles wasted
        if (depth >= ctx.max_depth) return false;

        // is the actual start a abort state?
        for (std::list<puzzle_t*>::iterator it = ctx.abort_states.begin(); it != ctx.abort_states.end(); ++it)        {
                bool abort = true;
                for (int y=0; y<3; ++y)        {
                        for (int x=0; x<3; ++x)        {
                                if (start[y][x] != (**it)[y][x]) abort=false;
                        }
                }
                // this state will be checked by on of the parents, anyhow
                if (abort)        {
                        return false;
                }
        }
       
        // are we done?
        bool done = true;
        for (int yy=0; yy<3; ++yy)        {
                for (int xx=0; xx<3; ++xx)        {
                        if (start[yy][xx] != stop[yy][xx]) done= false;
                }
        }
        if (done) return true;

        // add this state to the list of abort states
        // it safe to push_front an stack objectpointer
        // as we remove it again before stack is unwinded
        // or never ever touch it again
        puzzle_t p;
        memcpy(p, start, sizeof(p));
        ctx.abort_states.push_front(&p);

        for (int yy=0; yy<3; ++yy)        {
                for (int xx=0; xx<3; ++xx)        {
                        // if the move is possible, take it
                        if (((yy+1 == y0) || (yy-1 == y0)) && (xx == x0))        {
                                std::swap(start[yy][xx], start[y0][xx]);
                                if (solver_rec(start, stop, yy, x0, depth+1, ctx))        {
                                        std::stringstream s;
                                        s << depth << ". tile  " << yy << "/" << x0;
                                        ctx.solution.push_back(s.str());
                                        return true;
                                }
                                std::swap(start[yy][xx], start[y0][xx]);
                        }
                        if (((xx+1 == x0) || (xx-1 == x0)) && (yy == y0))        {
                                std::swap(start[yy][x0], start[yy][xx]);
                                if (solver_rec(start, stop, y0, xx, depth+1, ctx))        {
                                        std::stringstream s;
                                        s << depth << ". tile " << y0 << "/" << xx;
                                        ctx.solution.push_back(s.str());
                                        return true;
                                }
                                std::swap(start[yy][x0], start[yy][xx]);
                        }
                }
        }
        // remove the abort state
        ctx.abort_states.pop_front();
        return false;
};

bool solver(puzzle_t& start, const puzzle_t& stop, int max_depth)       
{
        context_t ctx;
       
        // search for the 0 element
        int y0=-1, x0=-1;
        for (int y=0; y<3; ++y)        {
                for (int x=0; x<3; ++x)        {
                        if (start[y][x] == 0) {
                                y0 = y;
                                x0 = x;
                                break;
                        }
                }
        }
        assert(y0 != -1);
        assert(x0 != -1);
        // breath first search, assures that a shortest solution is found
        for (ctx.max_depth=0; ctx.max_depth<max_depth; ++(ctx.max_depth))        {
                if (solver_rec(start, stop, y0, x0, 1, ctx))        {
                        std::cout << "---SOLUTION---" << std::endl;
                        for (std::list<std::string>::reverse_iterator it = ctx.solution.rbegin(); it != ctx.solution.rend(); ++it)        {
                                std::cout << *it << std::endl;
                        }
                        return true;
                }
        }
        return false;
}

int main(int argc, char**argv)       
{
        // 3 argument == max_depth
        if (!solver(_puzzle_start, _puzzle_stop, 20))        {
                std::cout << "--- NO SOLUTION ---" << std::endl;
        }
        return 0;
}


يک سورس ديگر به c++[/QUOTE]

asal_12 ۰۲-۲۰-۱۳۹۰ ۰۹:۱۹ قبل از ظهر

سلام دوستان خوبید؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ ؟میشه برای من برنامه هشت پازل به روشa* به زبان ++cایمیل کنییییییییییییییید
خواهش میکنم دوستان

sahel_6432 ۰۲-۲۰-۱۳۹۰ ۰۶:۱۰ بعد از ظهر

سلام خدمت همه دوستان.من هم تازه واردم و هم چیزی از هوش مصنوعی نمیدونم.این ترم جزو واحدهای درسیمه.استادمون خواسته معمای 8 رو به روش دستی روی کاغذ براش حل کنیم و به بهترین جواب برسیم.آیا راهی یا فرمولی هست که از همون اول تشخیص بدیم روش درست چیه؟
ممنون از همه.:53:

yekta kh ۰۲-۲۲-۱۳۹۰ ۱۰:۲۲ قبل از ظهر

برنامه حل معمای پازل 8 را به روش *aمیخواستم خواهش میکنم اگه دارید تا حداکثر27 اردیبهشت به این آدرس ایمیل کنید khodadadi.elham@yahoo.com

hamidreza_kh ۰۲-۲۴-۱۳۹۰ ۰۳:۳۱ بعد از ظهر

كد:


//h_r_k_s@yahoo.com
//IDS code
#include <conio.h>
#include <iostream.h>

int g[10]={0,1,2,3,4,5,6,7,8,0};//goal
int s[10]={0,3,2,4,5,6,7,8,0,1};//initial state


void IDS(int,int,int);
void init(int [][5],int,int);
void succesor(int ,int );
int goalcheck();
int d=0;
int flag=0;
int arr[2][100];
int r=0;
int t;
void main()
{
        clrscr();
        int l=1;
        while(d==0)
        {
                IDS(1,1,l);
                if(flag==1)
                {
                        d=1;
                }
                l++;
        }
        l--;
        cout<<l;
        for(int i=0;i<t;i++)
        {
                cout<<"\n"<<arr[0][i]<<" "<<arr[1][i];
        }
        getch();
}
void IDS(int i,int j,int l)
{
        if(goalcheck()==1)
        {

                l=0;
                flag=1;
                t=r;
                return;
        }
        else if(l>0)
        {
                int sucarray[2][5];
                init(sucarray,j,i);
                int k=0;
                while(sucarray[0][k]!=-1 && flag!=1)
                {
                        succesor(sucarray[0][k],sucarray[1][k]);
                        arr[0][r]=sucarray[0][k];
                        arr[1][r]=sucarray[1][k];
                        r++;
                        IDS(sucarray[0][k],sucarray[1][k],l-1);
                        succesor(sucarray[0][k],sucarray[1][k]);
                        k++;
                        r--;
                }
                return;
        }
}
void init(int sucarray[][5],int a,int b)
{
        int i=1;
        while(s[i]!=0)
                i++;
        if(i==1)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i+1;//1:2
                sucarray[0][1]=i;
                sucarray[1][1]=i+3;//1:4
                sucarray[0][2]=-1;
        }else if(i==2)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i-1;//2:1
                sucarray[0][1]=i;
                sucarray[1][1]=i+1;//2:3
                sucarray[0][2]=i;
                sucarray[1][2]=i+3;//2:5
                sucarray[0][3]=-1;
        }else if(i==3)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i-1;//3:2
                sucarray[0][1]=i;
                sucarray[1][1]=i+3;//3:6
                sucarray[0][2]=-1;
        }else if(i==4)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i+1;//4:5
                sucarray[0][1]=i;
                sucarray[1][1]=i+3;//4:7
                sucarray[0][2]=i;
                sucarray[1][2]=i-3;//4:1
                sucarray[0][3]=-1;
        }else if(i==5)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i+1;//5:6
                sucarray[0][1]=i;
                sucarray[1][1]=i-1;//5:4
                sucarray[0][2]=i;
                sucarray[1][2]=i-3;//5:2
                sucarray[0][3]=i;
                sucarray[1][3]=i+3;//5:8
                sucarray[0][4]=-1;
        }else if(i==6)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i-3;//6:3
                sucarray[0][1]=i;
                sucarray[1][1]=i-1;//6:5
                sucarray[0][2]=i;
                sucarray[1][2]=i+3;//6:9
                sucarray[0][3]=-1;
        }else if(i==7)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i+1;//7:8
                sucarray[0][1]=i;
                sucarray[1][1]=i-3;//7:4
                sucarray[0][2]=-1;
        }else if(i==8)
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i-1;//8:7
                sucarray[0][1]=i;
                sucarray[1][1]=i+1;//8:9
                sucarray[0][2]=i;
                sucarray[1][2]=i-3;//8:5
                sucarray[0][3]=-1;
        }else
        {
                sucarray[0][0]=i;
                sucarray[1][0]=i-1;//9:8
                sucarray[0][1]=i;
                sucarray[1][1]=i-3;//9:6
                sucarray[0][2]=-1;
        }
        int k=0;
        while(sucarray[0][k]!=-1)
        {
                if(sucarray[1][k]==b)
                {
                        for(int v=k;v<4;v++)
                        {
                                sucarray[0][v]=sucarray[0][v+1];
                                sucarray[1][v]=sucarray[1][v+1];
                        }
                }
                k++;
        }
}
void succesor(int a,int b)
{
        int temp;
        temp=s[a];
        s[a]=s[b];
        s[b]=temp;
}
int goalcheck()
{
        for(int i=1;i<=9;i++)
        {
                if(s[i]!=g[i])
                        return -1;
        }
        return 1;
}



زمان محلي شما با تنظيم GMT +3.5 هم اکنون ۰۹:۵۴ قبل از ظهر ميباشد.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.