From 4f9f6660992a8eb16cc82f9e3ba1ef768731e5b3 Mon Sep 17 00:00:00 2001 From: fdai7492 Date: Fri, 2 Feb 2024 20:38:22 +0000 Subject: [PATCH] Feldsicherheit fertig + tests, Anton Lohrey --- src/Koenig.c | 3 ++- test/test_Feldsicherheit.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Koenig.c b/src/Koenig.c index ae21665..dd97a02 100644 --- a/src/Koenig.c +++ b/src/Koenig.c @@ -229,7 +229,8 @@ bool istzugerlaubt_Koenig(char** Brett, int startX, int startY, int endX, int en if (player == PLAYER_BLACK && islower(endPosition)) return false; - // mehr checks noch benötigt + if (istFeldUnsicher(Brett, endX, endY, player)) + return false; return true; } diff --git a/test/test_Feldsicherheit.c b/test/test_Feldsicherheit.c index e5b1326..644fdc5 100644 --- a/test/test_Feldsicherheit.c +++ b/test/test_Feldsicherheit.c @@ -162,5 +162,34 @@ void test_GreiftKoenigAn(void) { freeTestBrett(Brett); } +void test_istFeldUnsicher(void) { + char** Brett = ErstelleTestBrett(); + Brett[4][4] = 'p'; + print_Schachfeld(Brett); + TEST_ASSERT_TRUE(istFeldUnsicher(Brett, 5, 3, player)); + TEST_ASSERT_FALSE(istFeldUnsicher(Brett, 0, 0, player)); + + Brett[4][4] = ' '; + Brett[0][1] = 'N'; + player = PLAYER_BLACK; + + TEST_ASSERT_TRUE(istFeldUnsicher(Brett, 2, 2, player)); + TEST_ASSERT_FALSE(istFeldUnsicher(Brett, 0, 0, player)); + + Brett[0][1] = ' '; + Brett[7][0] = 'r'; + player = PLAYER_WHITE; + + TEST_ASSERT_TRUE(istFeldUnsicher(Brett, 0, 0, player)); + TEST_ASSERT_FALSE(istFeldUnsicher(Brett, 4, 4, player)); + + Brett[7][0] = ' '; + Brett[3][3] = 'Q'; + player = PLAYER_BLACK; + TEST_ASSERT_TRUE(istFeldUnsicher(Brett, 7, 7, player)); + TEST_ASSERT_TRUE(istFeldUnsicher(Brett, 3, 0, player)); + + freeTestBrett(Brett); +} #endif // TEST