1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <ctime>
#include <algorithm>
using namespace std; // <--- Best not to use.
constexpr int MAXSIZE{ 10 }; // <--- Added.
//constexpr int MAXROWS{ 8 }; // <--- These are more for future use when you have an array of different sizes.
//constexpr int MAXCOLS{ 8 };
int checkfill(int n, vector<int> &a); // <--- Did you forget to define "check" or should this be "checkfill"
int move(int arr[][MAXSIZE], vector<int>& b, int current, int i, int j, int count);
void restart(int arr[][MAXSIZE], vector<int>& b);
int equal(vector<int>& a, vector<int>& b);
int equal(vector<int>& a, vector<int>& b) // <--- Defined, but never called.
{
if (a == b) // <--- What did you intend to compare and why?
{
return 1;
}
else
return 0;
}
void restart(int maze[][MAXSIZE], vector<int>& b)
{
//b.clear(); // <--- These are unnecessary when all you want to do is add a (0)zero.
//b.push_back(-1);
b.push_back(0);
int current = 1; // <--- current what?
int i = 1, j = 1; // <--- You forgot about "p" and "q".
int count = 0; // <--- Count of what?
move(maze, b, current, i, j, count);
}
int move(int maze[][MAXSIZE], vector<int>& b, int current, int i, int j, int count)
{
return 0; // <--- Tempory. Added because the function needs a return value so it will compile.
}
int checkfill(int n, vector<int> &a) // <--- Defined, but never called. You could just return a "bool".
{
auto it = find(a.begin(), a.end(), n);
if (it != a.end())
{
return 0;
}
else
{
a.push_back(n);
return 1;
}
}
int main()
{
vector<int> a{ -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 };
vector<int> b{ -1 };
int maze[MAXSIZE][MAXSIZE]
{
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, 1, 16, 5, 20, 25, 9, 21, 1, -1},
{-1, 18, 12, 27, 26, 11, 17, 12, 32, -1},
{-1, 32, 11, 15, 29, 8, 6, 27, 20, -1},
{-1, 17, 4, 13, 24, 30, 28, 31, 2, -1},
{-1, 25, 10, 2, 26, 4, 28, 22, 13, -1},
{-1, 5, 14, 30, 8, 15, 31, 19, 6, -1},
{-1, 23, 7, 24, 16, 29, 22, 18, 19, -1},
{-1, 3, 12, 9, 3, 7, 14, 23, 33, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
};
//int k; // <--- Defined, but never used. ALWAYS initialize all your variables.
for (int row{}; row < MAXSIZE; row++) // <--- Should be in a function.
{
cout << '\n';
for (int col{}; col < MAXSIZE; col++)
{
cout << setw(3) << maze[row][col];
}
}
cout << '\n';
restart(maze, b);
return 0; // <--- Not required, but makes a good break point for testing.
}
| |