前两节提到了神经网络部分和遗传算法部分,那么代码就到此结束了吗?当然没有,无论什么算法,总要针对一个特定的对象进行使用不是?因此,本节介绍另一个部分,CMinesweeper,即扫雷机代码。
class CMinesweeper
{
private:
//the minesweeper's neural net
CNeuralNet m_ItsBrain;//扫雷机的大脑,在这里就是一个神经网络
//its position in the world
SVector2D m_vPosition;//扫雷机的位置,用一个二维坐标表示
//direction sweeper is facing
SVector2D m_vLookAt;//扫雷机的朝向,用一个二维向量表示,注意这个向量是物理中的向量
//its rotation (surprise surprise)
double m_dRotation;//扫雷机的旋转速度??
double m_dSpeed;//扫雷机的速度
//to store output from the ANN
double m_lTrack, m_rTrack;//扫雷机左、右轮速度,这里即是神经网络的输出
//the sweeper's fitness score
double m_dFitness;//扫雷机的适应度函数,算法好坏的关键在于适应度函数的设计!
//the scale of the sweeper when drawn
double m_dScale;// 变比
//index position of closest mine
int m_iClosestMine;//距离扫雷机最近的地雷
public:
CMinesweeper();//构造函数
//updates the