-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added Sheet2Task7 and its verifier * fixed some code issues * edited vorkurs.cls
- Loading branch information
1 parent
bc8650a
commit 631bef1
Showing
11 changed files
with
219 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../src/main/java/de/unistuttgart/informatik/fius/jvk/provided/programs/SafeWalkProgram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package de.unistuttgart.informatik.fius.jvk.provided.programs; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; | ||
import de.unistuttgart.informatik.fius.jvk.provided.entity.Totoro; | ||
|
||
|
||
public class SafeWalkProgram implements Program<Totoro> { | ||
|
||
@Override | ||
public void run(Totoro totoro) { | ||
if (totoro.canMove()) { | ||
totoro.move(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet2Task7.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.unistuttgart.informatik.fius.jvk.tasks; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.Position; | ||
import de.unistuttgart.informatik.fius.icge.simulation.Simulation; | ||
import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; | ||
import de.unistuttgart.informatik.fius.icge.simulation.tools.PlayfieldModifier; | ||
import de.unistuttgart.informatik.fius.jvk.provided.entity.*; | ||
import de.unistuttgart.informatik.fius.jvk.provided.factories.*; | ||
import de.unistuttgart.informatik.fius.jvk.provided.shapes.*; | ||
|
||
public class Sheet2Task7 implements Task { | ||
|
||
@Override | ||
public void run(Simulation sim) { | ||
PlayfieldModifier pm = new PlayfieldModifier(sim.getPlayfield()); | ||
Totoro totoro1 = new Totoro(); | ||
Totoro totoro2 = new Totoro(); | ||
Totoro totoro3 = new Totoro(); | ||
Totoro totoro4 = new Totoro(); | ||
pm.placeEntityAt(totoro1, new Position(0, 2)); | ||
pm.placeEntityAt(totoro4, new Position(0, 0)); | ||
pm.placeEntityAt(totoro3, new Position(2, 2)); | ||
pm.placeEntityAt(totoro2, new Position(2, 0)); | ||
totoro4.setNutsInPocket(42); | ||
totoro2.setNutsInPocket(42); | ||
totoro1.turnClockWise(); | ||
totoro3.setNutsInPocket(13); | ||
totoro3.turnClockWise(); | ||
totoro1.setNutsInPocket(7); | ||
totoro3.turnClockWise(); | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet2Task7Verifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package de.unistuttgart.informatik.fius.jvk.verifier; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Iterator; | ||
import java.util.stream.Collectors; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.Position; | ||
import de.unistuttgart.informatik.fius.icge.simulation.Simulation; | ||
import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier; | ||
import de.unistuttgart.informatik.fius.icge.simulation.actions.*; | ||
import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; | ||
import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus; | ||
import de.unistuttgart.informatik.fius.jvk.provided.BasicTaskInformation; | ||
import de.unistuttgart.informatik.fius.jvk.provided.entity.Nut; | ||
|
||
|
||
public class Sheet2Task7Verifier implements TaskVerifier { | ||
|
||
private BasicTaskInformation task; | ||
|
||
private BasicTaskInformation taskB = new BasicTaskInformation("b) Find the differences between the totoros.", "Find the differences between the totoros.", TaskVerificationStatus.SUCCESSFUL); | ||
|
||
private ActionLog actionLog; | ||
|
||
public Sheet2Task7Verifier() { | ||
List<BasicTaskInformation> subTasks = new ArrayList<>(); | ||
subTasks.add(this.taskB); | ||
this.task = new BasicTaskInformation("Sheet 2 Task 7", "Learn how differentiate objects and classes", subTasks); | ||
} | ||
|
||
@Override | ||
public void attachToSimulation(Simulation sim) { | ||
this.actionLog = sim.getActionLog(); | ||
} | ||
|
||
@Override | ||
public void verify() { | ||
System.out.println("Verify"); | ||
List<EntitySpawnAction> spawnActions = this.actionLog.getActionsOfType(EntitySpawnAction.class, true); | ||
|
||
List<Position> coinPositions = spawnActions.stream() | ||
.filter((action) -> (action.getEntity() instanceof Nut)) | ||
.map((action) -> action.getPosition()) | ||
.sorted((a, b) -> { | ||
if (a.getY() < b.getY()) return -1; | ||
if (a.getY() == b.getY()) { | ||
if (a.getX() < b.getX()) return -1; | ||
if (a.getX() == b.getX()) return 0; | ||
} | ||
return 1; | ||
}) | ||
.collect(Collectors.toList()); | ||
|
||
// subtask b) | ||
int nrOfCoinsSpawned = coinPositions.size(); | ||
if (nrOfCoinsSpawned >= 5) { | ||
this.taskB = this.taskB.updateStatus(TaskVerificationStatus.SUCCESSFUL); | ||
} | ||
|
||
List<BasicTaskInformation> subTasks = new ArrayList<>(); | ||
subTasks.add(this.taskB); | ||
|
||
if (subTasks.stream().allMatch(subTask -> subTask.getTaskStatus().equals(TaskVerificationStatus.SUCCESSFUL))) { | ||
this.task = this.task.updateStatus(TaskVerificationStatus.SUCCESSFUL); | ||
} | ||
|
||
this.task = this.task.updateSubTasks(subTasks); | ||
} | ||
|
||
/** | ||
* Check if a field with at least {@code nrOfCoins} exists. | ||
*/ | ||
private boolean checkMultiCoinsField(List<Position> coinPositions, int nrOfCoins) { | ||
Position currentPos = null; | ||
int currentCount = 0; | ||
|
||
Iterator<Position> positions = coinPositions.iterator(); | ||
|
||
while (positions.hasNext()) { | ||
Position p = positions.next(); | ||
if (currentPos == null || !p.equals(currentPos)) { | ||
if (currentCount == nrOfCoins) { // found field with right coincount | ||
return true; | ||
} | ||
currentPos = p; | ||
currentCount = 0; | ||
} | ||
currentCount++; | ||
if (!positions.hasNext()) { // special check for end of list | ||
if (currentCount == nrOfCoins) { // found field with right coincount | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Count the number of horizontal lines of length {@code lineLength}. | ||
*/ | ||
private int countLines(List<Position> coinPositions, int lineLength) { | ||
if(coinPositions.isEmpty()){ | ||
return 0; | ||
} | ||
int currentX = coinPositions.get(0).getX(); | ||
int currentY = coinPositions.get(0).getY(); | ||
int rowCount = 0; | ||
int currentLength = 0; | ||
|
||
int lineCount = 0; | ||
|
||
Iterator<Position> positions = coinPositions.iterator(); | ||
|
||
while (positions.hasNext()) { | ||
Position p = positions.next(); | ||
if (currentY == p.getY()) { | ||
if (currentX + currentLength == p.getX()) { | ||
currentLength++; | ||
if (!positions.hasNext()) { | ||
// special check for end of Iterator | ||
if (currentLength == lineLength) { | ||
// only count lines of the exact length specified | ||
lineCount++; | ||
} | ||
} | ||
} else { | ||
if (currentLength == lineLength) { | ||
// only count lines of the exact length specified | ||
lineCount++; | ||
} | ||
currentX = p.getX(); | ||
currentLength = 1; | ||
} | ||
} else { | ||
if (currentLength == lineLength) { | ||
// only count lines of the exact length specified | ||
lineCount++; | ||
} | ||
// start new row | ||
currentY = p.getY(); | ||
currentX = p.getX(); | ||
currentLength = 1; | ||
} | ||
} | ||
|
||
return lineCount; | ||
} | ||
|
||
@Override | ||
public TaskInformation getTaskInformation() { | ||
return this.task; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters