Jenkins
4 years ago
7 changed files with 248 additions and 0 deletions
-
2build.gradle
-
23fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java
-
26fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java
-
36fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java
-
54fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java
-
63fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java
-
44fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.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; |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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])); |
|||
} |
|||
} |
@ -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])); |
|||
} |
|||
} |
@ -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])); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue