资源简介
越野小汽车机器人,使用遗传算法创造出最佳的汽车机器人。
每一辆汽车获得一个代表他们的“染色体”,每次根据上一代基因生成30个小车,其中越野最远的小车为此代最优基因,下一代小车使用他的基因随机变异生成。
当小车不移动时会自动死亡,当全部小车死亡时会重新生成下一代小车。
当点击左上方下一代按钮时,选取当前跑得最远的小车作为最优基因生成下一代小车。
按下 再生世界 按钮清除当前跑道数据和小车基因数据,生成新的跑道和初代小车。
再生设置可以设置跑道的长度,弯曲度,弯曲度为最小时跑道没有上下坡可以进行小车赛跑。
参考网站
http://boxcar2d.com
代码片段和文件信息
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CarBuilder : MonoBehaviour {
public delegate void CarUpdate(Gameobject pCar);
public static CarUpdate OnCarUpdated;
void Start() {
// register to take
OnCarUpdated += buildACar;
}
///
/// Builds a cars body using its chromosome
///
/// Cars game object
public void buildACar(Gameobject pCar) {
var carTracker = pCar.GetComponent();
List genes = carTracker.carChromosome.genes;
int vertices = 6; // num of body vertices
Gameobject[] children = new Gameobject[vertices];
float[] angles = new float[vertices];
var lastWeight = genes[(vertices - 1) * 2].value;
float lastAngle = 0;
float angle = 0;
for (var i = 0; i < vertices; i++) {
var weight = genes[i * 2].value;
if (i == vertices - 1) {
angle = 360;
} else {
angle += genes[i * 2 + 1].value;
}
angles[i] = angle;
var mesh = createMesh(
lastAngle angle
lastWeight weight);
var child = pCar.transform.GetChild(i).gameobject;
var meshFilter = child.GetComponent();
meshFilter.mesh = mesh;
var renderer = child.GetComponent();
renderer.material.color =
new Color(Random.value Random.value Random.value);
PolygonCollider2D collider = child.GetComponent();
collider.points = createPhysMesh(mesh);
children[i] = child;
lastWeight = weight;
lastAngle = angle;
}
connect(children[children.Length - 1] children[0]);
for (int j = 0; j < children.Length - 1; j++) {
connect(children[j] children[j + 1]);
}
int offset = vertices * 2;
for (var k = 0; k < 2; k++) {
int i = offset + k * 2;
int vI = (int) genes[i].value;
connectWheel(
pCar.transform.GetChild(vertices + k).gameobject
children[vI]
angles[vI] // angle of car part
genes[vI * 2].value // radius of car part
genes[i + 1].value); // radius of car wheel
}
}
///
/// Connect car parts
///
///
///
void connect(Gameobject pFirst Gameobject pSecond) {
FixedJoint2D joint = pFirst.GetComponent();
joint.connectedBody = pSecond.GetComponent();
joint.connectedAnchor = new Vector2(0 0);
}
///
/// Connects a wheel to a car part
///
///
///
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-01-28 20:05 unity_geneticcars-master\
文件 6148 2017-01-28 19:56 unity_geneticcars-master\.DS_Store
目录 0 2017-01-28 20:05 __MACOSX\
目录 0 2017-01-28 20:05 __MACOSX\unity_geneticcars-master\
文件 120 2017-01-28 19:56 __MACOSX\unity_geneticcars-master\._.DS_Store
文件 477 2016-03-30 06:08 unity_geneticcars-master\.gitignore
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\._.gitignore
文件 8487 2017-01-28 19:56 unity_geneticcars-master\Assembly-CSharp-Editor.csproj
文件 5826 2017-01-28 19:56 unity_geneticcars-master\Assembly-CSharp.csproj
目录 0 2017-01-28 19:13 unity_geneticcars-master\Assets\
文件 73576 2017-01-28 19:13 unity_geneticcars-master\Assets\car.unity
文件 175 2017-01-28 17:33 unity_geneticcars-master\Assets\car.unity.me
目录 0 2017-01-28 20:05 __MACOSX\unity_geneticcars-master\Assets\
文件 210 2017-01-28 17:33 __MACOSX\unity_geneticcars-master\Assets\._car.unity.me
目录 0 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\
目录 0 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\graphics\
文件 78 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\graphics\Ground.png
目录 0 2017-01-28 20:05 __MACOSX\unity_geneticcars-master\Assets\cars\
目录 0 2017-01-28 20:05 __MACOSX\unity_geneticcars-master\Assets\cars\graphics\
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\Assets\cars\graphics\._Ground.png
文件 1282 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\graphics\Ground.png.me
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\Assets\cars\graphics\._Ground.png.me
文件 78 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\graphics\Polygon.png
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\Assets\cars\graphics\._Polygon.png
文件 1399 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\graphics\Polygon.png.me
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\Assets\cars\graphics\._Polygon.png.me
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\Assets\cars\._graphics
文件 192 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\graphics.me
文件 212 2016-03-30 06:08 __MACOSX\unity_geneticcars-master\Assets\cars\._graphics.me
目录 0 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\Meterials\
文件 4152 2016-03-30 06:08 unity_geneticcars-master\Assets\cars\Meterials\CarBodyMaterial.physicsMaterial2D
............此处省略1902个文件信息
相关资源
- unity4.0官方正式版
- Logistic回归总结非常好的机器学习总结
- 遗传算法的堆石料非线性本构模型参
- Convex Analysis and Optimization (Bertsekas
- 机器学习个人笔记完整版v5.2-A4打印版
- Behavior Designer 1.6.3(u2018.3.0).unitypa
- Unity纪念碑谷.rar
- A Pathfinding Project Pro v4.2.2.rar
- JUNIOR:粒子物理学中无监督机器学习
- Unity 声音播放插件,支持将字符串转
- Gaia 1.7.2
- Unity3d实现扭动挤压浏览效果
- 语料库.zip
- UnityShader卷轴效果
- 爱酱(绊爱Kizuna)模型
- 中国科学技术大学 研究生课程 机器学
- unity 3D 百度语音合成 并播放
- unity案例入门坦克大战源码
- 吴恩达机器学习编程题
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 机器学习实战高清pdf,中文版+英文版
- 车间布局遗传算法
- 李宏毅-机器学习(视频2017完整)
- 机器学习深度学习 PPT
- Graph And Chart 1.91.unitypackage
- Animated Steel Coaster 1.51.rar
- 麻省理工:深度学习介绍PPT-1
- Wikipedia机器学习迷你电子书之四《D
- Unity3D游戏开发.pdf 宣雨松著完整高清
- Learning From Data Yaser S. Abu-Mostafa
评论
共有 条评论