|
@ -1,6 +1,8 @@ |
|
|
package de.fd.fh; |
|
|
package de.fd.fh; |
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
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.lang.reflect.Array; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
@ -13,13 +15,15 @@ class FigureKingTest |
|
|
// x x x |
|
|
// x x x |
|
|
// x K x |
|
|
// x K x |
|
|
// x x x |
|
|
// x x x |
|
|
@Test |
|
|
|
|
|
void checkInvalidKingMoves() |
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
@CsvSource({ |
|
|
|
|
|
"19", |
|
|
|
|
|
"45" |
|
|
|
|
|
}) |
|
|
|
|
|
void checkKingMovesSimple(int pos) |
|
|
{ |
|
|
{ |
|
|
Figure f = new FigureKing(); |
|
|
Figure f = new FigureKing(); |
|
|
|
|
|
|
|
|
int pos = 19; |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Integer> possibleMoves = new ArrayList<>(); |
|
|
ArrayList<Integer> possibleMoves = new ArrayList<>(); |
|
|
|
|
|
|
|
|
possibleMoves.add(pos - Figure.fieldLength - 1); |
|
|
possibleMoves.add(pos - Figure.fieldLength - 1); |
|
@ -33,40 +37,15 @@ class FigureKingTest |
|
|
possibleMoves.add(pos + Figure.fieldLength); |
|
|
possibleMoves.add(pos + Figure.fieldLength); |
|
|
possibleMoves.add(pos + Figure.fieldLength + 1); |
|
|
possibleMoves.add(pos + Figure.fieldLength + 1); |
|
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
|
|
|
|
|
for (int i = 0; i < Figure.fieldLength * Figure.fieldLength; i++) |
|
|
{ |
|
|
{ |
|
|
if (possibleMoves.contains(i)) |
|
|
if (possibleMoves.contains(i)) |
|
|
{ |
|
|
{ |
|
|
|
|
|
assertTrue(f.moveAllowed(pos, i, new Figure[64])); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |