|
@@ -50,10 +50,13 @@ class World
|
|
|
// Unidimensional array for tiles
|
|
|
int* board;
|
|
|
|
|
|
+ // Number of empty tiles
|
|
|
+ unsigned int tileQuantity;
|
|
|
+
|
|
|
public:
|
|
|
// Constructor
|
|
|
World(unsigned int l_, unsigned int h_, double p)
|
|
|
- :l(l_), h(h_), size(l_ * h_)
|
|
|
+ :l(l_), h(h_), size(l_ * h_), tileQuantity(size)
|
|
|
{
|
|
|
board = new int[size]();
|
|
|
|
|
@@ -62,6 +65,7 @@ class World
|
|
|
{
|
|
|
board[i * l] = WALL;
|
|
|
board[i * l + l - 1] = WALL;
|
|
|
+ tileQuantity -= 2;
|
|
|
}
|
|
|
|
|
|
// Add walls to the first and last lines
|
|
@@ -69,6 +73,7 @@ class World
|
|
|
{
|
|
|
board[j] = WALL;
|
|
|
board[(h - 1) * l + j] = WALL;
|
|
|
+ tileQuantity -= 2;
|
|
|
}
|
|
|
|
|
|
for (unsigned int i = 0; i < h; i++)
|
|
@@ -80,6 +85,7 @@ class World
|
|
|
if ((double) rand() / RAND_MAX < p && !(i == 1 && j == 1) && !(i == h - 2 && j == l - 2))
|
|
|
{
|
|
|
board[i * l + j] = WALL;
|
|
|
+ tileQuantity --;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -350,6 +356,12 @@ class World
|
|
|
cout << discovered.size() << " tiles discovered;" << endl;
|
|
|
cout << path.size() << " path length." << endl;
|
|
|
}
|
|
|
+
|
|
|
+ void showProperties() {
|
|
|
+ cout << "Length : " << l << endl;
|
|
|
+ cout << "Height : " << h << endl;
|
|
|
+ cout << "Number of floor tiles : " << tileQuantity << endl;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
int main()
|
|
@@ -368,6 +380,7 @@ int main()
|
|
|
|
|
|
// Display it
|
|
|
cout << endl << "Generated world" << endl;
|
|
|
+ w.showProperties();
|
|
|
w.markOne(start, ORIGIN);
|
|
|
w.markOne(end, TARGET);
|
|
|
w.display();
|