• 大小:
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-29
  • 语言: 其他
  • 标签: 人工智能  

资源简介

Unity开发人工智能坦克大战项目源码

资源截图

代码片段和文件信息

using System;
using UnityEngine;

using SPINACH.AI;

namespace ArtificialTankDriver_by_QI {

public class TankDriver : MonoBehaviour {

public Tank target;
public float viewRange;


public GeneticOptimizeableNerualNetwork network;

private void Awake() {
target = GetComponent();

network = new GeneticOptimizeableNerualNetwork(53);
var actvationFunction = new TanhFunction();
for (var i = 0; i < network.activateFunctions.Length; i++) {
network.SetActivationFunctionForlayer(i actvationFunction);
}
}

public double CalculateFitness() {
network.fitness = target.score;
return network.fitness;
}

//call per training update.
public void DoSomethingUseful() {
// calculate all input features

var inputs = new double[5];
var closestEnemy = target.ClosestEnemy(viewRange);

//assuming that closest one is always the one it trying to attack.

//distance between enemy.
inputs[0] = closestEnemy != null ? Vector3.Distance(transform.position closestEnemy.position) / viewRange : 1d;
//cos to enemy.
inputs[1] = closestEnemy != null ? Vector3.Dot(transform.right (closestEnemy.position - transform.position).normalized) : 1d;
//is weapon ready ?
inputs[2] = target.weaponReady ? 1d : 0d;
// current speed.
inputs[3] = target.rigidbody.velocity.magnitude / target.maxSpeed;
// current torque.
inputs[4] = target.rigidbody.angularVelocity.magnitude / target.maxTorque;

//feedforward
var output = network.Compute(inputs);

//drive
target.SetMove((float)output[0]);
target.SetRotate((float)output[1]);
if(output[2] > 0) target.Shoot();
}

private void OnDrawGizmosSelected() {
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.positionviewRange);
}
}

}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\
     文件        6148  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\.DS_Store
     文件         452  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\.gitignore
     文件       11357  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\LICENSE
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Package\
     文件        6148  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Package\.DS_Store
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\
     文件        6148  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\.DS_Store
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\
     文件        6148  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.DS_Store
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\.idea.ArtificialTankDriver by QI\
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\.idea.ArtificialTankDriver by QI\.idea\
     文件         227  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\.idea.ArtificialTankDriver by QI\.idea\contentModel.xml
     文件         340  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\.idea.ArtificialTankDriver by QI\.idea\modules.xml
     文件       72341  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\.idea.ArtificialTankDriver by QI\.idea\workspace.xml
     文件         654  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\.idea\.idea.ArtificialTankDriver by QI\riderModule.iml
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\
     文件        6148  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\.DS_Store
     文件         191  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI.meta
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\
     文件        6148  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\.DS_Store
     文件         191  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Music.meta
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Music\
     文件     2092325  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Music\A Flight in Dark v0.1.2.mp3
     文件         477  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Music\A Flight in Dark v0.1.2.mp3.meta
     文件         191  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Prefabs.meta
     目录           0  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Prefabs\
     文件        3253  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Prefabs\Shell.prefab
     文件         209  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Prefabs\Shell.prefab.meta
     文件       13053  2017-11-09 09:45  Unity-Neural-Network-Tanks-AI-master\Project\ArtificialTankDriver by QI\Assets\ArtificialTankDriver by QI\Prefabs\Tank.prefab
............此处省略778个文件信息

评论

共有 条评论