fixes and improved tests
This commit is contained in:
@@ -368,7 +368,7 @@ public class Worm {
|
||||
* | actionPoints = 0;
|
||||
* |this.actionPoints = actionPoints;
|
||||
*/
|
||||
public void setActionPoints(long actionPoints) {
|
||||
private void setActionPoints(long actionPoints) {
|
||||
if (actionPoints > getMaxActionPoints())
|
||||
actionPoints = getMaxActionPoints();
|
||||
else if (actionPoints < 0)
|
||||
@@ -553,7 +553,7 @@ public class Worm {
|
||||
if (numberSteps < 0)
|
||||
throw new IllegalArgumentException(); // TODO add decent exception msg
|
||||
|
||||
long cost = (long) ceil(abs(cos(getOrientation())) + abs(4 * sin(getOrientation())));
|
||||
long cost = (long) ceil(abs(cos(getOrientation())) + abs(4 * sin(getOrientation()))) * numberSteps;
|
||||
|
||||
if (cost > getActionPoints())
|
||||
throw new IllegalArgumentException(); // TODO add decent exception msg
|
||||
@@ -589,7 +589,7 @@ public class Worm {
|
||||
*/
|
||||
public void turn(double angle) {
|
||||
assert canTurn(angle);
|
||||
setOrientation((getOrientation() + angle) % (2 * PI));
|
||||
setOrientation(getOrientation() + angle);
|
||||
subtractActionPoints(abs(angle));
|
||||
}
|
||||
|
||||
@@ -605,7 +605,8 @@ public class Worm {
|
||||
| (getActionPoints() - (long) ceil(toDegrees(angle) / 6) >= 0) )
|
||||
*/
|
||||
private boolean canTurn(double angle) {
|
||||
return 0 <= angle && angle < (2 * PI) &&
|
||||
double currentAngle = this.getOrientation();
|
||||
return 0 <= angle + currentAngle && angle + currentAngle < (2 * PI) &&
|
||||
!Double.isNaN(angle) &&
|
||||
getActionPoints() - (long) ceil(toDegrees(angle) / 6) >= 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user