-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from FIUS/feature/tasks
Add tasks
- Loading branch information
Showing
11 changed files
with
244 additions
and
31 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
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
42 changes: 42 additions & 0 deletions
42
...va/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.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,42 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.internal.tasks; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.Simulation; | ||
import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; | ||
import de.unistuttgart.informatik.fius.icge.simulation.tasks.TaskRunner; | ||
|
||
|
||
/** | ||
* The standard implementation of {@link TaskRunner}. | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public class StandardTaskRunner implements TaskRunner { | ||
|
||
@Override | ||
public boolean runTask(Class<? extends Task> taskToRun, Simulation sim) { | ||
if (taskToRun == null || sim == null) throw new IllegalArgumentException("Argument is null."); | ||
|
||
try { | ||
Task task = taskToRun.getDeclaredConstructor().newInstance(); | ||
task.prepare(sim); | ||
task.solve(); | ||
return task.verify(); | ||
} catch ( | ||
InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ||
| NoSuchMethodException | SecurityException e | ||
) { | ||
throw new IllegalArgumentException("Failed to instantiate.", e); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.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,40 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.tasks; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.Simulation; | ||
|
||
|
||
/** | ||
* The interface for a task to be solved by students. | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public interface Task { | ||
/** | ||
* Prepare the simulation for this task | ||
* | ||
* @param sim | ||
* The simulation this task should be prepared in | ||
*/ | ||
void prepare(Simulation sim); | ||
|
||
/** | ||
* Solve the task | ||
*/ | ||
void solve(); | ||
|
||
/** | ||
* Verify that the task was solved correctly. | ||
* | ||
* @return true if the task was solved correctly | ||
*/ | ||
boolean verify(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/TaskRunner.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,33 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.tasks; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.Simulation; | ||
|
||
|
||
/** | ||
* The interface | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public interface TaskRunner { | ||
/** | ||
* Run the given task and verify the solution. | ||
* | ||
* @param taskToRun | ||
* The task to run; must not be null; must be possible to be instantiated without an argument | ||
* @param sim | ||
* The simulation to run the task in; must not be null | ||
* @return true if the task was completed successfully and the solution could be verified | ||
* @throws IllegalArgumentException | ||
* if the argument is null or an error occurs during instantiation | ||
*/ | ||
boolean runTask(Class<? extends Task> taskToRun, Simulation sim); | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...rio/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution1.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,37 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.example.mario.tasks; | ||
|
||
import de.unistuttgart.informatik.fius.icge.example.mario.WalkingProgram; | ||
|
||
|
||
/** | ||
* The example solution for Task1 | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public class Solution1 extends Task1 { | ||
|
||
@Override | ||
public void solve() { | ||
String walkingProgramName = "Walking"; | ||
|
||
this.sim.getEntityProgramRegistry().registerEntityProgram(walkingProgramName, new WalkingProgram()); | ||
|
||
this.sim.getSimulationClock().start(); //This can be done via UI in the future. | ||
|
||
this.sim.getEntityProgramRunner().run(walkingProgramName, this.walkingMario); | ||
|
||
while (true) { | ||
this.spinningMario.turnClockWise(); | ||
} | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...s/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task1.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,64 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.example.mario.tasks; | ||
|
||
import de.unistuttgart.informatik.fius.icge.example.mario.entity.Mario; | ||
import de.unistuttgart.informatik.fius.icge.example.mario.entity.Wall; | ||
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; | ||
|
||
|
||
/** | ||
* An example task | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public abstract class Task1 implements Task { | ||
|
||
/** | ||
* the simulation | ||
*/ | ||
Simulation sim; | ||
/** | ||
* The walking mario | ||
*/ | ||
Mario walkingMario; | ||
/** | ||
* The spinning mario | ||
*/ | ||
Mario spinningMario; | ||
|
||
@Override | ||
public void prepare(Simulation sim) { | ||
this.sim = sim; | ||
sim.getPlayfield().addEntity(new Position(-3, -1), new Wall()); | ||
sim.getPlayfield().addEntity(new Position(-3, 0), new Wall()); | ||
sim.getPlayfield().addEntity(new Position(-3, 1), new Wall()); | ||
sim.getPlayfield().addEntity(new Position(3, -1), new Wall()); | ||
sim.getPlayfield().addEntity(new Position(3, 0), new Wall()); | ||
sim.getPlayfield().addEntity(new Position(3, 1), new Wall()); | ||
|
||
this.walkingMario = new Mario(); | ||
|
||
this.spinningMario = new Mario(); | ||
|
||
sim.getPlayfield().addEntity(new Position(-1, 0), this.walkingMario); | ||
sim.getPlayfield().addEntity(new Position(0, 0), this.spinningMario); | ||
|
||
} | ||
|
||
@Override | ||
public boolean verify() { | ||
// TODO | ||
return true; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module de.unistuttgart.informatik.fius.icge.example.mario { | ||
open module de.unistuttgart.informatik.fius.icge.example.mario { | ||
requires de.unistuttgart.informatik.fius.icge.simulation; | ||
} |