small changes

This commit is contained in:
2018-02-27 10:47:06 +01:00
parent ada39c72b6
commit 83ae8d18fb
2 changed files with 15 additions and 6 deletions

View File

@@ -46,7 +46,7 @@
kan veranderen tijdens uitvoering kan veranderen tijdens uitvoering
defensief defensief
### massa ### massa - DONE?
afh. van radius afh. van radius
in kg in kg
p = 1062 kg/m3 p = 1062 kg/m3
@@ -72,7 +72,7 @@
type niet gezegd -> double (radius, coordinaat) type niet gezegd -> double (radius, coordinaat)
Double.NEGATIVE_INFINITY && Double.POSITIVE_INFINITY toegestaan Double.NEGATIVE_INFINITY && Double.POSITIVE_INFINITY toegestaan
### Turning and Moving ##Turning and Moving
### method move ### method move
change location worm (location, orientation, number of steps) change location worm (location, orientation, number of steps)
@@ -94,7 +94,7 @@
total cost step: abs(cos theta) + abs(4sin theta) total cost step: abs(cos theta) + abs(4sin theta)
action point: int (round to next int) action point: int (round to next int)
### Jumping ## Jumping
### method jump ### method jump
change location (respect orientation and action points) change location (respect orientation and action points)
@@ -117,7 +117,7 @@
jumping: consumes all remaining action points jumping: consumes all remaining action points
jumpTime and jumpStep must not change attributes of a worm jumpTime and jumpStep must not change attributes of a worm
### Opmerkingen ## Opmerkingen
future: involve further trajectory parameters or geographical features future: involve further trajectory parameters or geographical features

View File

@@ -13,7 +13,6 @@ public class Worm {
private double minRadius; private double minRadius;
// mass // mass
private double mass; private double mass;
private final int rho = 1062;
// points // points
private int points; private int points;
@@ -104,6 +103,9 @@ public class Worm {
} }
public void setRadius(double radius) { public void setRadius(double radius) {
if (radius < this.minRadius) {
throw new IllegalArgumentException();
}
this.radius = radius; this.radius = radius;
setMass(radius); setMass(radius);
} }
@@ -122,7 +124,8 @@ public class Worm {
private void setMass(double radius) { private void setMass(double radius) {
double mass = this.rho * (4 / 3 * Math.PI * Math.pow(radius, 3)); final int rho = 1062;
double mass = rho * (4 / 3 * Math.PI * Math.pow(radius, 3));
this.mass = mass; this.mass = mass;
setMaxPoints(mass); setMaxPoints(mass);
@@ -133,6 +136,11 @@ public class Worm {
} }
public void setPoints(int points) { public void setPoints(int points) {
if (points > this.maxPoints) {
points = this.maxPoints;
}
else if (points < 0)
points = 0;
this.points = points; this.points = points;
} }
@@ -141,5 +149,6 @@ public class Worm {
} }
private void setMaxPoints(double maxPoints) { private void setMaxPoints(double maxPoints) {
this.maxPoints = (int) Math.round(maxPoints); this.maxPoints = (int) Math.round(maxPoints);
setPoints(this.points);
} }
} }