From 07524ab01cf1f9ccd5b3e3ea228bb388e2cbf5e4 Mon Sep 17 00:00:00 2001 From: Ronja Awe Date: Wed, 1 Feb 2023 11:35:22 +0100 Subject: [PATCH] =?UTF-8?q?if=20Anweisung=20nach=20oben=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/c/labyrinth.c | 3 +++ test/c/test_labyrinth.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/c/labyrinth.c b/src/c/labyrinth.c index c4cefe3..410dce2 100644 --- a/src/c/labyrinth.c +++ b/src/c/labyrinth.c @@ -34,5 +34,8 @@ void wegsuchen(lab laby, bool* done, int y, int x, int ziely, int zielx){ if (!*done && x + 1 <= zielx && laby[y][x+1] == '0'){ wegsuchen(laby, done, y, x + 1, ziely, zielx); } + if (!*done && y - 1 >= 0 && laby[y-1][x] == '0'){ // oben + wegsuchen(laby, done, y - 1, x, ziely, zielx); + } } } \ No newline at end of file diff --git a/test/c/test_labyrinth.c b/test/c/test_labyrinth.c index 9b9448c..f2d1e80 100644 --- a/test/c/test_labyrinth.c +++ b/test/c/test_labyrinth.c @@ -126,8 +126,26 @@ void test_LabyrinthRechts(void){ wegsuchen(laby, &result, 0, 0, 0, 2); printlabyrinth(laby, hoehe, breite); TEST_ASSERT_EQUAL_INT(1, result); +} + +void test_LabyrinthOben(void){ + bool result; + int input = 1; + int hoehe = 5; + int breite = 5; + lab laby = { + {'0', '1', '0', '0', '0'}, + {'0', '1', '0', '1', '0'}, + {'0', '1', '0', '1', '0'}, + {'0', '1', '0', '1', '0'}, + {'0', '0', '0', '1', '0'}, + }; + + wegsuchen(laby, &result, 0, 0, 4, 4); + printlabyrinth(laby, hoehe, breite); + TEST_ASSERT_EQUAL_INT(1, result); } #endif // TEST \ No newline at end of file