Browse Source

refactoring: optimized bishop move validation

feat-figureMovement
JD 4 years ago
parent
commit
d9b9c2ac1b
  1. 6
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java
  2. 9
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java

6
fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java

@ -10,11 +10,9 @@ public class FigureBishop extends Figure
return false; return false;
} }
if (dst - src == 1 || dst - src == 6
|| dst - src == 10) // 1 Feld nach rechts
{
if ((dst-src) % 7 != 0
&& (dst-src) % 9 != 0)
return false; return false;
}
return super.moveAllowed(src, dst, field); return super.moveAllowed(src, dst, field);
} }

9
fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java

@ -2,7 +2,7 @@ package de.fd.fh;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
class FigureBishopTest class FigureBishopTest
{ {
@ -42,10 +42,13 @@ class FigureBishopTest
} }
@Test @Test
void checkValidMovesBishopRight3()
void checkInvalidMovesBishopRight3()
{ {
Figure f = new FigureBishop(); Figure f = new FigureBishop();
assertFalse(f.moveAllowed(45, 55, field));
int src = Figure.fieldLength * 5 + 5;
int dst = src + 10;
assertFalse(f.moveAllowed(src, dst, field));
} }
} }
Loading…
Cancel
Save