Как перейти от одной ячейки в лабиринте к нижней ячейке для DFS C ++? - PullRequest
0 голосов
/ 19 октября 2018

Я пытаюсь создать приложение для решения лабиринтов, но мне трудно понять, как перейти из одной ячейки в другую.У меня есть два класса.Класс лабиринта и класс ячейки.Лабиринт - это двумерный вектор клеток.

Вот мои классы Cell и Maze:

class Cell{
public:
    Cell(){}
    Cell(bool a,bool b,bool c,bool d);
    Cell(Cell &copy);
    bool getTop(){ return top; }
    bool getBottom(){ return bottom; }
    bool getRight(){return right;}
    bool getLeft(){return left;}
    bool getVisited(){return visited;}
    bool getPrevCell(){return prevCell;}
    char getData(){return data;}
    void setTop(bool a ){top = a;}
    void setBottom(bool b){bottom = b;}
    void setRight(bool c){right = c;}
    void setLeft(bool d){left = d;}
    void setVisited(bool e){ visited = e; }
    void setPrevCell(bool f){prevCell = f;}
    void setData(char c){data = c;}
    void operator=(const Cell &assign);
    bool operator==(const Cell &comp);
private:
    bool top, bottom, right, left, visited, prevCell;
    char data;
};

class Maze{
public:
    Maze(){}
    void addMaze(vector< Cell*> m)
    {
        maze.push_back(m);
        cout<<maze[0][0]->getTop();
    }
    bool operator== (const Maze& a);
    friend ostream &operator<<(ostream &output, Maze &a){
        for (auto it = a.maze.begin(); it != a.maze.end(); it++) {
            output << a.maze.data();
        }
        return output;
    }
    void Success(stack<Cell> &m);
    Cell setStart(int, int);
    Cell setGoal(int, int);
    void DFS(Cell start, Cell goal);
    void BFS(Cell start, Cell goal);
    void backTrack(stack<Cell> &a);
    void faliure();

private:
    vector<vector<Cell*>> maze;
};

Cell Maze::setStart(int x, int y){
    if (maze[y][x]->getData() == ' ') {
        maze[y][x]->setData('S');
        Cell start = *maze[y][x];
        cout << &maze;
        return start;
    }else{
        cout << "Invalid Start coordinates" << endl;
    }
    exit(0);
}

Cell Maze::setGoal(int x, int y){
    if (maze[y][x]->getData() == ' ') {
        maze[y][x]->setData('G');
        Cell goal = *maze[y][x];
        cout << &maze;
        return goal;
    }else{
        cout << "Invalid goal coordinates" << endl;
    }
    exit(0);
}

А вот моя функция DFS:

void Maze::DFS(Cell start, Cell goal){
    stack<Cell*> path;
    path.push(&start);
    Cell temp;
    int i = 1;


    while(!path.empty()){
        temp = *path.top();
        if (temp == goal) {
//            Success(path);
        }
        while (!temp.getBottom()) {
            if (temp.getBottom() == false) {

            }
        }
        if( temp.getBottom() == temp.getVisited()){
            path.pop();
        }else if(){

        }
    }
    faliure();
}

Моя главная проблема - моя функция DFS, так как я хочуспуститесь, чтобы проверить следующую клетку ниже, если это стена или нет.Я не знаю, как именно это сделать, поскольку большинство атрибутов классов ячеек находятся в bool, а координаты задаются в классе Maze.Я не уверен, как их точно изменить.Это были также требования поставленного перед нами вопроса, поэтому любая помощь будет высоко оценена.

...