Browse Source

test: king movement -> valid moves (based on checkInvalidKingMoves())

feat-figureMovement
JD 4 years ago
parent
commit
39759cf01d
  1. 14
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java
  2. 26
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java

14
fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java

@ -7,15 +7,15 @@ public class FigureKing extends Figure
{ {
// TODO: Positionierung in einer Ecke beachten // TODO: Positionierung in einer Ecke beachten
if (dst != src-1 if (dst != src-1
|| dst != src +1
&& dst != src +1
|| dst != src -8
|| dst != src -8 -1
|| dst != src -8 +1
&& dst != src -8
&& dst != src -8 -1
&& dst != src -8 +1
|| dst != src +8
|| dst != src +8 -1
|| dst != src +8 +1)
&& dst != src +8
&& dst != src +8 -1
&& dst != src +8 +1)
{ {
return false; return false;
} }

26
fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java

@ -43,4 +43,30 @@ class FigureKingTest
assertFalse(f.moveAllowed(pos, i, new Figure[64])); assertFalse(f.moveAllowed(pos, i, new Figure[64]));
} }
} }
@Test
void checkValidKingMoves()
{
Figure f = new FigureKing();
int pos = 45;
ArrayList<Integer> possibleMoves = new ArrayList<>();
possibleMoves.add(pos - Figure.fieldLength - 1);
possibleMoves.add(pos - Figure.fieldLength);
possibleMoves.add(pos - Figure.fieldLength + 1);
possibleMoves.add(pos - 1);
possibleMoves.add(pos + 1);
possibleMoves.add(pos + Figure.fieldLength - 1);
possibleMoves.add(pos + Figure.fieldLength);
possibleMoves.add(pos + Figure.fieldLength + 1);
for (int i = 0; i < possibleMoves.size(); i++)
{
assertTrue(f.moveAllowed(pos, possibleMoves.get(i), new Figure[64]));
}
}
} }
Loading…
Cancel
Save