亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ccontroller.cpp

?? 《游戲編程中的人工智能技術》書中源代碼和可執行文件
?? CPP
字號:
#include "CController.h"


//these hold the geometry of the sweepers and the mines
const int	 NumSweeperVerts = 16;
const SPoint sweeper[NumSweeperVerts] = {SPoint(-1, -1),
                                         SPoint(-1, 1),
                                         SPoint(-0.5, 1),
                                         SPoint(-0.5, -1),

                                         SPoint(0.5, -1),
                                         SPoint(1, -1),
                                         SPoint(1, 1),
                                         SPoint(0.5, 1),
                                         
                                         SPoint(-0.5, -0.5),
                                         SPoint(0.5, -0.5),

                                         SPoint(-0.5, 0.5),
                                         SPoint(-0.25, 0.5),
                                         SPoint(-0.25, 1.75),
                                         SPoint(0.25, 1.75),
                                         SPoint(0.25, 0.5),
                                         SPoint(0.5, 0.5)};


const int NumObjectVerts = 42;
const SPoint objects[NumObjectVerts] = {SPoint(80, 60),
                                        SPoint(200,60),
                                        SPoint(200,60),
                                        SPoint(200,100),
                                        SPoint(200,100),
                                        SPoint(160,100),
                                        SPoint(160,100),
                                        SPoint(160,200),
                                        SPoint(160,200),
                                        SPoint(80,200),
                                        SPoint(80,200),
                                        SPoint(80,60),

                                        SPoint(250,100),
                                        SPoint(300,40),
                                        SPoint(300,40),
                                        SPoint(350,100),
                                        SPoint(350,100),
                                        SPoint(250, 100),

                                        SPoint(220,180),
                                        SPoint(320,180),
                                        SPoint(320,180),
                                        SPoint(320,300),
                                        SPoint(320,300),
                                        SPoint(220,300),
                                        SPoint(220,300),
                                        SPoint(220,180),

                                        SPoint(12,15),
                                        SPoint(380, 15),
                                        SPoint(380,15),
                                        SPoint(380,360),
                                        SPoint(380,360),                                
                                        SPoint(12,360),
                                        SPoint(12,360),
                                        SPoint(12,340),
                                        SPoint(12,340),
                                        SPoint(100,290),
                                        SPoint(100,290),
                                        SPoint(12,240),
                                        SPoint(12,240),
                                        SPoint(12,15)};


//---------------------------------------constructor---------------------
//
//	initilaize the sweepers, their brains and the GA factory
//
//-----------------------------------------------------------------------
CController::CController(HWND hwndMain): m_NumSweepers(CParams::iNumSweepers), 
										                     m_pGA(NULL),
										                     m_bFastRender(false),
										                     m_iTicks(0),
										                     m_hwndMain(hwndMain),
										                     m_iGenerations(0),
                                         cxClient(CParams::WindowWidth),
                                         cyClient(CParams::WindowHeight)
                                         
{
	//let's create the mine sweepers
	for (int i=0; i<m_NumSweepers; ++i)
	{
		m_vecSweepers.push_back(CMinesweeper());
	}

	//get the total number of weights used in the sweepers
	//NN so we can initialise the GA
	m_NumWeightsInNN = m_vecSweepers[0].GetNumberOfWeights();

  //calculate the neuron placement in the weight vector
  vector<int> SplitPoints = m_vecSweepers[0].CalculateSplitPoints();

	//initialize the Genetic Algorithm class
	m_pGA = new CGenAlg(m_NumSweepers,
                      CParams::dMutationRate,
	                    CParams::dCrossoverRate,
	                    m_NumWeightsInNN,
                      SplitPoints);

	//Get the weights from the GA and insert into the sweepers brains
	m_vecThePopulation = m_pGA->GetChromos();

	for (i=0; i<m_NumSweepers; i++)
  {
		m_vecSweepers[i].PutWeights(m_vecThePopulation[i].vecWeights);
  }


	//create pens for the graph drawing
	m_BluePen        = CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
	m_RedPen         = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
	m_GreenPen       = CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
  m_GreyPenDotted  = CreatePen(PS_DOT, 1, RGB(200, 200, 200));
  m_RedPenDotted   = CreatePen(PS_DOT, 1, RGB(250, 200, 200));

	m_OldPen	= NULL;

  //and the brushes
  m_BlueBrush = CreateSolidBrush(RGB(0,0,244));
  m_RedBrush = CreateSolidBrush(RGB(150,0,0));

	//fill the vertex buffers
	for (i=0; i<NumSweeperVerts; ++i)
	{
		m_SweeperVB.push_back(sweeper[i]);
	}

  for (i=0; i<NumObjectVerts; ++i)
  {
    m_ObjectsVB.push_back(objects[i]);
  }
}

//--------------------------------------destructor-------------------------------------
//
//--------------------------------------------------------------------------------------
CController::~CController()
{
	if(m_pGA)
  {
    delete		m_pGA;
  }

	DeleteObject(m_BluePen);
	DeleteObject(m_RedPen);
	DeleteObject(m_GreenPen);
	DeleteObject(m_OldPen);
  DeleteObject(m_GreyPenDotted);
  DeleteObject(m_RedPenDotted);
  DeleteObject(m_BlueBrush);
  DeleteObject(m_RedBrush);
}


//---------------------WorldTransform--------------------------------
//
//	sets up the translation matrices for the mines and applies the
//	world transform to each vertex in the vertex buffer passed to this
//	method.
//-------------------------------------------------------------------
void CController::WorldTransform(vector<SPoint> &VBuffer,
                                 SVector2D      vPos,
                                 double         rotation,
                                 double         scale)
{
	//create the world transformation matrix
	C2DMatrix matTransform;
	
	//scale
	matTransform.Scale(scale, scale);

   	//rotate
	matTransform.Rotate(rotation);
	
	//translate
	matTransform.Translate(vPos.x, vPos.y);


	//transform the ships vertices
	matTransform.TransformSPoints(VBuffer);
}


//-------------------------------------Update---------------------------------------
//
//	This is the main workhorse. The entire simulation is controlled from here.
//
//	The comments should explain what is going on adequately.
//--------------------------------------------------------------------------------------
bool CController::Update()
{
  //run the sweepers through NUM_TICKS amount of cycles. During this loop each
	//sweepers NN is constantly updated with the appropriate information from its 
	//surroundings. The output from the NN is obtained and the sweeper is moved. If
	//it encounters a mine its fitness is updated appropriately,
	if (m_iTicks++ < CParams::iNumTicks)
	{
		for (int i=0; i<m_NumSweepers; ++i)
		{
			//update the NN and position
			if (!m_vecSweepers[i].Update(m_ObjectsVB))
			{
				//error in processing the neural net
				MessageBox(m_hwndMain, "Wrong amount of NN inputs!", "Error", MB_OK);

				return false;
			}
		}
	}

	//**We have completed another generation.

	//Time to run the GA and update the sweepers with their new NNs
	else
	{
   for (int swp=0; swp<m_vecSweepers.size(); ++swp)
    {
        //add up all the penalties and calculate a fitness score
        m_vecSweepers[swp].EndOfRunCalculations();

        //update the fitness score stored in the GA with this score
			  m_vecThePopulation[swp].dFitness = m_vecSweepers[swp].Fitness();
    }

		//update the stats to be used in our stat window
		m_vecAvFitness.push_back(fabs(m_pGA->AverageRawFitness()));
		m_vecBestFitness.push_back(fabs(m_pGA->BestRawFitness()));

		//increment the generation counter
		++m_iGenerations;

		//reset cycles
		m_iTicks = 0;

		//insert the sweepers chromosones into the GA factory and
		//run the factory to create a new population
		m_vecThePopulation = m_pGA->Epoch(m_vecThePopulation);
			
		//insert the new (hopefully)improved brains back into the sweepers
    //and reset their positions etc
    for (int i=0; i<m_NumSweepers; ++i)
		{
			m_vecSweepers[i].PutWeights(m_vecThePopulation[i].vecWeights);
		
			m_vecSweepers[i].Reset();
		}
	}

	return true;
}
//------------------------------------Render()--------------------------------------
//
//----------------------------------------------------------------------------------
void CController::Render(HDC surface)
{
	//render the stats
	string s = "Generation: " + itos(m_iGenerations);
	TextOut(surface, 5,0, s.c_str(), s.size());


	//do not render if running at accelerated speed
	if (!m_bFastRender)
	{
		//display the penalties
    m_vecSweepers[0].RenderPenalties(surface);
    
    //render the objects
    for (int i=0; i<NumObjectVerts; i+=2)
    {
      MoveToEx(surface, m_ObjectsVB[i].x, m_ObjectsVB[i].y, NULL);

      LineTo(surface, m_ObjectsVB[i+1].x, m_ObjectsVB[i+1].y);
    }

   		
    //record the current pen
    m_OldPen = (HPEN)SelectObject(surface, m_GreyPenDotted);

		//render the sweepers
		for (i=0; i<m_vecSweepers.size(); i++)
		{
			if (i < CParams::iNumElite)
      {
        SelectObject(surface, m_OldPen);        
      }

      else
      {
        SelectObject(surface, m_GreyPenDotted);
      }

       //render red if collided and elite
      if ( m_vecSweepers[i].Collided() && (i < CParams::iNumElite) )
      {
        SelectObject(surface, m_RedPen);
      }
      
      //render dotted red if collided and not elite
      if ( m_vecSweepers[i].Collided() && (i > CParams::iNumElite) )
      {
        SelectObject(surface, m_RedPenDotted);
      }
      
      //grab the sweeper vertices
			vector<SPoint> sweeperVB = m_SweeperVB;

			//transform the vertex buffer
			m_vecSweepers[i].WorldTransform(sweeperVB, m_vecSweepers[i].Scale());

			//draw the sweeper left track
			MoveToEx(surface, (int)sweeperVB[0].x, (int)sweeperVB[0].y, NULL);

			for (int vert=1; vert<4; ++vert)
			{
				LineTo(surface, (int)sweeperVB[vert].x, (int)sweeperVB[vert].y);
			}

      LineTo(surface, (int)sweeperVB[0].x, (int)sweeperVB[0].y);

      //draw the sweeper right track
			MoveToEx(surface, (int)sweeperVB[4].x, (int)sweeperVB[4].y, NULL);

			for (vert=5; vert<8; ++vert)
			{
				LineTo(surface, (int)sweeperVB[vert].x, (int)sweeperVB[vert].y);
			}

      LineTo(surface, (int)sweeperVB[4].x, (int)sweeperVB[4].y);

      MoveToEx(surface, (int)sweeperVB[8].x, (int)sweeperVB[8].y, NULL);
      LineTo(surface, (int)sweeperVB[9].x, (int)sweeperVB[9].y);

      MoveToEx(surface, (int)sweeperVB[10].x, (int)sweeperVB[10].y, NULL);

      for (vert=11; vert<16; ++vert)
			{
				LineTo(surface, (int)sweeperVB[vert].x, (int)sweeperVB[vert].y);
			}

		}

    //render the sensors
    for (i=0; i<CParams::iNumElite; ++i)
    {
      //grab each sweepers sensor data
      vector<SPoint> tranSensors    = m_vecSweepers[i].Sensors();
      vector<double>   SensorReadings = m_vecSweepers[i].SensorReadings();

      for (int sr=0; sr<tranSensors.size(); ++sr)
      {
        if (SensorReadings[sr] > 0)
        {
          SelectObject(surface, m_RedPen);
        }

        else
        {
          SelectObject(surface, m_GreyPenDotted);
        }
        
        //make sure we clip the drawing of the sensors or we will get
        //unwanted artifacts appearing
        if (!((fabs(m_vecSweepers[i].Position().x - tranSensors[sr].x) >
              (CParams::dSensorRange+1))||
              (fabs(m_vecSweepers[i].Position().y - tranSensors[sr].y) >
              (CParams::dSensorRange+1))))
        {
        
          MoveToEx(surface,
                   (int)m_vecSweepers[i].Position().x,
                   (int)m_vecSweepers[i].Position().y,
                   NULL);

          LineTo(surface, (int)tranSensors[sr].x, (int)tranSensors[sr].y);
          
        }
      }
    }

    SelectObject(surface, m_OldPen);

	}//end if

  else
  {
    PlotStats(surface);
  }

}
//--------------------------PlotStats-------------------------------------
//
//  Given a surface to draw on this function displays stats and a crude
//  graph showing best and average fitness
//------------------------------------------------------------------------
void CController::PlotStats(HDC surface)
{
   
    string s = "Best Fitness:       " + ftos(m_pGA->BestRawFitness());
	  TextOut(surface, 5, 20, s.c_str(), s.size());

     s = "Average Fitness: " + ftos(m_pGA->AverageRawFitness());
	  TextOut(surface, 5, 40, s.c_str(), s.size());
    
    //render the graph
    float HSlice = (float)cxClient/(m_iGenerations+1);
    float VSlice = (float)cyClient/((m_pGA->BestRawFitness()+1)*1.5);

    //plot the graph for the best fitness
    float x = 0;
    
    m_OldPen = (HPEN)SelectObject(surface, m_RedPen);

    MoveToEx(surface, 0, cyClient, NULL);
    
    for (int i=0; i<m_vecBestFitness.size(); ++i)
    {
       LineTo(surface, x, (cyClient - VSlice*m_vecBestFitness[i]));

       x += HSlice;
    }

    //plot the graph for the average fitness
    x = 0;

    SelectObject(surface, m_BluePen);

    MoveToEx(surface, 0, cyClient, NULL);
    
    for (i=0; i<m_vecAvFitness.size(); ++i)
    {
       LineTo(surface, x, (cyClient - VSlice*m_vecAvFitness[i]));

       x += HSlice;
    }

    //replace the old pen
    SelectObject(surface, m_OldPen);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美在线观看视频在线| 欧美一级在线观看| 美女精品一区二区| 一区二区三区波多野结衣在线观看 | 精品盗摄一区二区三区| 色婷婷久久99综合精品jk白丝| 久久精品国产**网站演员| 一区二区三区影院| 国产精品麻豆欧美日韩ww| 欧美一级在线免费| 欧美午夜精品理论片a级按摩| 成人伦理片在线| 国模大尺度一区二区三区| 亚洲动漫第一页| 亚洲色图色小说| 欧美国产日韩在线观看| 欧美成人video| 91精品国产综合久久精品图片| 91精品福利在线| 一本到不卡免费一区二区| 国产成人精品亚洲日本在线桃色| 免费观看日韩电影| 日韩影视精彩在线| 亚洲成av人片在线观看无码| 亚洲精品视频一区| 中文字幕视频一区| 国产精品福利av| 欧美韩日一区二区三区| 久久久美女毛片| 精品国产凹凸成av人导航| 日韩一区二区免费电影| 91精品婷婷国产综合久久竹菊| 欧美主播一区二区三区| 欧美中文字幕久久| 欧美日韩一区二区三区四区| 欧美专区日韩专区| 欧美日韩成人高清| 69p69国产精品| 91精品国产91久久久久久最新毛片| 欧美三级日本三级少妇99| 欧美日韩一级片在线观看| 欧美日韩在线精品一区二区三区激情| 欧美在线影院一区二区| 欧美丝袜丝交足nylons| 欧美日韩大陆在线| 日韩精品最新网址| 久久色.com| 国产精品网站在线观看| 国产精品剧情在线亚洲| 亚洲欧美一区二区三区极速播放| 18欧美亚洲精品| 伊人性伊人情综合网| 亚洲中国最大av网站| 五月婷婷综合激情| 免费欧美日韩国产三级电影| 韩国成人精品a∨在线观看| 国产99久久久国产精品| 95精品视频在线| 欧美三级在线看| 日韩亚洲欧美综合| 国产精品少妇自拍| 亚洲精品国产精品乱码不99| 五月激情六月综合| 国产精品正在播放| 91丨九色丨蝌蚪富婆spa| 欧美三级欧美一级| 久久久美女毛片| 亚洲精品视频观看| 美女视频网站久久| 成人精品在线视频观看| 欧美亚洲动漫精品| 精品sm在线观看| 亚洲色图19p| 麻豆国产欧美日韩综合精品二区| 国产高清在线精品| 欧美色区777第一页| 久久久www免费人成精品| 亚洲免费观看高清完整版在线观看熊| 日韩在线播放一区二区| 成人综合激情网| 69久久99精品久久久久婷婷 | 欧美一区二区三区四区高清| 久久精品一区二区三区av| 一区二区三区.www| 国产久卡久卡久卡久卡视频精品| 一本久久a久久免费精品不卡| 欧美电视剧在线观看完整版| 18成人在线观看| 国模少妇一区二区三区| 欧美丝袜丝交足nylons| 国产精品网站导航| 毛片av一区二区| 91精彩视频在线观看| 精品国产第一区二区三区观看体验 | 日韩欧美黄色影院| 亚洲一区中文日韩| 夫妻av一区二区| 日韩欧美一区电影| 亚洲已满18点击进入久久| 高清不卡一二三区| 日韩视频免费观看高清完整版在线观看 | 中文字幕免费一区| 精品在线一区二区| 欧美日韩在线播放一区| 国产精品动漫网站| 国内国产精品久久| 制服.丝袜.亚洲.另类.中文| 亚洲日本丝袜连裤袜办公室| 国产精品1区2区3区| 日韩一区二区不卡| 午夜国产不卡在线观看视频| 一本色道久久综合亚洲91| 亚洲国产精品成人综合| 加勒比av一区二区| 日韩欧美中文一区| 午夜日韩在线观看| 欧美色倩网站大全免费| 一区二区三区精品在线| 91在线国产福利| 国产精品家庭影院| 粗大黑人巨茎大战欧美成人| 久久久精品影视| 国产一区二区三区日韩| 精品伦理精品一区| 久久99国产精品麻豆| 欧美一级淫片007| 美腿丝袜亚洲一区| 欧美一二三四在线| 日本欧美大码aⅴ在线播放| 欧美日韩在线不卡| 日欧美一区二区| 制服丝袜日韩国产| 麻豆成人久久精品二区三区小说| 欧美一级二级三级蜜桃| 免费人成在线不卡| 欧美成人精品1314www| 捆绑紧缚一区二区三区视频| 日韩一区二区三区视频在线| 久久精品99国产国产精| 精品久久久影院| 国产综合色视频| 国产亚洲欧美在线| 国产·精品毛片| 国产精品不卡在线观看| 91麻豆国产香蕉久久精品| 亚洲精品欧美激情| 欧美亚洲图片小说| 蜜臀精品久久久久久蜜臀 | av亚洲精华国产精华精华 | 亚洲欧美另类在线| 日本久久电影网| 午夜精品一区二区三区电影天堂| 欧美日韩精品免费观看视频| 日韩国产高清影视| 亚洲精品在线网站| 成人性色生活片免费看爆迷你毛片| 国产精品久久久久久久久久免费看 | 久久久久国产精品厨房| 国产成人精品免费在线| 亚洲色图欧美激情| 制服视频三区第一页精品| 国内精品免费**视频| 自拍偷拍亚洲综合| 欧美日韩精品一区二区天天拍小说 | 欧美群妇大交群的观看方式 | 99国内精品久久| 亚洲a一区二区| 欧美成人免费网站| 不卡av电影在线播放| 亚洲一区二区三区爽爽爽爽爽 | 欧美一区二区私人影院日本| 国产伦理精品不卡| 亚洲私人黄色宅男| 欧美高清视频不卡网| 国产精品99久久久久久久女警 | 五月天激情综合| 国产欧美一区二区精品性色| 色婷婷久久99综合精品jk白丝 | 久99久精品视频免费观看| 国产精品美女久久久久aⅴ国产馆| 欧美自拍偷拍一区| 国产乱人伦偷精品视频免下载| 亚洲欧美日韩国产综合| 精品国产91洋老外米糕| 色诱亚洲精品久久久久久| 久久精品国产色蜜蜜麻豆| 亚洲欧美一区二区三区国产精品 | 蜜桃视频在线观看一区二区| 国产精品电影一区二区三区| 日韩欧美三级在线| 色综合一区二区| 国产一区二区三区免费播放 | 成人中文字幕在线| 日韩av在线发布| 亚洲另类中文字| 久久久91精品国产一区二区精品| 欧美色网一区二区| fc2成人免费人成在线观看播放 | 国产精品国产三级国产a| 日韩一级精品视频在线观看|