public static void Run() { var buffer = new NameIndexedBuffer(); buffer.AddIndex("one", 1); buffer.AddIndex("two", 2); buffer.AddIndex("three", 3); buffer.AddIndex("any", 8); buffer.SetData("one", 1); buffer.SetData("two", 22, 44); buffer.SetData("three", 333, 444, 555); buffer.SetData("any", new float[] { 81, 82, 83, 84, 85, 86, 87, 89 }); foreach (float n in buffer.data) { Console.Write($" <{n}> "); } Console.WriteLine(); }
// ======================================= void Awake() { // Sensor data /** * x * y * health_percent * Can shoot * forward_x * forward_y * * eye_active * eye_x * eye_y * . * . drive by eyeCount * . * hit_from_active * hit_from_x * hit_from_y */ this.eyes = new Vector3[this.eyeCount]; this.sensorBuffer = new NameIndexedBuffer(); this.sensorBuffer.AddIndex("time", 1); this.sensorBuffer.AddIndex("position", 2); this.sensorBuffer.AddIndex("health", 1); this.sensorBuffer.AddIndex("shoot_time", 1); this.sensorBuffer.AddIndex("forward", 2); for (int i = 0; i < this.eyeCount; i++) { this.sensorBuffer.AddIndex($"eye_{i}", 3); } this.sensorBuffer.AddIndex("hit_from", 3); // Reaction data /** * forward * backwards * turn left * turn right * shoot */ this.reaction = new float[5]; this.brain = BrainFactory.Create() .WithInput(this.sensorBuffer.size) .WithLayer(16, LayerType.Tanh) .WithLayer(8, LayerType.Tanh) .WithLayer(this.reaction.Length, LayerType.Sigmoid) .WithWeightBiasAmplitude(10f) .Build(); this.physics = GetComponent <Rigidbody>(); this.positionRecorder = GetComponent <PositionRecorder>(); this.lookToFriend = new FloatRecorder(); this.lookToFoe = new FloatRecorder(); }