diff --git a/build.gradle b/build.gradle index 1c6072a..f65fcce 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,8 @@ repositories { subprojects { apply plugin: 'java' + compileJava {options.encoding = "UTF-8"} + compileTestJava {options.encoding = "UTF-8"} sourceCompatibility = JavaVersion.VERSION_11 repositories { mavenCentral() diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java b/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java new file mode 100644 index 0000000..745d961 --- /dev/null +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java @@ -0,0 +1,23 @@ +package de.fd.fh; + +public class Figure +{ + public static final int fieldLength = 8; + + public boolean moveAllowed(int src, int dst, Figure[] field) + { + if (src == dst) + { + return false; + } + + if (field.length != Figure.fieldLength * Figure.fieldLength) + { + return false; + } + + // TODO: im Falle von Schach muss Zug Situation auflösen, sonst nicht möglich + + return true; + } +} diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java new file mode 100644 index 0000000..49ec0be --- /dev/null +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java @@ -0,0 +1,26 @@ +package de.fd.fh; + +public class FigureFarmer extends Figure +{ + @Override + public boolean moveAllowed(int src, int dst, Figure[] field) + { + int rowDiff = src / fieldLength - dst / fieldLength; // hoch/runter + + if (rowDiff > 1) // weißer Bauer nicht mehr als 1 Schritt nach "oben" + { + return false; + } + + if (rowDiff <= 0) // weißer Bauer kein Schritt "runter" + { + return false; + } + + // TODO: nur ein Schritt nach oben, wenn auf Ziel keine Figur + // TODO: links, rechts verboten + // TODO: Diagonal links/rechts hoch, wenn Figur geschlagen werden kann (Figur auf Ziel) + + return super.moveAllowed(src, dst, field); + } +} diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java new file mode 100644 index 0000000..545eccc --- /dev/null +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java @@ -0,0 +1,36 @@ +package de.fd.fh; + +public class FigureRook extends Figure +{ + @Override + public boolean moveAllowed(int src, int dst, Figure[] field) + { + int rowDiff = src / fieldLength - dst / fieldLength; // hoch/runter + int relStep = src % fieldLength - dst % fieldLength; // links//rechts + + if (rowDiff > 0 && relStep > 0) // diagonal nach links oben + { + return false; + } + + if (rowDiff > 0 && relStep < 0) // diagonal nach rechts oben + { + return false; + } + + if (rowDiff < 0 && relStep > 0) // diagonal nach rechts oben + { + return false; + } + + if (rowDiff < 0 && relStep < 0) // diagonal nach rechts unten + { + return false; + } + + // TODO: keine Figuren auf dem Weg "überspringen" + // TODO: falls Figur auf Ziel und keine Figuren auf Weg -> Figur schlagen + + return super.moveAllowed(src, dst, field); + } +} diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java new file mode 100644 index 0000000..9e17ae4 --- /dev/null +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java @@ -0,0 +1,54 @@ +package de.fd.fh; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FigureFarmerTest +{ + // weißer Bauer + @Test + void whiteFarmerValidDestination() + { + Figure f = new FigureFarmer(); + assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 5 + 0, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteFarmerInvalidDestinationDown() // statt nach "oben" wird nach "unten" gegangen + { + Figure f = new FigureFarmer(); + assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 7 + 0, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben" + { + Figure f = new FigureFarmer(); + assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 4 + 0, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void checkMoveWithValidDestinationVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach oben + { + Figure f = new FigureFarmer(); + assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 3 + 4, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteFarmerInvalidDestinationDownVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach unten + { + Figure f = new FigureFarmer(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 5 + 4, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } +} \ No newline at end of file diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java new file mode 100644 index 0000000..526664e --- /dev/null +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java @@ -0,0 +1,63 @@ +package de.fd.fh; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FigureRookTest +{ + // weißer Turm + @Test + void whiteRookValidMoveUp() + { + Figure f = new FigureRook(); + assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 0 + 4, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookValidMoveDown() + { + Figure f = new FigureRook(); + assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 7 + 4, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveLeftUp() // diagonal nach links oben + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 3 + 3, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveRightUp() // diagonal nach rechts oben + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 3 + 5, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveLeftDown() // diagonal nach links unten + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 5 + 3, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveRightDown() // diagonal nach rechts unten + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, + Figure.fieldLength * 5 + 5, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } +} \ No newline at end of file diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java new file mode 100644 index 0000000..49ea43c --- /dev/null +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java @@ -0,0 +1,44 @@ +package de.fd.fh; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FigureTest +{ + @Test + void checkMoveWithInvalidFieldSmall() // Feldgröße sollte 8*8 betragen + { + Figure f = new Figure(); + assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 5 + 0, + new Figure[0])); + } + + @Test + void checkMoveWithInvalidFieldBigger() // Feldgröße sollte 8*8 betragen + { + Figure f = new Figure(); + assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 5 + 0, + new Figure[8*9])); + } + + @Test + void checkMoveWithInvalidFieldCorrect() // Feldgröße sollte 8*8 betragen + { + Figure f = new Figure(); + assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 5 + 0, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void checkMoveWithoutNewDestination() + { + Figure f = new Figure(); + assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, + Figure.fieldLength * 6 + 0, + new Figure[Figure.fieldLength * Figure.fieldLength])); + } +} \ No newline at end of file