1
0
mirror of https://github.com/fazo96/AIrium.git synced 2025-01-10 09:34:20 +01:00

implemented logger

This commit is contained in:
Enrico Fasoli 2015-07-01 16:07:29 +02:00
parent d5cff69151
commit 75d91da46c
5 changed files with 46 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;
}