diff --git a/core/src/com/mygdx/game/Log.java b/core/src/com/mygdx/game/Log.java new file mode 100644 index 0000000..35fbccc --- /dev/null +++ b/core/src/com/mygdx/game/Log.java @@ -0,0 +1,34 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.mygdx.game; + +/** + * + * @author fazo + */ +public class Log { + + public static final int ERROR = 0; + public static final int INFO = 1; + public static final int DEBUG = 2; + + private static int logLevel = 1; + + public static void log(int level, String msg) { + if (level >= logLevel) { + System.out.println(msg); + } + } + + public static int getLogLevel() { + return logLevel; + } + + public static void setLogLevel(int logLevel) { + Log.logLevel = logLevel; + } + +} diff --git a/core/src/logic/Creature.java b/core/src/logic/Creature.java index c214a62..61c4d70 100644 --- a/core/src/logic/Creature.java +++ b/core/src/logic/Creature.java @@ -2,6 +2,7 @@ package logic; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.mygdx.game.Game; +import com.mygdx.game.Log; import logic.neural.Brain; /** @@ -85,7 +86,7 @@ public class Creature extends Element { brain.input(values); // compute behavior float[] actions = brain.compute(); - System.out.println("Accel: " + actions[0] + " Rot: " + actions[1]); + Log.log(Log.DEBUG,"Accel: " + actions[0] + " Rot: " + actions[1]); speed = actions[0]*max_speed; rotSpeed = actions[1]/10; } @@ -130,7 +131,7 @@ public class Creature extends Element { if (tempDist > sightRange) { continue; } - //System.out.println("TempDist "+tempDist+" SightRange "+sightRange); + //Log.log(Log.DEBUG,"TempDist "+tempDist+" SightRange "+sightRange); if (tempDist > dist && seen != null) { continue; } @@ -142,7 +143,7 @@ public class Creature extends Element { angle = relAngle - ndir; dist = tempDist; } - //System.out.println("RelAngle "+relAngle+" Dir "+ndir); + //Log.log(Log.DEBUG,"RelAngle "+relAngle+" Dir "+ndir); } if (seen != null) { return new Sight(seen, dist, angle); diff --git a/core/src/logic/World.java b/core/src/logic/World.java index da6c0c1..b1cc1f1 100644 --- a/core/src/logic/World.java +++ b/core/src/logic/World.java @@ -5,6 +5,7 @@ */ package logic; +import com.mygdx.game.Log; import java.util.ArrayList; import java.util.Comparator; import logic.neural.Brain; @@ -107,12 +108,12 @@ public class World { } } while (overlaps); if (isCreature) { - System.out.println("New Creat: " + x + " " + y); + Log.log(Log.INFO,"New Creat: " + x + " " + y); Creature c = new Creature(x, y); elements.add(c); creatures.add(c); } else { - System.out.println("New Veg: " + x + " " + y); + Log.log(Log.INFO,"New Veg: " + x + " " + y); Vegetable v = new Vegetable(x, y); elements.add(v); plants.add(v); diff --git a/core/src/logic/neural/Brain.java b/core/src/logic/neural/Brain.java index f87ec86..a41f485 100644 --- a/core/src/logic/neural/Brain.java +++ b/core/src/logic/neural/Brain.java @@ -1,5 +1,6 @@ package logic.neural; +import com.mygdx.game.Log; import java.util.ArrayList; /** @@ -33,7 +34,7 @@ public class Brain { n.getInputs().add(new NeuralConnection(randWeight(), s)); } hidden.add(n); - System.out.println("Adding Hidden Layer " + (i + 1) + " Neuron " + j + " with " + inputs.size() + " inputs"); + Log.log(Log.DEBUG,"Adding Hidden Layer " + (i + 1) + " Neuron " + j + " with " + inputs.size() + " inputs"); } } // populate output layer @@ -48,7 +49,7 @@ public class Brain { n.getInputs().add(new NeuralConnection(randWeight(), s)); } } - System.out.println("Adding Output Layer Neuron " + i + " with " + conn + " inputs"); + Log.log(Log.DEBUG,"Adding Output Layer Neuron " + i + " with " + conn + " inputs"); outputs.add(n); } } diff --git a/core/src/logic/neural/Neuron.java b/core/src/logic/neural/Neuron.java index e4dcc1b..bbc3887 100644 --- a/core/src/logic/neural/Neuron.java +++ b/core/src/logic/neural/Neuron.java @@ -5,6 +5,7 @@ */ package logic.neural; +import com.mygdx.game.Log; import java.util.ArrayList; /** @@ -36,11 +37,10 @@ public class Neuron { for (NeuralConnection i : inputs) { a += i.compute(); } - System.out.println("Computed Value "+a+" for neuron"); cachedValueValid = true; // sigmoid function cachedValue = (float) (1 / (1 + Math.pow(Math.E, a * -1))); - System.out.println("Computed Value "+cachedValue+" for neuron"); + Log.log(Log.DEBUG,"Computed Value "+cachedValue+" for neuron"); return cachedValue; }