Ml-AgentsのOnActionReceived(float[] vectorActions)のエラー
解決したいこと
public override void OnActionReceived(float[] vectorActions) のエラー
現在、ML-Agentsで人工知能を作っているのですが、参考書に書かれてる通りにプログラミングを行いました。
しかし、 public override void OnActionReceived(float[] vectorActions) の引数がエラーになってしまいます。
エラー
Assets/EllenAgent.cs(84,30): error CS0115: 'EllenAgent.OnActionReceived(float[])': no suitable method found to override
よく分からないのですが、 float[] vectorActions を ActionBuffers actionBuffers に変えても下記のようにエラーが出てしまいます。
エラー
Assets/EllenAgent.cs(84,47): error CS0246: The type or namespace name 'ActionBuffers' could not be found (are you missing a using directive or an assembly reference?)
どうすればエラーが治るでしょうか
該当するソースコード
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Gamekit3D;
public class EllenAgent : Agent
{
public GameObject enemy;
PlayerInput input;
Damageable damageable;
public int maxEnemyNum;
int currentEnemyNum;
GameObject target;
float targetDistance;
public override void Initialize()
{
this.input = GetComponent<PlayerInput>();
this.damegeable = GetComponent<Damegeable>();
}
public override void OnEpisodeBegin()
{
this.target = null;
this.targetDistance = 0;
this.damegeable.ResetDamage();
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
for (int i = 0; i < enemies.Length; i++)
{
GameObject.Destroy(enemies[i]);
}
this.currentEnemyNum = this.maxEnemyNum;
for (int i = 0; i < this.maxEnemyNum; i++)
{
Vector3 position = new Vector3(Random.Range(
-23f, 23f), 0.0f, Random.Range(-23f, 23f));
Quaternion rotation = Quaternion.Euler(0, Random.Range(0f, 360f), 0);
Instantiate(enemy, position, rotation);
}
}
public override void CollectObservations (VectorSensor sensor)
{
GameObject enemy = GetNearEnemy();
if (enemy != null)
{
sensor.AddObservation((enemy.transform .position.x-this.
transform.position.x)/25f); //一番近い敵のX座標
sensor.AddObservation ((enemy. transform.position.z-thistransform.position.z)/25f); //一番近い敵のZ座標
}
else
{
sensor.AddObservation(Of) ;
sensor.AddObservation(Of);
}
}
public GameObject GetNearEnemy()
{
Vector3 ellenPos = this.transform.position;
float minDistance = 999f ;
GameObject enemy = null;
GameObject [] enemies = GameObject.FindGameObjectsWithTag("Enemy");
for (int i = 0; i < enemies.Length; i++)
{
float distance = (ellenPos - enemies[i].transform.position).sqrMagnitude;
if (minDistance > distance)
{
minDistance = distance;
enemy = enemies[i];
}
}
return enemy;
}
public override void OnActionReceived(float[] vectorActions)
{
this.input.SetAction(vectorActions);
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
if (this.currentEnemyNum > enemies.Length)
{
//print("reward>>>"+(this.currentEnemyNum - enemies.Length));
AddReward(this.currentEnemyNum - enemies.Length);
this.currentEnemyNum = enemies.Length;
if (enemies.Length == 0) EndEpisode();
}
GameObject enemy = GetNearEnemy();
if (enemy != null)
{
float distance = (this.transform.position - enemy.transform.position).sqrMagnitude;
if (this.target == enemy)
{
if (this.targetDistance > distance)
{
float reward = (this.targetDistancev - distance)/10000f;
this.targetDistance = distance;
AddReward(reward);
}
} else {
this.target = enemy;
this.targetDistance = distance;
}
}
AddReward(-0.0001f);
//print("reward>>>"+GetCumulativeReward());
}
}
例)
def greet
puts Hello World
end
自分で試したこと
ここに問題・エラーに対して試したことを記載してください。
0