12 Commits

  1. 19
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java
  2. 25
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java
  3. 54
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java
  4. 51
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java

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

@ -0,0 +1,19 @@
package de.fd.fh;
public class FigureBishop extends Figure
{
@Override
public boolean moveAllowed(int src, int dst, Figure[] field)
{
if ((dst-src) % Figure.fieldLength == 0) // nach oben/unten nicht erlaubt
{
return false;
}
if ((dst-src) % 7 != 0
&& (dst-src) % 9 != 0)
return false;
return super.moveAllowed(src, dst, field);
}
}

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

@ -0,0 +1,25 @@
package de.fd.fh;
public class FigureKing extends Figure
{
@Override
public boolean moveAllowed(int src, int dst, Figure[] field)
{
// TODO: Positionierung in einer Ecke beachten
if (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)
{
return false;
}
return super.moveAllowed(src, dst, field);
}
}

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

@ -0,0 +1,54 @@
package de.fd.fh;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
class FigureBishopTest
{
Figure[] field = new Figure[Figure.fieldLength * Figure.fieldLength];
@Test
void checkInvalidMovesBishopUpward()
{
Figure f = new FigureBishop();
int src = Figure.fieldLength * 5 + 5;
int dst = src - Figure.fieldLength;
assertFalse(f.moveAllowed(src, dst, field));
}
@Test
void checkInvalidMovesBishopRight()
{
Figure f = new FigureBishop();
int src = Figure.fieldLength * 5 + 5;
int dst = src + 1;
assertFalse(f.moveAllowed(src, dst, field));
}
@Test
void checkInvalidMovesBishopRight2()
{
Figure f = new FigureBishop();
int src = Figure.fieldLength * 5 + 5;
int dst = src + 6;
assertFalse(f.moveAllowed(src, dst, field));
}
@Test
void checkInvalidMovesBishopRight3()
{
Figure f = new FigureBishop();
int src = Figure.fieldLength * 5 + 5;
int dst = src + 10;
assertFalse(f.moveAllowed(src, dst, field));
}
}

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

@ -0,0 +1,51 @@
package de.fd.fh;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
class FigureKingTest
{
// K = Position (19), x = gültig (10, 11, 12, 18, 20, 26, 27, 28), rest nicht
// x x x
// x K x
// x x x
@ParameterizedTest
@CsvSource({
"19",
"45"
})
void checkKingMovesSimple(int pos)
{
Figure f = new FigureKing();
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 < Figure.fieldLength * Figure.fieldLength; i++)
{
if (possibleMoves.contains(i))
{
assertTrue(f.moveAllowed(pos, i, new Figure[64]));
continue;
}
assertFalse(f.moveAllowed(pos, i, new Figure[64]));
}
}
}
Loading…
Cancel
Save