Browse Source

Turm negative Bewegung, Luis Hahn

remotes/origin/Läufer-fertig,-Hendrik-Voß
Luis Hahn 11 months ago
parent
commit
247ed1dce3
  1. 28
      src/Turm.c
  2. 25
      test/test_Turm.c

28
src/Turm.c

@ -10,21 +10,43 @@ bool istzugerlaubt_Turm(char** Brett, int startX, int startY, int endX, int endY
int counter = 0; int counter = 0;
if(startX == startY){ if(startX == startY){
counter = endY-startY;
if(startY<endY){
counter = endY-startY;
for(int i = 0; i<counter;i++){ for(int i = 0; i<counter;i++){
if(Brett[startY+i][startX] != ' '){ if(Brett[startY+i][startX] != ' '){
return false; return false;
} }
} }
}else{
counter = startY-endY;
for(int i = 0; i<counter;i++){
if(Brett[startY-i][startX] != ' '){
return false;
}
}
}
}else if(startY == endY){ }else if(startY == endY){
counter = endX-startX;
for(int i = 0; i<counter;i++){
if(startX<endX){
counter = endX-startX;
for(int i = 0; i<counter;i++){
if(Brett[startY][startX+i] != ' '){ if(Brett[startY][startX+i] != ' '){
return false; return false;
} }
} }
}else{
counter = startX-endX;
for(int i = 0; i<counter;i++){
if(Brett[startY][startX-i] != ' '){
return false;
}
}
}
} }
return true; return true;
} }

25
test/test_Turm.c

@ -61,6 +61,31 @@ void test_Turm_X_Bewegung(void) {
free(brett); free(brett);
} }
void test_Turm_negative_Y_Bewegung(void) {
char** brett = Schachbrett_erstellen();
int startX = 0;
int startY = 4;
int endX = 0;
int endY = 2;
Player player = PLAYER_WHITE;
TEST_ASSERT_NOT_NULL(brett);
brett[4][0] = 'r';
print_Schachfeld(brett);
TEST_ASSERT_TRUE(istzugerlaubt_Turm(brett, startX, startY, endX, endY, player));
for (int i = 0; i < 8; i++) {
free(brett[i]);
}
free(brett);
}
#endif // TEST #endif // TEST

Loading…
Cancel
Save