|
@@ -21,29 +21,31 @@ class World
|
|
|
// Number of lines
|
|
|
unsigned int h;
|
|
|
|
|
|
+ // Size of the array
|
|
|
+ const unsigned int size;
|
|
|
+
|
|
|
// Unidimensional array for tiles
|
|
|
- int* w;
|
|
|
+ int* board;
|
|
|
|
|
|
public:
|
|
|
// Constructor
|
|
|
- World(unsigned int l, unsigned int h, double p)
|
|
|
+ World(unsigned int l_, unsigned int h_, double p)
|
|
|
+ :l(l_), h(h_), size(l_ * h_)
|
|
|
{
|
|
|
- this->l = l;
|
|
|
- this->h = h;
|
|
|
- this->w = new int[l*h]();
|
|
|
+ board = new int[size]();
|
|
|
|
|
|
// Add walls to the first and last columns
|
|
|
for (unsigned int i = 0; i < h; i++)
|
|
|
{
|
|
|
- this->w[i * l] = 1;
|
|
|
- this->w[i * l + l - 1] = 1;
|
|
|
+ board[i * l] = 1;
|
|
|
+ board[i * l + l - 1] = 1;
|
|
|
}
|
|
|
|
|
|
// Add walls to the first and last lines
|
|
|
for (unsigned int j = 0; j < l; j++)
|
|
|
{
|
|
|
- this->w[j] = 1;
|
|
|
- this->w[(h - 1) * l + j] = 1;
|
|
|
+ board[j] = 1;
|
|
|
+ board[(h - 1) * l + j] = 1;
|
|
|
}
|
|
|
|
|
|
for (unsigned int i = 0; i < h; i++)
|
|
@@ -54,7 +56,7 @@ class World
|
|
|
// the starting tile nor the goal tile
|
|
|
if ((double) rand() / RAND_MAX < p && !(i == 1 && j == 1) && !(i == h - 2 && j == l - 2))
|
|
|
{
|
|
|
- this->w[i * l + j] = 1;
|
|
|
+ board[i * l + j] = 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -67,7 +69,7 @@ class World
|
|
|
{
|
|
|
for (unsigned int j = 0; j < l; j++)
|
|
|
{
|
|
|
- switch (this->w[i * l + j])
|
|
|
+ switch (board[i * l + j])
|
|
|
{
|
|
|
case 0:
|
|
|
cout << " ";
|
|
@@ -90,7 +92,7 @@ class World
|
|
|
{
|
|
|
unsigned int n = 0;
|
|
|
|
|
|
- if (i >= 0 && i < this->l * this->h && this->w[i] != 1)
|
|
|
+ if (i >= 0 && i < size && board[i] != 1)
|
|
|
{
|
|
|
// if i is a correct tile number (inside the array and not on a wall)
|
|
|
// look in the four adjacent tiles and keep only those with no wall
|
|
@@ -98,7 +100,7 @@ class World
|
|
|
|
|
|
for (unsigned int k = 0; k < 4; k++)
|
|
|
{
|
|
|
- if (this->w[moves[k]] != 1)
|
|
|
+ if (board[moves[k]] != 1)
|
|
|
{
|
|
|
r[n] = moves[k];
|
|
|
n++;
|
|
@@ -116,9 +118,14 @@ class World
|
|
|
bool dfs(unsigned int s0, unsigned int t, list<unsigned int>& path)
|
|
|
{
|
|
|
bool r = false;
|
|
|
+ int current = s0;
|
|
|
+
|
|
|
+ bool explored[size];
|
|
|
|
|
|
+ for (unsigned int k(0); k < size; k ++)
|
|
|
+ explored[k] = false;
|
|
|
|
|
|
- // ... Complete here ...
|
|
|
+ explored[s0] = true;
|
|
|
|
|
|
return r;
|
|
|
}
|