Skip to content
Snippets Groups Projects
Commit cc11dbf1 authored by AxelCarayon's avatar AxelCarayon
Browse files

agents cannot go out of bounds

parent b08b1636
No related branches found
No related tags found
No related merge requests found
......@@ -33,13 +33,16 @@ public class Agent {
private void move() {
int move = r.nextInt(4);
position = switch (move) {
Point newPosition = switch (move) {
case IEnvironment.LEFT -> new Point(position.x-environment.RADIUS,position.y);
case IEnvironment.RIGHT -> new Point(position.x+environment.RADIUS,position.y);
case IEnvironment.UP -> new Point(position.x,position.y-environment.RADIUS);
case IEnvironment.DOWN -> new Point(position.x,position.y+environment.RADIUS);
default -> throw new IllegalStateException("Unexpected value: " + move);
};
if (newPosition.x <= environment.getWidth() && newPosition.x >= 0 && newPosition.y <= environment.getHeight() && newPosition.y >=0 ) {
position = newPosition;
}
}
private void contact() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment