X-Git-Url: https://git.piment-noir.org/?p=TD_C.git;a=blobdiff_plain;f=TP_13%2Fexo2%2Flib%2Fcoordinates.c;h=a9d8159a3584af3fc321d4857d4f73d558d80267;hp=f9123e95f7b25a2902efdb68cb2e587bc59dc9dd;hb=04b0afb5d5c81f1d98e98b9a6e532b1d3c868cc4;hpb=506ed8ed2ccf2fce58e9a0dd651e4ceea5a6320c diff --git a/TP_13/exo2/lib/coordinates.c b/TP_13/exo2/lib/coordinates.c index f9123e9..a9d8159 100644 --- a/TP_13/exo2/lib/coordinates.c +++ b/TP_13/exo2/lib/coordinates.c @@ -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; }