mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 01:15:05 +00:00
Do not test ambiguous train placement, clean up code
This commit is contained in:
parent
57708e1b4f
commit
1a049e97cf
6
newest_ilias_shit_input.txt
Normal file
6
newest_ilias_shit_input.txt
Normal file
@ -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
|
5
newest_ilias_shit_output.txt
Normal file
5
newest_ilias_shit_output.txt
Normal file
@ -0,0 +1,5 @@
|
||||
1
|
||||
2
|
||||
OK
|
||||
T3-Emma
|
||||
diesel engine T3-Emma added to train 1
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user