نمایش نتایج 1 تا 2 از 2

نام تاپیک: الگوریتم جارو برقی

  1. #1

    Unhappy الگوریتم جارو برقی

    سلام به همه دوستای گلم در سایت
    من خیلی خیلی فوری نیاز به این دارم که کد الگوریتم جارو برقی در ( هوش مصنوعی ) پیدا کنم . مهم نیست چه زبانی باشه . فقط پیاده سازی شده باشه .
    اگر کسی از دوستان این کد را داره خیلی ازش ممنون می شم که این کد رو بزاره .


  2. #2

    نقل قول: الگوریتم جارو برقی

    دوستان من خودم کد را نوشتم و براتون می زارم .



    #include<graphics.h>
    #include<conio.h>
    #include<string.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<dos.h>
    #include<time.h>

    #include<iostream.h>
    #include<conio.h>
    #include<graphics.h>
    #include<process.h>
    #include<math.h>
    #include<dos.h>

    void board (void);
    void piece_position ( int[8][8] );
    void place_pieces (int[8][8],int[8][8]);
    void king_status(int[8][8]); //STOP PAGE
    void rubber(int,int,int); //MOVE SHAY
    void messages (int); // MASSAGE
    void coordinate_manager(int*,int*); //MOGHEYAT MOHRE
    void draw_knight(int,int,int,int);
    void update_pawns(int[8][8],int,int,int,int,int);

    extern int turn = 0; //global variable


    int a[10][10];
    int direction;
    int left_right;
    int percept[3];
    int position[2];
    int side=1,row=1,cols=1,value=0;
    int x1,y1,x2,y2;
    //
    void direction4()
    {
    delay(200);
    setfillstyle(SOLID_FILL,LIGHTCYAN);
    setcolor(CYAN);
    fillellipse(x1+12,y1+22,3,3);
    fillellipse(x1+23,y1+22,8,4);
    fillellipse(x1+33,y1+22,2,8);
    putpixel(x1+25,y1+25,LIGHTCYAN);
    putpixel(x1+23,y1+24,1);
    putpixel(x1+24,y1+24,1);
    delay(200);
    };
    //***********
    void direction2()
    { delay(200);
    setfillstyle(SOLID_FILL,LIGHTCYAN);
    setcolor(CYAN);
    /* draw a filled ellipse */
    {
    fillellipse(x1+45,y1+22,3,3);
    fillellipse(x1+23,y1+22,4,8);
    fillellipse(x1+33,y1+22,8,2);
    }
    putpixel(x1+25,y1+25,LIGHTCYAN);
    putpixel(x1+23,y1+24,1);
    putpixel(x1+24,y1+24,1);
    delay(200);
    };
    void direction3()
    { delay(200);
    setfillstyle(SOLID_FILL,LIGHTCYAN);
    setcolor(CYAN);

    fillellipse(x1+31,y1+33,3,3);
    fillellipse(x1+31,y1+11,8,4);
    fillellipse(x1+31,y1+23,2,8);
    putpixel(x1+25,y1+25,LIGHTCYAN);
    putpixel(x1+23,y1+24,1);
    putpixel(x1+24,y1+24,1);

    delay(200);
    }
    void direction1()
    { delay(200);
    setfillstyle(SOLID_FILL,LIGHTCYAN);
    setcolor(CYAN);

    fillellipse(x1+22,y1+12,3,3);
    fillellipse(x1+22,y1+23,4,8);
    fillellipse(x1+22,y1+33,8,2);
    putpixel(x1+25,y1+25,LIGHTCYAN);
    putpixel(x1+23,y1+24,1);
    putpixel(x1+24,y1+24,1);
    delay(200);
    }
    int move( )
    {
    if(percept[2]==1)
    {
    if (direction==1 )
    { row=row-1; y1=y1-50; x1=x1; direction1(); }
    if (direction==2)
    { cols=cols+1; x1=x1+50;y1=y1; direction2(); }
    if (direction==3)
    {row=row+1; y1=y1+50; x1=x1; direction3(); }
    if (direction==4 )
    {cols=cols-1; x1=x1-50; y1=y1; direction4(); }
    percept[1]=a[row][cols];
    value--;


    //*********
    if (direction==1 )
    {

    if(a[row-1][cols]==-1)
    percept[2]=0;
    else
    percept[2]=1;


    }
    if (direction==2 )
    {
    if(a[row][cols+1]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    }
    if (direction==3)
    {
    if(a[row+1][cols]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    }
    if (direction==4)
    {

    if(a[row][cols-1]==-1)
    percept[2]=0;
    else
    percept[2]=1;

    }

    ///*******
    }
    return 0;
    }

    int rotat ()
    {
    int f;
    float t;
    f=rand();
    t=(float) f/RAND_MAX;
    if (t<0.5)
    left_right=1;
    else
    left_right=0;

    if(left_right==1)
    {
    if (direction==1 )
    { direction2();
    direction=2;
    if(a[row][cols+1]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    if (direction==2)
    { direction3();
    direction=3;
    if(a[row+1][cols]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    if (direction==3)
    { direction=4; direction4();
    if(a[row][cols-1]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    if (direction==4 )
    {
    direction=1; direction1();
    if(a[row-1][cols]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    }
    if(left_right==0)
    {
    if (direction==1 )
    { direction=4; direction4();
    if(a[row][cols-1]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    if (direction==2)
    {
    direction=1; direction1();
    if(a[row-1][cols]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    if (direction==3)
    {
    direction=2; direction2();
    if(a[row][cols+1]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    if (direction==4 )
    {
    direction=3; direction3();
    if(a[row+1][cols]==-1)
    percept[2]=0;
    else
    percept[2]=1;
    return 0;
    }
    }

    return 0;
    }
    int suck()
    { setcolor(BLUE);
    x2=x1+18; y2=y1+22;
    delay(200);
    char num[3];
    num[1]='\0';
    if (percept[1]==1)
    {
    percept[1]=0;
    a[row][cols]=0;
    num[0]='0';
    outtextxy(x2,y2,num);
    value=value+100;
    return -1;
    }
    delay(200);
    return 0;
    }
    int do_agent()
    {

    if (percept[1]==1)
    { messages ( 1 );
    setcolor(RED);
    outtextxy(100,20,"...suck.....");
    setcolor(YELLOW);
    suck();
    return 1;
    }
    if (percept[2]==1 )
    { messages ( 0 );
    setcolor(YELLOW);
    outtextxy(10,20,"...mov...");
    move();
    if(row==1&cols==1)
    percept[0]=1;
    else
    percept[0]=0;
    if (percept[0]==1)
    {
    printf("\nvalue= %d ",value);
    delay(5000);
    exit(1);
    return 1;
    }
    return 3;
    }
    if (percept[2]==0)
    {
    messages ( 2 );
    setcolor(RED);
    outtextxy(150,20,"...rotate...");
    rotat (); return 2;
    }


    return 0;
    }


    //**************
    void setvalue()
    {
    int j=120;
    int i=75;
    char num[3],color[1];
    num[1]='\0';
    int k;
    k=1;
    setcolor(RED);
    //****** row1 *********
    num[0]='1'; a[k][1]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][2]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][3]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][4]=0;
    outtextxy(j,i,num);
    j=j+50; a[k][5]=0;
    num[0]='0';
    outtextxy(j,i,num);
    j=j+50;
    num[0]='-'; num[1]='1'; num[2]='\0'; a[k][6]=-1;
    outtextxy(j,i,num);
    num[1]='\0';
    j=j+50;
    num[0]='1'; a[k][7]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //***********
    //****row2***********
    k=2;;
    i=125; j=120;
    num[0]='0'; a[k][1]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][2]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][3]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][4]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][5]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='-'; num[1]='1'; num[2]='\0'; a[k][6]=-1;
    outtextxy(j,i,num);
    j=j+50;
    num[1]='\0';
    num[0]='0'; a[k][7]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    //***********
    //****row3***********
    k=3;
    i=175; j=120;
    num[0]='0'; a[k][1]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][2]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][3]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][4]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][5]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][6]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][7]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][8]=0;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    //***********
    //****row4***********
    k=4;
    i=225; j=120;
    num[0]='0'; a[k][1]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][2]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][3]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][4]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][5]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='-'; num[1]='1'; num[2]='\0'; a[k][6]=-1;
    outtextxy(j,i,num);
    j=j+50;
    num[1]='\0';
    num[0]='-'; num[1]='1'; num[2]='\0'; a[k][7]=-1;
    outtextxy(j,i,num);
    j=j+50;
    num[1]='\0';
    num[0]='1';
    a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    //***********
    //****row5***********
    k=5;
    i=275; j=120;
    num[0]='0'; a[k][1]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][2]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][3]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][4]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][5]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][6]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][7]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    //***********
    //****row6***********
    k=6;
    i=325; j=120;
    num[0]='1'; a[k][1]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][2]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][3]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][4]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][5]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][6]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][7]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    //***********
    //****row7***********
    k=7;
    i=375; j=120;
    num[0]='1'; a[k][1]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][2]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][3]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='0'; a[k][4]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='-'; num[1]='1'; num[2]='\0'; a[k][5]=-1;
    outtextxy(j,i,num);
    j=j+50;
    num[1]='\0';
    num[0]='0'; a[k][6]=0;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][7]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    //***********
    //****row8***********
    k=8;
    i=425; j=120;
    num[0]='1'; a[k][1]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][2]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][3]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][4]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][5]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][6]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][7]=1;
    outtextxy(j,i,num);
    j=j+50;
    num[0]='1'; a[k][8]=1;
    outtextxy(j,i,num);
    j=j+50;
    //******************
    }
    void main()
    {
    //**************************
    clrscr();
    int gdriver = DETECT, gmode;
    initgraph (&gdriver, &gmode, "C:\\TC\\BGI"); //starting graphics engine

    x1=50; y1=50;

    srand( (unsigned)time( NULL ) );
    for (int i=0;i<10;i++) a[0][i]=-1;
    for ( i=0;i<10;i++) a[9][i]=-1;
    for ( i=0;i<10;i++) a[i][0]=-1;
    for ( i=0;i<10;i++) a[i][9]=-1;


    board ();
    setvalue();
    direction=2;
    direction2();
    delay(3000);
    clearviewport();
    board ();
    setvalue();
    x1=100; y1=50;
    setvalue();
    direction=2;
    direction2();
    //*****
    setfillstyle(WIDE_DOT_FILL,BLUE);
    /* draw the 3-d bar */
    bar3d(220,8, 222+205,8+15, 5, 1);
    setcolor(YELLOW);
    outtextxy(240,8,"nabi & daneale & nazari");
    //Draws 64 Blocks of the chess board and fills them
    setcolor(LIGHTBLUE);

    //*******
    row=cols=1;
    percept[0]=1;
    percept[1]=a[row][cols];
    percept[2]=1;

    char stop='1';
    printf("** for stop presh 'e' ** ");
    while(stop!='e')
    {
    do_agent();
    stop=getch();
    }
    printf("\n value= %d",value);
    delay(3000);
    getch();

    }
    //*********************

    void board (void)
    {
    clrscr();
    //************************
    //************************
    setfillstyle(SOLID_FILL,LIGHTGREEN); //colours the
    floodfill(320,240,2); //background
    setlinestyle (SOLID_LINE,5,THICK_WIDTH); //for thick edge of the board
    setcolor(BLACK);
    int x1=100,y1=50,x2=150,y2=100;
    for (int j=1; j <= 8; j++)
    {
    for (int i=1; i <= 8; i++)
    {
    rectangle(x1,y1,x2,y2);
    setfillstyle (SOLID_FILL, BLACK);
    x1 += 50;
    x2 += 50;
    }
    x1 = 100;
    x2 = 150;
    y1 += 50;
    y2 += 50;
    }
    setcolor(WHITE);
    setlinestyle (SOLID_LINE,1,THICK_WIDTH);
    setfillstyle (SOLID_FILL, BLACK); //draws the
    // rectangle (481,21,570,100);
    rectangle (510,21,630,100); //message window
    floodfill (550,25,WHITE);
    setlinestyle (SOLID_LINE,1,NORM_WIDTH);
    }

    void messages ( int msgid )
    {
    gotoxy (65,1);
    cout<<"JARO BARGHI";
    gotoxy (63,4);
    switch ( msgid )
    {
    case 0: gotoxy(65,4);
    cout<<" MOVE ";
    break;
    case 1: gotoxy(65,4);
    cout<<" SUCK ";
    break;
    case 2: gotoxy(65,4);
    cout<<" ROTEAT ";
    break;
    }//end of switch
    }//end of msgind function
    //


برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •