亚洲欧美第一页_禁久久精品乱码_粉嫩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 NumMineVerts = 4;
const SPoint mine[NumMineVerts] = {SPoint(-1, -1),
                                   SPoint(-1, 1),
                                   SPoint(1, 1),
                                   SPoint(1, -1)};



//---------------------------------------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_NumMines(CParams::iNumMines),
										                     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);

	//initialize mines in random positions within the application window
	for (i=0; i<m_NumMines; ++i)
	{
		m_vecMines.push_back(SVector2D(RandFloat() * cxClient,
                                   RandFloat() * cyClient));
	}

	//create a pen 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, 150, 0));

	m_OldPen	= NULL;

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

	for (i=0; i<NumMineVerts; ++i)
	{
		m_MineVB.push_back(mine[i]);
	}

}


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

	DeleteObject(m_BluePen);
	DeleteObject(m_RedPen);
	DeleteObject(m_GreenPen);
	DeleteObject(m_OldPen);
}


//---------------------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)
{
	//create the world transformation matrix
	C2DMatrix matTransform;
	
	//scale
	matTransform.Scale(CParams::dMineScale, CParams::dMineScale);
	
	//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 CParams::iNumTicks 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_vecMines))
			{
				//error in processing the neural net
				MessageBox(m_hwndMain, "Wrong amount of NN inputs!", "Error", MB_OK);

				return false;
			}
				
			//see if it's found a mine
      int GrabHit = m_vecSweepers[i].CheckForMine(m_vecMines,
                                                  CParams::dMineScale);

			if (GrabHit >= 0)
      {
        //we have discovered a mine so increase fitness
        m_vecSweepers[i].IncrementFitness();

        //mine found so replace the mine with another at a random 
			  //position
			  m_vecMines[GrabHit] = SVector2D(RandFloat() * cxClient,
                                        RandFloat() * cyClient);
      }

			//update the chromos fitness score
			m_vecThePopulation[i].dFitness = m_vecSweepers[i].Fitness();

		}
	}

	//Another generation has been completed.
	//Time to run the GA and update the sweepers with their new NNs
	else
	{
		//update the stats to be used in our stat window
		m_vecAvFitness.push_back(m_pGA->AverageFitness());
		m_vecBestFitness.push_back(m_pGA->BestFitness());

		//increment the generation counter
		++m_iGenerations;

		//reset cycles
		m_iTicks = 0;

		//run the GA 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)
	{
		//keep a record of the old pen
     m_OldPen = (HPEN)SelectObject(surface, m_GreenPen);

    //render the mines
		for (int i=0; i<m_NumMines; ++i)
		{
			//grab the vertices for the mine shape
			vector<SPoint> mineVB = m_MineVB;

			WorldTransform(mineVB, m_vecMines[i]);

			//draw the mines
			MoveToEx(surface, (int)mineVB[0].x, (int)mineVB[0].y, NULL);

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

			LineTo(surface, (int)mineVB[0].x, (int)mineVB[0].y);
			
		}
    
    		
    //we want the fittest displayed in red
    SelectObject(surface, m_RedPen);

		//render the sweepers
		for (i=0; i<m_NumSweepers; i++)
		{
			if (i == CParams::iNumElite)
      {
        SelectObject(surface, m_OldPen);
      }
      
      //grab the sweeper vertices
			vector<SPoint> sweeperVB = m_SweeperVB;

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

			//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);
			}

		}

    //put the old pen back
    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->BestFitness());
	  TextOut(surface, 5, 20, s.c_str(), s.size());

     s = "Average Fitness: " + ftos(m_pGA->AverageFitness());
	  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->BestFitness()+1)*2);

    //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, (int)x, (int)(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, (int)x, (int)(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一区二区三区免费野_久草精品视频
