Прохождение лабиринта методом правой руки

Как правильно сделать отрисовку хода в лабиринте? Моя отрисовка почему-то не работает.

#include <iostream>
#include <iomanip>
#include <vector>
#include <windows.h>
using namespace std;

const int MazeHeight = 9;
const int MazeWidth = 9;

struct person{
    int x = 1;
    int y = 5;
} p;

char maze[MazeHeight][MazeWidth + 1] =
{
    "# #######",
    "#   #   #",
    "# # # # #",
    "# #   # #",
    "# # ### #",
    "#   # # #",
    "# ##### #",
    "#   #   #",
    "#######x#",
};

const char wall = '#';
const char escape = ' ';
const char dude = '*';


void PrintMaze()
{
    for (int i = 0; i < MazeHeight; i++)
    {
        for (int j = 0; j < MazeWidth; j++) {
            cout << maze[i][j];
        }
        cout << endl;
    }
}


int main()
{
    setlocale(LC_ALL, "RUS");
  
    PrintMaze();


    for (int i = 0; i < MazeHeight; i++)
    {
        for (int j = 0; j < MazeWidth; j++) {

                    if (maze[p.x + 1][p.y] == wall || maze[p.x - 1][p.y] == wall) {
                        p.y += 1;
                        maze[p.x][p.y] == dude;
                        Sleep(2000);
                        cout << endl;
                        PrintMaze();
                    }

                    if (maze[p.x][p.y + 1] == '#') {
                        p.x += 1;
                        maze[p.x][p.y] == dude;
                        Sleep(2000);
                        cout << endl;
                        PrintMaze();
                    }
                    if (maze[p.x][p.y] == 'x') {
                        cout << "Лабиринт пройден!";
                    }
        }
    }

    cout << endl;
}

Ответы (1 шт):

Автор решения: nevilad

В коде присваивания ячейке символа человечка ошибка, вместо

maze[p.x][p.y] == dude;

надо делать

maze[p.x][p.y] = dude;

С такой main будет работать:

int main()
{
  setlocale(LC_ALL, "RUS");

  PrintMaze();

  for (int i = 0; i < MazeHeight; i++)
  {
    for (int j = 0; j < MazeWidth; j++) {

      if (maze[p.x + 1][p.y] == wall || maze[p.x - 1][p.y] == wall) {
        p.y += 1;
        maze[p.x][p.y] = dude;
        Sleep(2000);
        cout << endl;
        PrintMaze();
      }

      if (maze[p.x][p.y + 1] == '#') {
        p.x += 1;
        maze[p.x][p.y] = dude;
        Sleep(2000);
        cout << endl;
        PrintMaze();
      }
      if (maze[p.x][p.y] == 'x') {
        cout << "Лабиринт пройден!";
      }
    }
  }

  cout << endl;
}

Кстати Visual studio предупреждает об этом. При компиляции исходной программы есть два предупреждения

warning C4553: '==': operator has no effect; did you intend '='?

указывающих на строки присваивания человечка.

→ Ссылка