From 1a049e97cf1c89e211ac56e4ee72c2f3ee5b642e Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 4 Mar 2020 14:25:31 +0100 Subject: [PATCH] Do not test ambiguous train placement, clean up code --- newest_ilias_shit_input.txt | 6 +++ newest_ilias_shit_output.txt | 5 ++ src/edu/kit/informatik/MainTest.java | 5 ++ .../kit/informatik/model/RailwayNetwork.java | 46 ++----------------- 4 files changed, 20 insertions(+), 42 deletions(-) create mode 100644 newest_ilias_shit_input.txt create mode 100644 newest_ilias_shit_output.txt diff --git a/newest_ilias_shit_input.txt b/newest_ilias_shit_input.txt new file mode 100644 index 0000000..69f61e4 --- /dev/null +++ b/newest_ilias_shit_input.txt @@ -0,0 +1,6 @@ +add track (0,0) -> (5,0) +add switch (5,0) -> (5,5),(10,0) +set switch 2 position (10,0) +create engine diesel T3 Emma 1 true true +add train 1 T3-Emma +exit diff --git a/newest_ilias_shit_output.txt b/newest_ilias_shit_output.txt new file mode 100644 index 0000000..8770f52 --- /dev/null +++ b/newest_ilias_shit_output.txt @@ -0,0 +1,5 @@ +1 +2 +OK +T3-Emma +diesel engine T3-Emma added to train 1 diff --git a/src/edu/kit/informatik/MainTest.java b/src/edu/kit/informatik/MainTest.java index 3bac916..c99f03a 100644 --- a/src/edu/kit/informatik/MainTest.java +++ b/src/edu/kit/informatik/MainTest.java @@ -108,6 +108,11 @@ class MainTest { cmpInOut("lgt_input.txt", "lgt_output.txt"); } + @Test + void newest_ilias_shit() throws IOException { + cmpInOut("newest_ilias_shit_input.txt", "newest_ilias_shit_output.txt"); + } + private void cmpInOut(String in, String out) throws IOException { System.setIn(new ByteArrayInputStream(readFile(in))); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/edu/kit/informatik/model/RailwayNetwork.java b/src/edu/kit/informatik/model/RailwayNetwork.java index 1f7bb50..aca7c21 100644 --- a/src/edu/kit/informatik/model/RailwayNetwork.java +++ b/src/edu/kit/informatik/model/RailwayNetwork.java @@ -211,26 +211,7 @@ public class RailwayNetwork { Vector2D nextPossiblePosition = position.add(direction); Rail possibleContainingRail = findRailPotentiallyContaining(nextPossiblePosition); if (possibleContainingRail != null && !possibleContainingRail.contains(position.subtract(direction))) { - Vector2D positionOnThatRail = possibleContainingRail.move(position, direction, 1); - /* - if ((positionOnThatRail == null || positionOnThatRail.equals(position)) && touchingRails.length == 2) { - Vector2D onRailOne = touchingRails[0].move(position, new Vector2D(direction), 1); - Vector2D onRailTwo = touchingRails[1].move(position, new Vector2D(direction), 1); - if ((position.equals(onRailOne) || onRailOne == null) && !position.equals(onRailTwo)) { - // we are moving on rail two - Vector2D newDirection = touchingRails[1].getDirectionFrom(position); - direction.copyFrom(newDirection); - return onRailTwo; - } else if ((position.equals(onRailTwo) || onRailTwo == null) && !position.equals(onRailOne)) { - Vector2D newDirection = touchingRails[0].getDirectionFrom(position); - direction.copyFrom(newDirection); - return onRailOne; - } else { - throw new RuntimeException("wtf"); - } - } - */ - return positionOnThatRail; + return possibleContainingRail.move(position, direction, 1); } if (touchingRails.length == 0) { @@ -250,30 +231,11 @@ public class RailwayNetwork { direction.copyFrom(newDirection); return onRailOne; } else { - throw new RuntimeException("wtf"); - } - /* - Vector2D nextPosition = position.add(direction); - if (touchingRails[0].contains(nextPosition) || touchingRails[0].connectsTo(nextPosition)) { - return nextPosition; - } else if (touchingRails[1].contains(nextPosition)) { - Vector2D nextDirection = touchingRails[1].getDirectionFrom(position); - direction.setX(nextDirection.getX()); - direction.setY(nextDirection.getY()); - return nextPosition; - } - Vector2D previousPosition = position.add(direction.negated()); - Rail nextRail = touchingRails[0].contains(previousPosition) - || touchingRails[0].canConnectTo(previousPosition) ? touchingRails[1] : touchingRails[0]; - Vector2D nextDirection = nextRail.getDirectionFrom(position); - if (nextDirection != null) { - direction.setX(nextDirection.getX()); - direction.setY(nextDirection.getY()); - return position.add(direction); - } else { + // this case: https://ilias.studium.kit.edu/goto.php?client_id=produktiv&target=frm_996924_139074_534267 + // it will not be tested, but simply refusing to place a train + // if there is more than one way to place it is fine return null; } - */ } /**