TP 13 exo2: Implement the missing bits to do a full game.
[TD_C.git] / TP_13 / exo2 / lib / coordinates.c
index f9123e95f7b25a2902efdb68cb2e587bc59dc9dd..a9d8159a3584af3fc321d4857d4f73d558d80267 100644 (file)
@@ -33,11 +33,16 @@ coordinates_t set_coordinates(int y, int x, unsigned type) {
     return new_coordinates;
 }
 
-unsigned add_coordinates(coordinates_t new_coordinates, coordinates_t* coordinates_array) {
+/* the function do a lot of sanity checks before adding new board elements,
+ * hence the loop. moving the checks in the main loop is also possible */
+unsigned add_coordinates(coordinates_t new_coordinates, coordinates_t* coordinates_array, unsigned round) {
     /* valid coordinates are in the [1-3] range */
     if (new_coordinates.y < 1 || new_coordinates.y > 3 || new_coordinates.x < 1 || new_coordinates.x > 3) {
         return 3; /* error value for invalid coordinates */
+    } else if (round == MAX_COORDINATES + 1) {
+        return 1; /* error value for full array */
     }
+
     for (unsigned i = 0; i < MAX_COORDINATES; i++) {
         /* check if already entered */
         if (new_coordinates.y == (coordinates_array + i)->y && new_coordinates.x == (coordinates_array + i)->x) {
@@ -47,5 +52,12 @@ unsigned add_coordinates(coordinates_t new_coordinates, coordinates_t* coordinat
             return 0; /* error value when everything if fine */
         }
     }
-    return 1; /* error value for full array */
+    return 4; /* error value for unknown error case - should never happen - */
+}
+
+bool chk_win_conditions(coordinates_t* coordinates_array) {
+    for (unsigned i = 0; i < MAX_COORDINATES; i++) {
+
+    }
+    return false;
 }