Browse Source

Refactor upcase variables

It is standard to have lowcase variables
DricomDragon 5 years ago
parent
commit
6dc0d0a2e9
1 changed files with 25 additions and 24 deletions
  1. 25 24
      main.cc

+ 25 - 24
main.cc

@@ -1,7 +1,8 @@
 // Example of world building, display, and successor computation for the artificial 
 // intelligence path-finding lab
 //
-// Author: Didier Lime
+// Author: Didier LIME
+// Adapted by : Jovian HERSEMEULE
 // Date: 2018-10-03
 
 #include <iostream>
@@ -15,45 +16,45 @@ class World
 {
     private:
         // Number of columns
-        unsigned int L;
+        unsigned int l;
         
         // Number of lines
-        unsigned int H;
+        unsigned int h;
 
         // Unidimensional array for tiles
         int* w;
     
     public:
         // Constructor
-        World(unsigned int L, unsigned int H, double P)
+        World(unsigned int l, unsigned int h, double p)
         {
-            this->L = L;
-            this->H = H;
-            this->w = new int[L*H]();
+            this->l = l;
+            this->h = h;
+            this->w = new int[l*h]();
 
             // Add walls to the first and last columns
-            for (unsigned int i = 0; i < H; i++)
+            for (unsigned int i = 0; i < h; i++)
             {
-                this->w[i * L] = 1;
-                this->w[i * L + L - 1] = 1;
+                this->w[i * l] = 1;
+                this->w[i * l + l - 1] = 1;
             }
 
             // Add walls to the first and last lines
-            for (unsigned int j = 0; j < L; j++)
+            for (unsigned int j = 0; j < l; j++)
             {
                 this->w[j] = 1;
-                this->w[(H - 1) * L + j] = 1;
+                this->w[(h - 1) * l + j] = 1;
             }
 
-            for (unsigned int i = 0; i < H; i++)
+            for (unsigned int i = 0; i < h; i++)
             {
-                for (unsigned int j = 0; j < L; j++)
+                for (unsigned int j = 0; j < l; j++)
                 {
-                    // add a wall in this tile with probability P and provided that it is neither
+                    // add a wall in this tile with probability p and provided that it is neither
                     // the starting tile nor the goal tile 
-                    if ((double) rand() / RAND_MAX < P && !(i == 1 && j == 1) && !(i == H - 2 && j == L - 2))
+                    if ((double) rand() / RAND_MAX < p && !(i == 1 && j == 1) && !(i == h - 2 && j == l - 2))
                     {
-                        this->w[i * L + j] = 1;
+                        this->w[i * l + j] = 1;
                     }
                 }
             }
@@ -62,18 +63,18 @@ class World
         // Display the world
         void display()
         {
-            for (unsigned int i = 0; i < H; i++)
+            for (unsigned int i = 0; i < h; i++)
             {
-                for (unsigned int j = 0; j < L; j++)
+                for (unsigned int j = 0; j < l; j++)
                 {
-                    switch (this->w[i * L + j])
+                    switch (this->w[i * l + j])
                     {
                         case 0:
-                            cout << ".";
+                            cout << " ";
                             break;
 
                         case 1:
-                            cout << "W";
+                            cout << "#";
                             break;
                     }
                 }
@@ -89,11 +90,11 @@ class World
         {
             unsigned int n = 0;
 
-            if (i >= 0 && i < this->L * this->H && this->w[i] != 1)
+            if (i >= 0 && i < this->l * this->h && this->w[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
-                const unsigned int moves[] = { i - 1, i + 1, i - L, i + L};
+                const unsigned int moves[] = { i - 1, i + 1, i - l, i + l};
                 
                 for (unsigned int k = 0; k < 4; k++)
                 {