diff --git a/core/src/com/mygdx/game/Game.java b/core/src/com/mygdx/game/Game.java index e4702f3..ee023fa 100644 --- a/core/src/com/mygdx/game/Game.java +++ b/core/src/com/mygdx/game/Game.java @@ -109,7 +109,7 @@ public class Game extends ApplicationAdapter { Creature c = world.getSelectedCreature(); renderer.setColor(1, 1, 1, 1); // Draw selection rectangle - renderer.rect(c.getX() - c.getSize() / 2, c.getY() - c.getSize() / 2, c.getSize(), c.getSize()); + renderer.rect(c.getX() - c.getSize(), c.getY() - c.getSize(), c.getSize()*2, c.getSize()*2); // Draw brain overlayRenderer.begin(); c.getBrain().render(overlayRenderer); @@ -129,4 +129,8 @@ public class Game extends ApplicationAdapter { public boolean isPaused() { return paused; } + + public void setPaused(boolean paused) { + this.paused = paused; + } } diff --git a/core/src/logic/Creature.java b/core/src/logic/Creature.java index 5505a99..ad45ac8 100644 --- a/core/src/logic/Creature.java +++ b/core/src/logic/Creature.java @@ -15,7 +15,7 @@ import logic.neural.Brain; public class Creature extends Element implements Runnable { public static int default_radius = 20, max_hp = 100; - public static float max_speed = 3, max_beak = default_radius / 4,fov,sightRange; + public static float max_speed = 3, max_beak = default_radius / 4, fov, sightRange; private Brain brain; private float dir, hp, prevHp, speed, fitness, rotSpeed, beak; @@ -262,26 +262,27 @@ public class Creature extends Element implements Runnable { float relAngle = (float) (Math.atan2(getY() - e.getY(), getX() - e.getX())); if (tempDist < dist || seen == null) { // Check if Visible - if (Math.abs(relAngle - ndir) < fov) { + float tempAngle = Math.abs(relAngle - ndir); + if (tempAngle < fov) { // Visible seen = e; angle = relAngle - ndir; dist = tempDist; + // Check if attackable + if (beak > beak/2 && tempDist < beak * 1.5f && tempAngle < fov/2) { + // Attacking! + hp++; + fitness++; + if (hp > max_hp) { + hp = max_hp; + } + killing = true; + Creature c = (Creature) e; + c.setHp(c.getHp() - 0.2f); + } } //Log.log(Log.DEBUG,"RelAngle "+relAngle+" Dir "+ndir); } - // Check if attackable - if (e instanceof Creature && beak > 5 && tempDist < beak * 1.5f && Math.abs(relAngle - ndir) < (float) Math.PI / 10f) { - // Attacking! - hp++; - fitness++; - if (hp > max_hp) { - hp = max_hp; - } - killing = true; - Creature c = (Creature) e; - c.setHp(c.getHp() - 0.2f); - } } if (seen != null) { newSights[1] = new Sight(seen, dist, angle); diff --git a/core/src/logic/World.java b/core/src/logic/World.java index 949268f..3b52743 100644 --- a/core/src/logic/World.java +++ b/core/src/logic/World.java @@ -155,7 +155,12 @@ public class World implements Runnable { } else { // Evolve previous gen graveyard.sort(creatureComp); // sort by fitness // Prepare best agent list - int topSize = (int) Math.round(graveyard.size() * 0.05f); + int topSize; + if (graveyard.size() == 1) { + topSize = 1; + } else { + topSize = (int) Math.max(2,Math.round(graveyard.size() * 0.05f)); + } Creature[] top = new Creature[topSize]; // Calculate avg fitness and prepare best agent list float avgFitness = 0; @@ -173,7 +178,7 @@ public class World implements Runnable { for (Creature c : graveyard) { int first = (int) Math.floor(Math.random() * topSize); int sec = first; - while (sec == first) { + while (sec == first && topSize > 1) { sec = (int) Math.floor(Math.random() * topSize); } float[][][] n = null; @@ -196,7 +201,7 @@ public class World implements Runnable { width = Math.round(options.getOrDefault("world_width", 2000f)); height = Math.round(options.getOrDefault("world_height", 2000f)); fpsLimit = Math.round(options.getOrDefault("fps_limit", 60f)); - creatPerGen = Math.round(options.getOrDefault("creatures_per_generation", (float) Math.min(Math.round(width * height / 20000), 50))); + creatPerGen = Math.round(options.getOrDefault("number_of_creatures", (float) Math.min(Math.round(width * height / 20000), 50))); nPlants = Math.round(options.getOrDefault("number_of_plants", width * height / 5500f)); multithreading = options.getOrDefault("enable_multithreading", -1f) > 0; Creature.default_radius = Math.round(options.getOrDefault("creature_radius", 20f)); @@ -214,6 +219,7 @@ public class World implements Runnable { } else { r = Vegetable.default_radius; } + int i = 0; do { overlaps = false; x = (int) (Math.random() * width); @@ -223,7 +229,7 @@ public class World implements Runnable { overlaps = true; } } - } while (overlaps); + } while (overlaps && i++ < 20); if (isCreature) { Log.log(Log.DEBUG, "New Creat: " + x + " " + y); Creature c = new Creature(x, y); diff --git a/desktop/src/gui/GUI.form b/desktop/src/gui/GUI.form index 637bb6f..8e5f62e 100644 --- a/desktop/src/gui/GUI.form +++ b/desktop/src/gui/GUI.form @@ -1,6 +1,6 @@ -