Skip to content
This repository has been archived by the owner on May 31, 2018. It is now read-only.

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Berger committed Sep 6, 2017
1 parent fa9ca99 commit 2ae0d50
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Assets/Prefabs/Rodent.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ MonoBehaviour:
serializedVersion: 2
m_Bits: 256
jumpForce: 10
rayScanRange: 5
rayScanRange: 8
alive: 1
17 changes: 16 additions & 1 deletion Assets/Scenes/main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 086ddfdefeb360843b4601e5c9ad337e, type: 3}
m_Name:
m_EditorClassIdentifier:
cameraManager: {fileID: 1377496960}
rodentPrefab: {fileID: 845664840}
rodentParent: {fileID: 1558692386}
floorParent: {fileID: 1394716947}
moveSpeedModifier: 3.5
zSpacing: 0.275
jumpTrigger: 0.5
timeScale: 1
timeScale: 2
aliveDisplay: {fileID: 1556306724}
fitnessDisplay: {fileID: 1733468739}
generationDisplay: {fileID: 1342257940}
Expand Down Expand Up @@ -966,6 +967,7 @@ GameObject:
- component: {fileID: 1377496958}
- component: {fileID: 1377496957}
- component: {fileID: 1377496956}
- component: {fileID: 1377496960}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand Down Expand Up @@ -1037,6 +1039,19 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 20, y: 15, z: 0}
--- !u!114 &1377496960
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1377496955}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2fd4aabb6d43de240a16aeb40a0d8dd7, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 0}
cameraOffset: {x: -3, y: 8, z: -12}
--- !u!1 &1394716946
GameObject:
m_ObjectHideFlags: 0
Expand Down
22 changes: 22 additions & 0 deletions Assets/Scripts/Game/CameraManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEngine;


namespace Neuroevolution.Game
{
public class CameraManager : MonoBehaviour
{

public Transform target;

[SerializeField] Vector3 cameraOffset;


void LateUpdate()
{
if(target == null)
return;

transform.position = new Vector3(target.position.x + cameraOffset.x, cameraOffset.y, cameraOffset.z);
}
}
}
13 changes: 13 additions & 0 deletions Assets/Scripts/Game/CameraManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Scripts/Game/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Neuroevolution.Game
{
public class GameController : MonoBehaviour
{
[SerializeField] CameraManager cameraManager;
[SerializeField] Rodent rodentPrefab;
[SerializeField] Transform rodentParent;
[SerializeField] Transform floorParent;
Expand Down Expand Up @@ -126,6 +127,8 @@ void InstantiateRodents(int amount)
}

Debug.Log("Instantiated the Rodents");

cameraManager.target = rodents[0].transform;
}


Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Game/Rodent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public float[] getInput()

float obstacleInput = 2 * hit.distance / rayScanRange - 1;

if(index == 0)
{
Debug.Log("<color=blue>DS:" + obstacleInput + "</color>");
}
// if(index == 0)
// {
// Debug.Log("<color=blue>DS:" + obstacleInput + "</color>");
// }

return new float[] { obstacleInput };
return new float[] { obstacleInput, transform.position.y / 5f };
}


Expand Down
7 changes: 2 additions & 5 deletions Assets/Scripts/Neural Network/Generation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ public NetworkSaveState[] breedNextGenerationNetworks()

for(int i = 0; i < randomAmount; i++)
{
if(nextNetworks.Count < Settings.populationSize)
{
Network net = new Network(Settings.inputNeurons, Settings.hiddenNeurons, Settings.ouputNeurons);
nextNetworks.Add(net.saveState());
}
Network net = new Network(Settings.inputNeurons, Settings.hiddenNeurons, Settings.ouputNeurons);
nextNetworks.Add(net.saveState());
}

int breederIndex = 0;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Neuroevolution
{
public static class Settings
{
public static readonly int inputNeurons = 1;
public static readonly int[] hiddenNeurons = {};
public static readonly int inputNeurons = 2;
public static readonly int[] hiddenNeurons = {2};
public static readonly int ouputNeurons = 1;

public static readonly int populationSize = 50;
Expand Down

0 comments on commit 2ae0d50

Please sign in to comment.