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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? ccontroller.cpp

?? 《游戲編程中的人工智能技術(shù)》書(shū)中源代碼和可執(zhí)行文件
?? CPP
字號(hào):
#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);
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜臂av日日欢夜夜爽一区| 欧美乱妇20p| 国产成人8x视频一区二区| 久久国产精品区| 美女视频网站黄色亚洲| 日韩精彩视频在线观看| 亚洲电影视频在线| 亚洲午夜影视影院在线观看| 一区二区免费看| 一区二区在线免费观看| 亚洲激情五月婷婷| 亚洲国产中文字幕在线视频综合| 亚洲图片自拍偷拍| 天天色天天操综合| 老司机精品视频线观看86| 国产综合色在线视频区| 国产成人在线视频免费播放| 高清成人免费视频| 91丨porny丨最新| 欧美视频一区二区三区| 在线成人午夜影院| 精品久久久久久久久久久久久久久 | 国产精品初高中害羞小美女文| 中文字幕av资源一区| 中文字幕综合网| 亚洲一区国产视频| 蜜臀av性久久久久蜜臀aⅴ四虎 | 国产乱人伦精品一区二区在线观看 | 男人的天堂久久精品| 久久er精品视频| 国v精品久久久网| 色激情天天射综合网| 欧美色偷偷大香| 日韩欧美国产精品| 国产精品福利一区二区三区| 亚洲午夜一区二区| 国产一区二区三区不卡在线观看| 成人av动漫网站| 欧美日韩国产高清一区二区三区| 欧美草草影院在线视频| 中文在线一区二区| 一区av在线播放| 美日韩黄色大片| 99精品久久99久久久久| 欧美疯狂性受xxxxx喷水图片| 久久伊人蜜桃av一区二区| 亚洲人成小说网站色在线| 日韩成人dvd| 国产69精品久久777的优势| 欧美日本国产视频| 国产精品网站在线| 五月天丁香久久| 成人免费看黄yyy456| 欧美日韩精品电影| 国产精品私房写真福利视频| 首页国产欧美久久| www.欧美色图| 日韩欧美一区二区在线视频| 亚洲欧美区自拍先锋| 蜜桃av一区二区在线观看| 色先锋久久av资源部| www久久精品| 图片区日韩欧美亚洲| 91在线小视频| 精品国产免费一区二区三区四区| 亚洲精品国产a| 国产高清久久久久| 欧美一区日本一区韩国一区| 亚洲激情欧美激情| 丁香一区二区三区| 精品国产亚洲在线| 日韩黄色片在线观看| 色婷婷激情久久| 国产片一区二区| 国内精品久久久久影院薰衣草 | 91亚洲精华国产精华精华液| 欧美不卡123| 亚洲宅男天堂在线观看无病毒| 国产一区二区三区美女| 666欧美在线视频| 亚洲精品乱码久久久久久日本蜜臀| 国内精品伊人久久久久影院对白| 欧美精品乱码久久久久久| 亚洲免费在线视频一区 二区| 国产成人综合自拍| 精品国精品自拍自在线| 日韩福利视频网| 欧美区一区二区三区| 亚洲欧美国产三级| 国产成人综合视频| 欧美va亚洲va| 久久国产免费看| 日韩视频在线一区二区| 日韩av在线播放中文字幕| 欧美图区在线视频| 亚洲线精品一区二区三区| 在线一区二区三区四区五区 | 日韩国产在线一| 欧美日韩精品欧美日韩精品一| 一区二区三区在线播放| 一本久久综合亚洲鲁鲁五月天| 秋霞av亚洲一区二区三| 91在线无精精品入口| 亚洲免费视频中文字幕| 欧美私人免费视频| 久久激情五月激情| 成人av免费观看| 国产午夜精品一区二区三区嫩草| 美女脱光内衣内裤视频久久网站| 91精品国产麻豆| 日韩精品五月天| 欧美一区二区免费视频| 久久国产精品一区二区| 欧美xxxxxxxxx| 国内精品在线播放| 国产日产欧产精品推荐色| 不卡电影一区二区三区| 亚洲婷婷在线视频| 在线免费不卡电影| 亚洲高清视频的网址| 欧美一区二区三区视频在线| 激情综合网av| 国产精品美女视频| 91黄色小视频| 日韩av电影免费观看高清完整版| 日韩一区二区三区免费观看| 国产一区二区三区免费看| 中文字幕免费一区| 91成人在线免费观看| 日韩av一区二区三区四区| 久久人人97超碰com| 不卡在线视频中文字幕| 一区二区三区国产豹纹内裤在线| 精品婷婷伊人一区三区三| 美女性感视频久久| 中文字幕欧美日韩一区| 欧美四级电影网| 经典三级视频一区| 亚洲欧美日韩国产另类专区| 欧美精品aⅴ在线视频| 久草中文综合在线| 亚洲三级在线免费| 91精品黄色片免费大全| 成人免费视频网站在线观看| 亚洲一二三区在线观看| 精品国产乱码久久久久久老虎| 成年人午夜久久久| 日韩不卡在线观看日韩不卡视频| 久久综合九色综合97婷婷| 99久久99久久综合| 蜜桃在线一区二区三区| 亚洲天堂免费看| 日韩一级片网址| 不卡一卡二卡三乱码免费网站 | 99久久婷婷国产精品综合| 日韩av午夜在线观看| 国产精品国产自产拍高清av | 五月天激情综合网| 欧美极品aⅴ影院| 制服丝袜亚洲色图| 99久久99久久久精品齐齐| 另类人妖一区二区av| 亚洲综合一区二区三区| 久久精品亚洲精品国产欧美 | 国产女人水真多18毛片18精品视频| 欧洲中文字幕精品| 国产宾馆实践打屁股91| 日韩精品乱码免费| 亚洲精品免费视频| 国产欧美日本一区视频| 欧美日韩高清一区| av亚洲精华国产精华| 激情五月激情综合网| 亚洲国产精品久久人人爱| 中文字幕精品—区二区四季| 日韩手机在线导航| 欧美日韩在线三区| 91麻豆福利精品推荐| 国产精品99久久久久久久vr| 视频一区二区国产| 亚洲伦在线观看| 无码av免费一区二区三区试看 | 国产一区二区三区蝌蚪| 奇米在线7777在线精品 | 色8久久精品久久久久久蜜| 国产精品小仙女| 久久精品国产**网站演员| 亚洲成a人v欧美综合天堂下载 | 国产精品三级av在线播放| 日韩精品中午字幕| 欧美日韩成人在线一区| 欧美午夜免费电影| 在线免费观看不卡av| 一本色道综合亚洲| 91天堂素人约啪| 色综合夜色一区| proumb性欧美在线观看| 不卡的av电影| 懂色一区二区三区免费观看 | 91精品在线免费观看|