Browse Source

refactoring:logik änderung der Turm Funktion, Luis Hahn

remotes/origin/Läufer-fertig,-Hendrik-Voß
Luis Hahn 11 months ago
parent
commit
9c250dc449
  1. 14
      src/Turm.c
  2. 6
      test/test_Turm.c

14
src/Turm.c

@ -9,39 +9,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 == endX){
if(startY<endY){ if(startY<endY){
counter = endY-startY; counter = endY-startY;
for(int i = 0; i<counter;i++){
for(int i = 1; i<counter;i++){
if(Brett[startY+i][startX] != ' '){ if(Brett[startY+i][startX] != ' '){
return false; return false;
} }
} }
return true;
}else{ }else{
counter = startY-endY; counter = startY-endY;
for(int i = 0; i<counter;i++){
for(int i = 1; i<counter;i++){
if(Brett[startY-i][startX] != ' '){ if(Brett[startY-i][startX] != ' '){
return false; return false;
} }
} }
return true;
} }
}else if(startY == endY){ }else if(startY == endY){
if(startX<endX){ if(startX<endX){
counter = endX-startX; counter = endX-startX;
for(int i = 0; i<counter;i++){
for(int i = 1; i<counter;i++){
if(Brett[startY][startX+i] != ' '){ if(Brett[startY][startX+i] != ' '){
return false; return false;
} }
} }
return true;
}else{ }else{
counter = startX-endX; counter = startX-endX;
for(int i = 0; i<counter;i++){
for(int i = 1; i<counter;i++){
if(Brett[startY][startX-i] != ' '){ if(Brett[startY][startX-i] != ' '){
return false; return false;
} }
} }
return true;
} }
} }

6
test/test_Turm.c

@ -24,10 +24,12 @@ void test_Turm_Y_Bewegung(void) {
TEST_ASSERT_NOT_NULL(brett); TEST_ASSERT_NOT_NULL(brett);
brett[1][0] = ' '; brett[1][0] = ' ';
brett[2][0] = ' ';
brett[3][0] = ' ';
print_Schachfeld(brett); print_Schachfeld(brett);
TEST_ASSERT_FALSE(istzugerlaubt_Turm( brett, startX, startY, endX, endY, player));
TEST_ASSERT_TRUE(istzugerlaubt_Turm( brett, startX, startY, endX, endY, player));
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@ -52,7 +54,7 @@ void test_Turm_X_Bewegung(void) {
print_Schachfeld(brett); print_Schachfeld(brett);
TEST_ASSERT_FALSE(istzugerlaubt_Turm( brett, startX, startY, endX, endY, player));
TEST_ASSERT_TRUE(istzugerlaubt_Turm( brett, startX, startY, endX, endY, player));
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {

Loading…
Cancel
Save