Browse Source

Merge commit '5d52b6b876b89a19c535fa7bc6d13d08b0b6e0aa' into HEAD

pr-loginClient
Jenkins 4 years ago
parent
commit
febd11a208
  1. 2
      build.gradle
  2. 23
      fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java
  3. 26
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java
  4. 36
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java
  5. 54
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java
  6. 63
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java
  7. 44
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java

2
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()

23
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;
}
}

26
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);
}
}

36
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);
}
}

54
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]));
}
}

63
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]));
}
}

44
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]));
}
}
Loading…
Cancel
Save