diff --git a/src/edu/kit/informatik/model/ModelRailwaySimulation.java b/src/edu/kit/informatik/model/ModelRailwaySimulation.java index b93cc6b..e78f4b9 100644 --- a/src/edu/kit/informatik/model/ModelRailwaySimulation.java +++ b/src/edu/kit/informatik/model/ModelRailwaySimulation.java @@ -320,7 +320,7 @@ public class ModelRailwaySimulation { */ public boolean putTrain(final int trainId, final Vector2D position, final Vector2D direction) { Train train = getTrain(trainId); - if (train == null || !train.isProperTrain()) { + if (train == null || !train.isProperTrain() || train.isPlaced()) { return false; } diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index f05b838..0170aeb 100644 --- a/src/edu/kit/informatik/model/Train.java +++ b/src/edu/kit/informatik/model/Train.java @@ -290,7 +290,7 @@ public final class Train { // we are really leaving this rail occupiedRails.remove(leavingRail); } // else: we are still on the rail - } else if (getLength() == 1) { + } else if (getLength() == 1 && railNetwork.findContainingRail(secondToLastPosition) == null) { // we evidently just moved into another rail occupiedRails.clear(); } // else: only touched rail @@ -298,7 +298,7 @@ public final class Train { Rail nextRail = railNetwork.findContainingRail(nextPosition); if (nextRail != null) { occupiedRails.add(nextRail); - } else if (getLength() == 1) { + } else if (getLength() == 1 && railNetwork.findContainingRail(secondToLastPosition) == null) { // we evidently just moved into another rail Rail[] nextTouchingRails = railNetwork.findTouchingRails(nextPosition); Rail[] alreadyTouchingRails = railNetwork.findTouchingRails(secondToLastPosition);