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

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

?? ccontroller.cpp

?? 智能掃雷工 AI 遺傳算法 人工神經網絡
?? 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();

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

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

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

	//initialize mines in random positions within the application window
	for (int 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 (int i=0; i<NumSweeperVerts; ++i)
	{
		m_SweeperVB.push_back(sweeper[i]);
	}

	for (int 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 (int 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 (int 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 (int 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, 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 (int 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一区二区三区免费野_久草精品视频
欧美一区二区不卡视频| 9久草视频在线视频精品| 亚洲卡通动漫在线| 国产精品天干天干在线综合| 欧美精品一区二区蜜臀亚洲| 日韩精品最新网址| 欧美videos中文字幕| 日韩精品在线看片z| 欧美xingq一区二区| 26uuu色噜噜精品一区| 日韩欧美中文字幕公布| 日韩欧美国产一区在线观看| 精品免费视频一区二区| 国产亚洲综合色| 中文在线一区二区| 亚洲免费资源在线播放| 一区二区三区国产| 亚洲va欧美va天堂v国产综合| 亚洲视频一区在线| 五月激情综合婷婷| 美美哒免费高清在线观看视频一区二区| 五月天激情小说综合| 久久99在线观看| 国产黄色成人av| 色综合天天狠狠| 欧美精品高清视频| 久久久久久久久久看片| 中文字幕亚洲电影| 婷婷开心久久网| 国产精品一区二区不卡| av激情亚洲男人天堂| 欧美日韩日本视频| 国产欧美精品国产国产专区 | 一区二区三区在线看| 香蕉成人啪国产精品视频综合网| 另类综合日韩欧美亚洲| 成人美女视频在线观看| 欧美视频完全免费看| 337p粉嫩大胆噜噜噜噜噜91av | 欧美在线free| 日韩三级视频在线看| 国产精品免费aⅴ片在线观看| 亚洲男人的天堂在线观看| 日韩精品一级中文字幕精品视频免费观看 | 精品对白一区国产伦| 亚洲欧美精品午睡沙发| 捆绑变态av一区二区三区| av中文一区二区三区| 日韩一区二区影院| 一区二区三区在线观看视频| 国产精品99久| 欧美日产在线观看| 亚洲日本在线视频观看| 韩国中文字幕2020精品| 欧美男女性生活在线直播观看| 国产欧美日韩三区| 蜜桃精品视频在线观看| 在线视频一区二区三| 国产区在线观看成人精品| 日本一区中文字幕| 欧美日韩在线免费视频| 国产精品成人在线观看| 国产美女精品一区二区三区| 欧美日本在线看| 国产视频一区二区在线| 亚洲一区二区三区中文字幕| 麻豆精品视频在线观看| 欧美午夜精品电影| 国产精品成人一区二区三区夜夜夜| 欧美激情自拍偷拍| 国产精品毛片久久久久久久| 福利一区二区在线观看| 亚洲福利一二三区| 国产欧美一区二区精品性色超碰| av在线不卡电影| 男人的天堂亚洲一区| 最新高清无码专区| 欧美一区三区四区| 99久精品国产| 国产综合色在线视频区| 亚洲香肠在线观看| 欧美国产在线观看| 欧美一二三四区在线| 99视频国产精品| 老司机精品视频线观看86| 亚洲精品视频一区| 国产调教视频一区| 欧美一级日韩免费不卡| 91丨九色丨蝌蚪丨老版| 国产毛片精品一区| 图片区小说区国产精品视频| 国产精品欧美极品| 久久久久久免费网| 5月丁香婷婷综合| 91福利国产精品| 成人小视频免费观看| 免费高清在线一区| 图片区小说区国产精品视频| 日韩理论片中文av| 国产目拍亚洲精品99久久精品| 6080国产精品一区二区| 欧美性一级生活| 色综合天天做天天爱| 成人午夜精品一区二区三区| 久久99国产精品久久| 日本vs亚洲vs韩国一区三区二区| 亚洲精品国产a| 自拍视频在线观看一区二区| 国产婷婷色一区二区三区在线| 精品久久免费看| 日韩免费在线观看| 日韩一区二区三区电影| 91精品在线观看入口| 欧美日产在线观看| 欧美乱妇15p| 欧美理论在线播放| 在线91免费看| 欧美一区二区视频在线观看2020| 欧美日韩在线观看一区二区| 欧美性色黄大片手机版| 欧美系列日韩一区| 欧美日韩成人一区二区| 欧美群妇大交群的观看方式| 欧美日韩五月天| 在线不卡免费欧美| 欧美一区二区视频在线观看2020| 日韩精品一区二区在线| 国产网站一区二区三区| 国产精品初高中害羞小美女文| 亚洲欧美日本韩国| 午夜伦理一区二区| 国产一区二区三区高清播放| 国产aⅴ精品一区二区三区色成熟| 国产福利精品导航| 色综合色综合色综合色综合色综合| 91黄色小视频| 日韩亚洲欧美中文三级| 国产欧美一区视频| 一区二区三区四区在线免费观看| 亚洲国产wwwccc36天堂| 精品一区二区三区在线视频| 成人性生交大片免费看视频在线 | 亚洲一区在线看| 日韩激情视频网站| 国产精一品亚洲二区在线视频| 国产精品白丝jk黑袜喷水| 不卡一区二区中文字幕| 不卡的av电影| 6080yy午夜一二三区久久| 欧美一激情一区二区三区| 2024国产精品| 亚洲图片激情小说| 午夜精品福利一区二区蜜股av| 日韩精品电影一区亚洲| 久久精工是国产品牌吗| 97精品国产露脸对白| 欧美日韩国产精品自在自线| 7777精品伊人久久久大香线蕉最新版| 这里只有精品免费| 中文字幕综合网| 日韩在线a电影| 国产69精品久久久久777| 在线一区二区三区四区五区| 欧美videos大乳护士334| 国产精品久久久久一区| 五月天久久比比资源色| 亚洲bt欧美bt精品| 99久久综合狠狠综合久久| 欧美日韩精品是欧美日韩精品| 日韩欧美激情四射| 久久一区二区三区国产精品| 亚洲乱码国产乱码精品精小说 | 亚洲精品成人天堂一二三| 婷婷成人激情在线网| 国产一区二区三区av电影| 91麻豆自制传媒国产之光| 日韩免费电影网站| 亚洲老妇xxxxxx| 国产一区二区免费看| 日韩午夜精品视频| 日韩一区中文字幕| 国产综合一区二区| 日韩精品一区国产麻豆| 一区二区三区在线播| 国产一区二区视频在线| 欧美一级高清片在线观看| 日韩一区欧美小说| 国产乱人伦偷精品视频免下载| 欧美亚洲另类激情小说| 亚洲欧美中日韩| 国产高清精品在线| 日韩你懂的在线播放| 国产欧美日韩在线观看| 国产一区二区美女诱惑| 欧美精品粉嫩高潮一区二区| 亚洲精品老司机| 国产又黄又大久久| 日韩亚洲欧美高清| 亚洲成人一区二区在线观看| 99精品欧美一区|