Skip to content

Commit 631bef1

Browse files
authored
Code fixes (#177)
* added Sheet2Task7 and its verifier * fixed some code issues * edited vorkurs.cls
1 parent bc8650a commit 631bef1

File tree

11 files changed

+219
-9
lines changed

11 files changed

+219
-9
lines changed

project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Sooty_mans.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class Sooty_mans extends Totoro {
2121

2222
/**
23-
* changes the appearance of the player in the game from Neo to Morpheus
23+
* changes the appearance of the player in the game from Totoro to Sooty_mans
2424
*/
2525
@Override
2626
protected String getTextureHandle() {
@@ -31,5 +31,4 @@ protected String getTextureHandle() {
3131
* TODO: Implement the operations of sooty_mans here
3232
*
3333
*/
34-
3534
}

project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Totoro.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

11+
import de.unistuttgart.informatik.fius.icge.simulation.Position;
1112
import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute;
1213
import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionMethod;
1314
import de.unistuttgart.informatik.fius.jvk.Texture;
@@ -88,7 +89,7 @@ public boolean canCollectNut() {
8889
*
8990
* @return a List of all Nuts on Totoros field
9091
*/
91-
public List<Nut> getCurrentlyCollectableCoins() {
92+
public List<Nut> getCurrentlyCollectableNuts() {
9293
return this.getCurrentlyCollectableEntities(Nut.class, true);
9394
}
9495

@@ -130,4 +131,6 @@ public void setNutsInPocket(int amountOfNuts) {
130131
public int getNutsInPocket() {
131132
return this.getInventory().get(Nut.class, true).size();
132133
}
134+
135+
133136
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package de.unistuttgart.informatik.fius.jvk.provided.programs;
2+
3+
import de.unistuttgart.informatik.fius.icge.simulation.programs.Program;
4+
import de.unistuttgart.informatik.fius.jvk.provided.entity.Totoro;
5+
6+
7+
public class SafeWalkProgram implements Program<Totoro> {
8+
9+
@Override
10+
public void run(Totoro totoro) {
11+
if (totoro.canMove()) {
12+
totoro.move();
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package de.unistuttgart.informatik.fius.jvk.tasks;
2+
3+
import de.unistuttgart.informatik.fius.icge.simulation.Position;
4+
import de.unistuttgart.informatik.fius.icge.simulation.Simulation;
5+
import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task;
6+
import de.unistuttgart.informatik.fius.icge.simulation.tools.PlayfieldModifier;
7+
import de.unistuttgart.informatik.fius.jvk.provided.entity.*;
8+
import de.unistuttgart.informatik.fius.jvk.provided.factories.*;
9+
import de.unistuttgart.informatik.fius.jvk.provided.shapes.*;
10+
11+
public class Sheet2Task7 implements Task {
12+
13+
@Override
14+
public void run(Simulation sim) {
15+
PlayfieldModifier pm = new PlayfieldModifier(sim.getPlayfield());
16+
Totoro totoro1 = new Totoro();
17+
Totoro totoro2 = new Totoro();
18+
Totoro totoro3 = new Totoro();
19+
Totoro totoro4 = new Totoro();
20+
pm.placeEntityAt(totoro1, new Position(0, 2));
21+
pm.placeEntityAt(totoro4, new Position(0, 0));
22+
pm.placeEntityAt(totoro3, new Position(2, 2));
23+
pm.placeEntityAt(totoro2, new Position(2, 0));
24+
totoro4.setNutsInPocket(42);
25+
totoro2.setNutsInPocket(42);
26+
totoro1.turnClockWise();
27+
totoro3.setNutsInPocket(13);
28+
totoro3.turnClockWise();
29+
totoro1.setNutsInPocket(7);
30+
totoro3.turnClockWise();
31+
32+
33+
}
34+
35+
}

project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet3Task3.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ public void run(Simulation sim) {
3030
pm.placeEntityAt(totoro, new Position(0, 0));
3131

3232
//Implementation here
33-
33+
3434
}
3535

3636
private void movePattern(Totoro totoro) {
3737

3838
}
3939

40-
private void dropFourCoinsAndTurnLeft(Totoro totoro) {
40+
private void dropFourNutsAndTurnLeft(Totoro totoro) {
4141
//write the Code for f) here
4242
//make totoro drop four nuts
4343
//make totoro turn Left
44+
4445
}
4546

4647
}

project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet4Task4.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import de.unistuttgart.informatik.fius.icge.simulation.tools.*;
1919
import de.unistuttgart.informatik.fius.jvk.provided.entity.*;
2020
import de.unistuttgart.informatik.fius.jvk.provided.factories.*;
21+
import de.unistuttgart.informatik.fius.jvk.provided.programs.SafeWalkProgram;
2122
import de.unistuttgart.informatik.fius.jvk.provided.shapes.*;
2223

2324

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

4143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package de.unistuttgart.informatik.fius.jvk.verifier;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Iterator;
6+
import java.util.stream.Collectors;
7+
8+
import de.unistuttgart.informatik.fius.icge.simulation.Position;
9+
import de.unistuttgart.informatik.fius.icge.simulation.Simulation;
10+
import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier;
11+
import de.unistuttgart.informatik.fius.icge.simulation.actions.*;
12+
import de.unistuttgart.informatik.fius.icge.ui.TaskInformation;
13+
import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus;
14+
import de.unistuttgart.informatik.fius.jvk.provided.BasicTaskInformation;
15+
import de.unistuttgart.informatik.fius.jvk.provided.entity.Nut;
16+
17+
18+
public class Sheet2Task7Verifier implements TaskVerifier {
19+
20+
private BasicTaskInformation task;
21+
22+
private BasicTaskInformation taskB = new BasicTaskInformation("b) Find the differences between the totoros.", "Find the differences between the totoros.", TaskVerificationStatus.SUCCESSFUL);
23+
24+
private ActionLog actionLog;
25+
26+
public Sheet2Task7Verifier() {
27+
List<BasicTaskInformation> subTasks = new ArrayList<>();
28+
subTasks.add(this.taskB);
29+
this.task = new BasicTaskInformation("Sheet 2 Task 7", "Learn how differentiate objects and classes", subTasks);
30+
}
31+
32+
@Override
33+
public void attachToSimulation(Simulation sim) {
34+
this.actionLog = sim.getActionLog();
35+
}
36+
37+
@Override
38+
public void verify() {
39+
System.out.println("Verify");
40+
List<EntitySpawnAction> spawnActions = this.actionLog.getActionsOfType(EntitySpawnAction.class, true);
41+
42+
List<Position> coinPositions = spawnActions.stream()
43+
.filter((action) -> (action.getEntity() instanceof Nut))
44+
.map((action) -> action.getPosition())
45+
.sorted((a, b) -> {
46+
if (a.getY() < b.getY()) return -1;
47+
if (a.getY() == b.getY()) {
48+
if (a.getX() < b.getX()) return -1;
49+
if (a.getX() == b.getX()) return 0;
50+
}
51+
return 1;
52+
})
53+
.collect(Collectors.toList());
54+
55+
// subtask b)
56+
int nrOfCoinsSpawned = coinPositions.size();
57+
if (nrOfCoinsSpawned >= 5) {
58+
this.taskB = this.taskB.updateStatus(TaskVerificationStatus.SUCCESSFUL);
59+
}
60+
61+
List<BasicTaskInformation> subTasks = new ArrayList<>();
62+
subTasks.add(this.taskB);
63+
64+
if (subTasks.stream().allMatch(subTask -> subTask.getTaskStatus().equals(TaskVerificationStatus.SUCCESSFUL))) {
65+
this.task = this.task.updateStatus(TaskVerificationStatus.SUCCESSFUL);
66+
}
67+
68+
this.task = this.task.updateSubTasks(subTasks);
69+
}
70+
71+
/**
72+
* Check if a field with at least {@code nrOfCoins} exists.
73+
*/
74+
private boolean checkMultiCoinsField(List<Position> coinPositions, int nrOfCoins) {
75+
Position currentPos = null;
76+
int currentCount = 0;
77+
78+
Iterator<Position> positions = coinPositions.iterator();
79+
80+
while (positions.hasNext()) {
81+
Position p = positions.next();
82+
if (currentPos == null || !p.equals(currentPos)) {
83+
if (currentCount == nrOfCoins) { // found field with right coincount
84+
return true;
85+
}
86+
currentPos = p;
87+
currentCount = 0;
88+
}
89+
currentCount++;
90+
if (!positions.hasNext()) { // special check for end of list
91+
if (currentCount == nrOfCoins) { // found field with right coincount
92+
return true;
93+
}
94+
}
95+
}
96+
97+
return false;
98+
}
99+
100+
/**
101+
* Count the number of horizontal lines of length {@code lineLength}.
102+
*/
103+
private int countLines(List<Position> coinPositions, int lineLength) {
104+
if(coinPositions.isEmpty()){
105+
return 0;
106+
}
107+
int currentX = coinPositions.get(0).getX();
108+
int currentY = coinPositions.get(0).getY();
109+
int rowCount = 0;
110+
int currentLength = 0;
111+
112+
int lineCount = 0;
113+
114+
Iterator<Position> positions = coinPositions.iterator();
115+
116+
while (positions.hasNext()) {
117+
Position p = positions.next();
118+
if (currentY == p.getY()) {
119+
if (currentX + currentLength == p.getX()) {
120+
currentLength++;
121+
if (!positions.hasNext()) {
122+
// special check for end of Iterator
123+
if (currentLength == lineLength) {
124+
// only count lines of the exact length specified
125+
lineCount++;
126+
}
127+
}
128+
} else {
129+
if (currentLength == lineLength) {
130+
// only count lines of the exact length specified
131+
lineCount++;
132+
}
133+
currentX = p.getX();
134+
currentLength = 1;
135+
}
136+
} else {
137+
if (currentLength == lineLength) {
138+
// only count lines of the exact length specified
139+
lineCount++;
140+
}
141+
// start new row
142+
currentY = p.getY();
143+
currentX = p.getX();
144+
currentLength = 1;
145+
}
146+
}
147+
148+
return lineCount;
149+
}
150+
151+
@Override
152+
public TaskInformation getTaskInformation() {
153+
return this.task;
154+
}
155+
156+
157+
158+
}

project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet3Task2Verifier.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Sheet3Task2Verifier implements TaskVerifier {
3030
private BasicTaskInformation taskC = new BasicTaskInformation("c) walk straight", "Walk straight until you are on a field with one or more nuts.");
3131
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.");
3232
private BasicTaskInformation taskE = new BasicTaskInformation(
33-
"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."
33+
"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."
3434
);
3535
private BasicTaskInformation taskF = new BasicTaskInformation("f) don't walk into bushes", "Before you walk into a bush you should turn around.");
3636
private BasicTaskInformation taskG = new BasicTaskInformation("g) enough food", "Walk until you have collected 20 nuts or step on a field with exactly 9 nuts");

sheets/4/figures/playfield.png

-3.99 KB
Loading

sheets/4/figures/smily.png

12.1 KB
Loading

sheets/vorkurs.cls

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
\usetikzlibrary{matrix}
5959
\tcbuselibrary{listings,breakable}
6060

61-
62-
\RequirePackage{cleveref}
63-
\crefname{Bild}{Bild}{Bilder}
6461
%% Testing...
6562
\RequirePackage{lipsum}
6663
%\RequirePackage{todo}

0 commit comments

Comments
 (0)