check home phone-call search send

سورس کد پروژه Maze به زبان سی پلاس پلاس

سورس کد پروژه Maze به زبان سی پلاس پلاسسورس کد پروژه Maze به زبان سی پلاس پلاس

در این پست سورس کد پروژه Maze به زبان سی پلاس پلاس را برایتان آماده کرده ایم.این پروژه به زبان سی پلاس پلاس برنامه نویسی شده است که جنبه آموزشی و سرگرمی دارد و می توانید به عنوان یک پروژه آموزشی از آن استفاده کنیم.بعلاوه می توانید سورس کد پروژه حقوق و دستمزد به زبان سی پلاس پلاس را نیز از سایت دریافت کنید.

//This Program Makes In Borland C++ Builder 2002
//Mazing Program
//By Mahmoud Nadim
//As DAT.HW#1
#pragma hdrstop
#pragma argsused


#define MAX_SIZE 100
#include <stdio.h>
#include <stdlib.h>
typedef struct
        {
                int row;
                int col;
                char dir;
                char last_choice;
        }element;
element Stack[MAX_SIZE];
int top=-1;
int *ptop=&top;

//These variables Define The Status Of Move
//For Example -> Moeve Is left_right and is described as *lr Pointer
int right_left=0;
int left_right=0;
int top_down=0;
int down_top=0;
int *rl=&right_left;
int *lr=&left_right;
int *td=&top_down;
int *dt=&down_top;

int i_kol,j_kol;
int *i=&i_kol;
int *j=&j_kol;


int kol[16][16]={ //Maze Starts FROM kol[1][1] AND Ends To kol[14[14]
                  {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                  {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1},
                  {1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1},
                  {1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1},
                  {1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1},
                  {1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1},
                  {1,0,1,1,1,0,1,1,1,1,1,0,1,1,0,1},
                  {1,0,1,1,1,0,0,0,0,1,1,0,1,1,0,1},
                  {1,0,1,1,1,0,1,1,0,0,0,0,1,1,1,1},
                  {1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1},
                  {1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1},
                  {1,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1},
                  {1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1},
                  {1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1},
                  {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                  {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
                };

//Definition : Function 1
void Add_To_Stack(char l_dir)
{
 if (*ptop>=MAX_SIZE)
        {
                printf("The Stack Is Full");
        }
 else
        {
            if (((*i)==Stack[*ptop].row)&&((*j)==Stack[*ptop].col)) return;
                (*ptop)++;
                Stack[*ptop].row=*i;
                Stack[*ptop].col=*j;
                Stack[*ptop].last_choice='a';
                Stack[*ptop].dir=l_dir;
                printf("Added To Stack");
        }
}

//Definition : Function 2
element Delete_From_Stack(void)
{
        if (*ptop<0)
                printf("The Stack Is Empty");
        else
                {
                        element d1;
                        d1.row=Stack[*ptop].row;
                        d1.col=Stack[*ptop].col;
                        d1.last_choice=Stack[*ptop].last_choice;
                        (*ptop)--;
                        return d1;
                }
}


//Definition : Function 3
//This Functin Check That If In The Current Cell  We Have More Than One Choice To Seek The Goal
//If In This Cell We Have More Than One Choice Store This Item(Cell) In Stack Else Exit And Return 0
int Check_Cell_For_Stack(int add_to_stack)
{
        if (  (*lr) && (  ( kol[*i][*j+1]==0 && kol[*i-1][*j]==0 ) || ( kol[*i][*j+1]==0 && kol[*i+1][*j]==0 ) || ( kol[*i-1][*j]==0 && kol[*i+1][*j]==0 ) || ( kol[*i-1][*j]==0 && kol[*i][*j+1]==0 && kol[*i+1][*j]==0 )  )    )
                {
                        if (add_to_stack==1) {Add_To_Stack('r');  }
                        return 1;
                }
        if (  (*rl) && (  ( kol[*i][*j-1]==0 && kol[*i-1][*j]==0 ) || ( kol[*i][*j-1]==0 && kol[*i+1][*j]==0 ) || ( kol[*i-1][*j]==0 && kol[*i+1][*j]==0 ) || ( kol[*i-1][*j]==0 && kol[*i][*j-1]==0 && kol[*i+1][*j]==0 )  )    )
                {
                        if (add_to_stack==1) {Add_To_Stack('l'); }
                        return 1;
                }
        if (  (*td) && (  ( kol[*i][*j+1]==0 && kol[*i+1][*j]==0 ) || ( kol[*i][*j+1]==0 && kol[*i][*j-1]==0 ) || ( kol[*i][*j-1]==0 && kol[*i+1][*j]==0 ) || ( kol[*i+1][*j]==0 && kol[*i][*j+1]==0 && kol[*i][*j-1]==0 )  )    )
                {
                        if (add_to_stack==1) {Add_To_Stack('d');}
                        return 1;
                }
        if (  (*dt) && (  ( kol[*i][*j+1]==0 && kol[*i-1][*j]==0 ) || ( kol[*i][*j+1]==0 && kol[*i][*j-1]==0 ) || ( kol[*i][*j+1]==0 && kol[*i][*j-1]==0 ) || ( kol[*i-1][*j]==0 && kol[*i][*j+1]==0 && kol[*i][*j-1]==0 )  )    )
                {
                        if (add_to_stack==1) {Add_To_Stack('t'); }
                        return 1;
                }
        return 0;
}


//Definition : Fuction 4
//This Function Calls When A Cell Has More Than One Choice AND The Possible Choices
//Goes To The Next Cell From Choices That We Have   According To The *td,*dt,*tl,*lr
void Choose_Choice()
{

        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i-1][*j]==0)&& (Stack[*ptop].dir=='r') ) {Stack[*ptop].last_choice='t'; (*i)--; *dt=1; *td=0; *lr=0; *rl=0;   return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i][*j+1]==0)&& (Stack[*ptop].dir=='r') ) {Stack[*ptop].last_choice='r'; (*j)++; *dt=0; *td=0; *lr=1; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i+1][*j]==0)&& (Stack[*ptop].dir=='r') ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return; }
        if ( (Stack[*ptop].last_choice=='t')&&(kol[*i][*j+1]==0)&&( (Stack[*ptop].dir=='r')) ) {Stack[*ptop].last_choice='r'; (*j)++; *dt=0; *td=0; *lr=1; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='t')&&(kol[*i][*j+1]==0)&&( (Stack[*ptop].dir=='r')) ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='r')&&(kol[*i+1][*j]==0)&&( (Stack[*ptop].dir=='r') ) ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return;}


        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i][*j+1]==0) && ((Stack[*ptop].dir=='d')) ) {Stack[*ptop].last_choice='r'; (*j)++; *dt=0; *td=0; *lr=1; *rl=0;   return; }
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i+1][*j]==0) && ((Stack[*ptop].dir=='d')) ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i][*j-1]==0) && ((Stack[*ptop].dir=='d')) ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}
        if ( (Stack[*ptop].last_choice=='r')&&(kol[*i+1][*j]==0) && (Stack[*ptop].dir=='d') ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='r')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='d') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}
        if ( (Stack[*ptop].last_choice=='d')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='d') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}


        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i-1][*j]==0) && (Stack[*ptop].dir=='t') ) {Stack[*ptop].last_choice='t'; (*i)--; *dt=1; *td=0; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i][*j+1]==0) && (Stack[*ptop].dir=='t') ) {Stack[*ptop].last_choice='r'; (*j)++; *dt=0; *td=0; *lr=1; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='t') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}
        if ( (Stack[*ptop].last_choice=='t')&&(kol[*i][*j+1]==0) && (Stack[*ptop].dir=='t') ) {Stack[*ptop].last_choice='r'; (*j)++; *dt=0; *td=0; *lr=1; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='t')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='t') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}
        if ( (Stack[*ptop].last_choice=='r')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='t') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}


        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i-1][*j]==0) && (Stack[*ptop].dir=='l') ) {Stack[*ptop].last_choice='t'; (*i)--; *dt=1; *td=0; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i+1][*j]==0) && (Stack[*ptop].dir=='l') ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='a')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='l') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}
        if ( (Stack[*ptop].last_choice=='t')&&(kol[*i+1][*j]==0) && (Stack[*ptop].dir=='l') ) {Stack[*ptop].last_choice='d'; (*i)++; *dt=0; *td=1; *lr=0; *rl=0;  return;}
        if ( (Stack[*ptop].last_choice=='t')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='l') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}
        if ( (Stack[*ptop].last_choice=='d')&&(kol[*i][*j-1]==0) && (Stack[*ptop].dir=='l') ) {Stack[*ptop].last_choice='l'; (*j)--; *dt=0; *td=0; *lr=0; *rl=1;  return;}

        element iu;
        iu=Delete_From_Stack();
        *i=Stack[*ptop].row;
        *j=Stack[*ptop].col;
        if (Stack[*ptop].dir=='t') {*dt=1; *td=0; *lr=0; *rl=0;}
        if (Stack[*ptop].dir=='r') {*dt=0; *td=0; *lr=1; *rl=0;}
        if (Stack[*ptop].dir=='d') {*dt=0; *td=1; *lr=0; *rl=0;}
        if (Stack[*ptop].dir=='l') {*dt=0; *td=0; *lr=0; *rl=1;}
        printf("Go Back To Previos Stack Cell");
        Choose_Choice();

}


//Definition : Function 5
//Track The Road To Find The Goal
//This Function Calls When THe Check_Cell_For_Stack() Function Return 0;
void Track_Road(void)
{
                                if ( (kol[(*i)-1][*j]==0)&&(!(*td)) )
                                        {
                                                (*i)--;
                                                *dt=1; *td=0; *lr=0; *rl=0;
                                                return;
                                        }
                                if ( (kol[*i][*j+1]==0) && (!(*rl)) )
                                        {
                                                (*j)++;
                                                *dt=0; *td=0; *lr=1; *rl=0;
                                                return;
                                        }
                                if ( (kol[*i+1][*j]==0) && (!(*dt)) )
                                        {
                                                (*i)++;
                                                *dt=0; *td=1; *lr=0; *rl=0;
                                                return;
                                        }
                                if ( (kol[*i][(*j)-1]==0) && (!(*lr)) )
                                        {
                                                (*j)--; 
                                                *dt=0; *td=0; *lr=0; *rl=1;
                                                return;
                                        }
                                        printf("bon bast");

                                        *i=Stack[*ptop].row;
                                        *j=Stack[*ptop].col;
                                        if ((Stack[*ptop].dir=='t')) {*dt=1; *td=0; *lr=0; *rl=0;}
                                        if (Stack[*ptop].dir=='r') {*dt=0; *td=0; *lr=1; *rl=0;}
                                        if (Stack[*ptop].dir=='d') {*dt=0; *td=1; *lr=0; *rl=0;}
                                        if (Stack[*ptop].dir=='l') {*dt=0; *td=0; *lr=0; *rl=1;}
                         printf(" %d,%d ",*i,*j);
                        Choose_Choice();

}


void main()
{

//The Maze Starts From kol[1][1] AND Ended To kol[14][14]
(*i)=1; (*j)=1;
(*lr)=1; (*rl)=0; (*td)=0; (*dt)=0;

printf("1,1");
       while (!(((*i)==14)&&((*j)==14)))

        if (!Check_Cell_For_Stack(0))
                {
                         Track_Road();
                         printf(" %d,%d ",*i,*j);
                }

        else    {
                        Check_Cell_For_Stack(1);
                        Choose_Choice();



                         printf(" %d,%d ",*i,*j);
                }


scanf("%d",i);

}

 

دانلــود بـاکـــس

لینک های دانلود در این باکس قرار دارد
img

جهت مشاهده لینک های دانلود ابتدا وارد شده یا ثبت نام کنید

Avatar
پشتیبان سورس ایران 2180 مطلب منتشر شده

در مجموعه سورس ایران سعی می کنیم علاوه بر آموزش برنامه نویسی، به مسائل مرتبط و مهارت های نرم بپردازیم تا بعدهای مختلف را پوشش دهیم.

دیدگاه کاربران

تعداد دیدگاه های کاربران : 2 دیدگاه
Avatar
محمد خراسانی
پاسخ دهید

خطا میده


شما با موفقیت در خبرنامه ما عضو شدید