欧美一区二区在线播放| 91成人免费在线| 国产精品国产三级国产aⅴ原创| 中文字幕亚洲区| 欧美一区二区三区在线电影| 国产在线国偷精品免费看| 中文字幕一区免费在线观看| 欧美理论电影在线| 欧美影院精品一区| 久久久美女毛片| 精品久久国产字幕高潮| 久久99精品久久久久| 亚洲国产综合人成综合网站| 精品国产人成亚洲区| 99久精品国产| 国产成人综合视频| 久久精品国产精品亚洲红杏| 91猫先生在线| 国产精品99久久久久久似苏梦涵 | 久久蜜桃av一区二区天堂| 风间由美性色一区二区三区| 一区二区高清免费观看影视大全| 精品粉嫩aⅴ一区二区三区四区| www.色精品| aaa亚洲精品一二三区| 91在线看国产| 国产精品久久二区二区| 欧美色视频在线观看| 成人福利视频网站| 精品国产污网站| 欧美亚洲高清一区二区三区不卡| 亚洲一二三四久久| 一区二区三区在线免费| 综合久久久久久久| 欧美色爱综合网| 国产午夜精品福利| 亚洲国产精品一区二区尤物区| 免费av成人在线| 色老综合老女人久久久| 国产日韩欧美精品在线| 五月综合激情婷婷六月色窝| 丁香天五香天堂综合| 日韩欧美一级在线播放| 性做久久久久久免费观看| 国产精品12区| 2022国产精品视频| 久久丁香综合五月国产三级网站| 一本大道久久a久久精二百| 国产精品日韩精品欧美在线| 国产一区二区三区黄视频 | 99精品一区二区三区| 精品国精品国产尤物美女| 五月婷婷综合在线| 制服丝袜成人动漫| 天天操天天干天天综合网| 欧美日韩成人综合在线一区二区| 亚洲乱码国产乱码精品精98午夜| 波多野结衣精品在线| 国产精品电影一区二区三区| 99国产精品国产精品毛片| 一区二区三区四区不卡在线 | 日韩小视频在线观看专区| 日本va欧美va精品| 日韩久久久精品| 国产一区二区调教| 国产精品青草久久| 中文字幕中文乱码欧美一区二区| 五月综合激情婷婷六月色窝| 91在线小视频| 久久精品无码一区二区三区| 三级不卡在线观看| 一本大道av一区二区在线播放 | 日本va欧美va精品发布| 国产剧情一区二区三区| 欧美色精品在线视频| 激情综合亚洲精品| 日欧美一区二区| 亚洲欧美偷拍三级| 国产日韩在线不卡| 日韩三级视频在线看| 欧美三级视频在线观看| av电影天堂一区二区在线| 狠狠色狠狠色合久久伊人| 日韩精品色哟哟| 国产日韩欧美综合一区| 国产一区久久久| 国产精品久99| 欧美色视频在线观看| 日韩vs国产vs欧美| 久久综合九色综合欧美亚洲| 91在线观看视频| 日韩一区精品字幕| 久久亚洲一区二区三区四区| 东方aⅴ免费观看久久av| 亚洲美女区一区| 91精品国产色综合久久ai换脸| 麻豆91小视频| 一区二区三区四区国产精品| 精品国产乱码久久久久久牛牛| 国产一区二区中文字幕| 亚洲午夜一二三区视频| 精品成人一区二区| 欧美艳星brazzers| 国产成人无遮挡在线视频| 首页国产丝袜综合| 夜夜亚洲天天久久| 亚洲国产成人自拍| 久久影音资源网| 337p亚洲精品色噜噜| 在线免费观看一区| 99久久99久久免费精品蜜臀| 精彩视频一区二区三区| 久久国产精品区| 亚洲国产另类精品专区| 亚洲欧美另类久久久精品| 国产欧美一区二区三区沐欲| 中文字幕一区二区三区在线观看 | 日韩精品一区二区三区视频播放 | 亚洲女爱视频在线| 亚洲成av人影院在线观看网| 青青草伊人久久| 成人白浆超碰人人人人| 欧美日韩国产另类不卡| 日韩欧美国产综合在线一区二区三区 | 婷婷综合五月天| 丰满放荡岳乱妇91ww| 在线观看成人小视频| 日韩免费在线观看| 亚洲欧美日韩系列| 美女视频黄 久久| yourporn久久国产精品| 91精品欧美一区二区三区综合在 | 日本一不卡视频| eeuss鲁片一区二区三区在线看| 日韩一区二区三区三四区视频在线观看 | 色婷婷综合激情| 国产精品国产三级国产aⅴ入口| 日本视频免费一区| 欧美日韩国产综合一区二区| 亚洲国产成人在线| 国产成人8x视频一区二区| 日韩欧美国产系列| 久久精品国产亚洲5555| 欧美日韩卡一卡二| 亚洲国产成人va在线观看天堂| 99久久精品一区二区| 国产精品美女久久久久高潮| 成人免费看黄yyy456| 中文字幕欧美三区| 国产在线视频一区二区| 国产日韩影视精品| 成人一区在线看| 丝瓜av网站精品一区二区| 色呦呦网站一区| 蜜臀va亚洲va欧美va天堂| 国产电影精品久久禁18| 一区二区三区在线视频免费观看| 欧美中文字幕一二三区视频| 精品写真视频在线观看| 国产精品每日更新| 日韩你懂的电影在线观看| 99精品国产热久久91蜜凸| 日韩高清不卡一区二区| 中文字幕视频一区二区三区久| 欧美久久久一区| 在线一区二区三区四区五区| 国产裸体歌舞团一区二区| 婷婷开心激情综合| 日韩美女视频一区二区| 国产日韩欧美在线一区| 欧美一区二区久久| 91精品国产91久久久久久一区二区| 国产成人av影院| 国产成人av网站| 国产成人精品影视| 国产毛片精品一区| 亚洲欧美日韩国产综合在线| www.亚洲在线| 亚洲成av人片在线观看无码| 色噜噜偷拍精品综合在线| 成人av综合在线| 99久久精品免费| www..com久久爱| 91网站最新网址| 99re热视频精品| 欧美国产日韩在线观看| 国产精品毛片久久久久久久| 国产精品国产自产拍高清av| 在线播放91灌醉迷j高跟美女 | 日韩在线卡一卡二| 99re热这里只有精品视频| 久久免费美女视频| 午夜精品123| 欧美性色欧美a在线播放| 久久综合中文字幕| 美女一区二区视频| 成人免费黄色在线| 欧美国产日韩一二三区| 粉嫩av一区二区三区在线播放 | 国产suv精品一区二区三区|