Skip to content

Commit

Permalink
Code fixes (#177)
Browse files Browse the repository at this point in the history
* added Sheet2Task7 and its verifier

* fixed some code issues

* edited vorkurs.cls
  • Loading branch information
Sara424242 authored Sep 29, 2024
1 parent bc8650a commit 631bef1
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class Sooty_mans extends Totoro {

/**
* changes the appearance of the player in the game from Neo to Morpheus
* changes the appearance of the player in the game from Totoro to Sooty_mans
*/
@Override
protected String getTextureHandle() {
Expand All @@ -31,5 +31,4 @@ protected String getTextureHandle() {
* TODO: Implement the operations of sooty_mans here
*
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package de.unistuttgart.informatik.fius.jvk.provided.entity;

import de.unistuttgart.informatik.fius.icge.simulation.Position;
import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute;
import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionMethod;
import de.unistuttgart.informatik.fius.jvk.Texture;
Expand Down Expand Up @@ -88,7 +89,7 @@ public boolean canCollectNut() {
*
* @return a List of all Nuts on Totoros field
*/
public List<Nut> getCurrentlyCollectableCoins() {
public List<Nut> getCurrentlyCollectableNuts() {
return this.getCurrentlyCollectableEntities(Nut.class, true);
}

Expand Down Expand Up @@ -130,4 +131,6 @@ public void setNutsInPocket(int amountOfNuts) {
public int getNutsInPocket() {
return this.getInventory().get(Nut.class, true).size();
}


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


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ public void run(Simulation sim) {
pm.placeEntityAt(totoro, new Position(0, 0));

//Implementation here

}

private void movePattern(Totoro totoro) {

}

private void dropFourCoinsAndTurnLeft(Totoro totoro) {
private void dropFourNutsAndTurnLeft(Totoro totoro) {
//write the Code for f) here
//make totoro drop four nuts
//make totoro turn Left

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import de.unistuttgart.informatik.fius.icge.simulation.tools.*;
import de.unistuttgart.informatik.fius.jvk.provided.entity.*;
import de.unistuttgart.informatik.fius.jvk.provided.factories.*;
import de.unistuttgart.informatik.fius.jvk.provided.programs.SafeWalkProgram;
import de.unistuttgart.informatik.fius.jvk.provided.shapes.*;


Expand All @@ -36,6 +37,7 @@ public void run(Simulation sim) {
Line obstacle = new Line(new Position(3, -rng.nextInt(5)), new Position(3, rng.nextInt(10)));
pm.placeEntityAtEachPosition(new BushFactory(), obstacle);
// put your implementation below this comment

}

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



}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Sheet3Task2Verifier implements TaskVerifier {
private BasicTaskInformation taskC = new BasicTaskInformation("c) walk straight", "Walk straight until you are on a field with one or more nuts.");
private BasicTaskInformation taskD = new BasicTaskInformation("d) left or right", "Turn right on a field with exactly one nut, but don't forget to collect the nut.");
private BasicTaskInformation taskE = new BasicTaskInformation(
"d) the other direction", "When on a field with more than one nut turn left, and collect one of the nuts before stepping of the field."
"e) the other direction", "When on a field with more than one nut turn left, and collect one of the nuts before stepping of the field."
);
private BasicTaskInformation taskF = new BasicTaskInformation("f) don't walk into bushes", "Before you walk into a bush you should turn around.");
private BasicTaskInformation taskG = new BasicTaskInformation("g) enough food", "Walk until you have collected 20 nuts or step on a field with exactly 9 nuts");
Expand Down
Binary file modified sheets/4/figures/playfield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sheets/4/figures/smily.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions sheets/vorkurs.cls
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
\usetikzlibrary{matrix}
\tcbuselibrary{listings,breakable}


\RequirePackage{cleveref}
\crefname{Bild}{Bild}{Bilder}
%% Testing...
\RequirePackage{lipsum}
%\RequirePackage{todo}
Expand Down

0 comments on commit 631bef1

Please sign in to comment.