Talk about Maze C + +

Source: Internet
Author: User

Today, the teacher made a maze problem, I saw and I found and I wrote before a program is the same, but in later writing when there is a place wrong, the end of the class I still did not write correctly, and then came back today after they have looked at, now has been resolved.

#ifndef Direction_h

#define Direction_h
#include <iostream>
using namespace Std;
struct node
{
int A;
int b;
};
Class Direction
{
Public
Direction ();
~direction ();
void DFS (int n, int m);
void Udlr (int &n, int &m, int num);
void Durl (int &n, int &m, int num);
void output ();
Private
int **a;
int **visit;
Node zxh[64];
int count1;
};
Direction::D irection ()
{
count1 = 0;
A = new int*[8];
Visit = new Int*[8];
for (int i = 0; i<8; i++)
{
A[i] = new INT[8];
Visit[i] = new INT[8];
}
for (int i = 0; i<8; i++)
{
ZXH[I].A =-1;
zxh[i].b =-1;
}
int b[] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 0, 1, 0,
0, 0, 0, 0, 1, 0, 1, 0,
0, 1, 0, 0, 0, 0, 1, 0,
0, 1, 0, 1, 1, 0, 1, 0,
0, 1, 0, 0, 1, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0};
for (int i = 0; i<8; i++)
{
for (int j = 0; j<8; j + +)
{
A[I][J] = B[i * 8 + j];
VISIT[I][J] = 0;
}
}
}
Direction::~direction ()
{}
void Direction::udlr (int &n, int &m, int num)
{
if (num = = 1)
n--;
else if (num = = 2)
n++;
else if (num = = 3)
m--;
Else
m++;
}//Famous Direction
void Direction::d url (int &n, int &m, int num)
{
if (num = = 1)
n++;
else if (num = = 2)
n--;
else if (num = = 3)
m++;
Else
m--;
}//Famous Direction
void Direction::output ()
{
int num = 0;
while (zxh[num].a! =-1)
{
if (num% 7 = = 0)
cout << Endl;
cout << "(" << zxh[num].a << "," << zxh[num].b << ")" << "";
num++;
}
}
void Direction::D fs (int n, int m)
{
if (n = = 7 && m = = 7)
{
Output (); cout << Endl; Return
}
Else
{
for (int i = 1; i < 5; i++)
{
UDLR (n, M, i);
if (n >= 0 && N < 8 && m >= 0 && m < 8 && A[n][m] = = 0)
{
ZXH[COUNT1].A = n;
zxh[count1].b = m;
count1++;
A[N][M] = 1;
DFS (n, m);
A[n][m] = 0;
count1--;
ZXH[COUNT1].A =-1;
zxh[count1].b =-1;
}
Durl (n, M, i);
}
}
}
#endif
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "Direction.h"
#include <iostream>
using namespace Std;
int main ()
{
Direction Z;
Z.dfs (0,0);
return 0;
}

Talk about Maze C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.