Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor agent generation #255

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions src/main/java/app/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,36 +223,21 @@ else if (r < 0.75)
private Vector randPosition(Rectangle2D r)
{
Vector v;
int tries = 0;
try
do
{
do
{
tries++;
double x = r.getMinX() + (Math.random() * (r.getMaxX() - r.getMinX()));
double y = r.getMinY() + (Math.random() * (r.getMaxY() - r.getMinY()));
v = new Vector(x, y);
if (tries > 500)
{
throw new RuntimeException("SpawnArea not big enough for number of agents");
}
} while (!clearSpot(v));

return v;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
double x = r.getMinX() + (Math.random() * (r.getMaxX() - r.getMinX()));
double y = r.getMinY() + (Math.random() * (r.getMaxY() - r.getMinY()));
v = new Vector(x, y);
} while(!clearSpot(v));
return v;
}

private boolean clearSpot(Vector v)
{
for(Agent agent: agents)
{
double dist = agent.getPosition().dist(v);
if(dist < 2*agent.getRadius())
if(dist < 2 * agent.getRadius())
return false;
}
return true;
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/testing/FileParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import app.controller.settings.Settings;
import app.model.Map;
import javafx.geometry.Rectangle2D;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -92,8 +93,6 @@ public class FileParserTest
assertEquals(new Vector(50, 90), s.getFurniture().get(6).getTeleportTo());
assertEquals(0.0, s.getFurniture().get(6).getTeleportRotation(), 0.001);
assertEquals("teleport", s.getFurniture().get(6).getType().label);

Map map = new Map(s);
}

@Test void testCreationOfSettingsNewMapWithComments()
Expand All @@ -119,7 +118,5 @@ public class FileParserTest
assertEquals(new Vector(50, 90), s.getFurniture().get(6).getTeleportTo());
assertEquals(0.0, s.getFurniture().get(6).getTeleportRotation(), 0.001);
assertEquals("teleport", s.getFurniture().get(6).getType().label);

Map map = new Map(s);
}
}