示例#1
0
//------------------------------------Render()--------------------------------------
//
//----------------------------------------------------------------------------------
void CContController::Render(HDC surface)
{
	//render the stats
	string s = "Iteration:          " + itos(m_iIterations);
	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+m_NumSuperMines+m_NumRocks; ++i)
		{
			if ((m_vecObjects[i])->isDead()) continue; //skip if dead
			if ( (m_vecObjects[i])->getType() == CCollisionObject::Mine)
			{
				SelectObject(surface, m_GreenPen);
			}
			else if ( (m_vecObjects[i])->getType() == CCollisionObject::Rock)
			{
				SelectObject(surface, m_BluePen );
			}
			else if ( (m_vecObjects[i])->getType() == CCollisionObject::SuperMine)
			{
				SelectObject(surface, m_RedPen);
			}
			//grab the vertices for the mine shape
			vector<SPoint> mineVB = m_MineVB;

			WorldTransform<double>(mineVB, (m_vecObjects[i])->getPosition());

			//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 some sweepers 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);
			}
			if (m_vecSweepers[i]->isDead()) continue; //skip if dead
			//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);
  }

}
//------------------------------------Render()--------------------------------------
//
//----------------------------------------------------------------------------------
void CController::Render(HDC &surface)
{
	//do not render if running at accelerated speed
	if (!m_bFastRender)
	{   
		HBRUSH leftBrush;
		HBRUSH rightBrush;

		if (m_iTrials >= m_iReverseTrial) {
			leftBrush = highBrush;
			rightBrush = lowBrush;
		} else {
			leftBrush = lowBrush;
			rightBrush = highBrush;
		}
		// Render rewards here
		// Left side
		RECT rect;
		rect.bottom = 170;
		rect.left = 80;
		rect.right = 120;
		rect.top = 100;
		FillRect(surface, &rect, leftBrush); 

		// Right side
		rect.bottom = 170;
		rect.left = 260;
		rect.right = 300;
		rect.top = 100;
		FillRect(surface, &rect, rightBrush);
		//m_vecBestSweepers[m_iViewThisSweeper].RenderReward(surface);
		string s = "Generation: " + itos(m_iGenerations) + ", Trial: " + itos(m_iTrials + 1) + "/" + itos(CParams::iNumTrials);
		if (m_iTrials >= m_iReverseTrial) 
		{
			s += ", reversed: yes";
		} 
		else 
		{
			s += ", reversed: no";
		}
		TextOut(surface, 25, 0, s.c_str(), s.size());

		//select in the blue pen
		m_OldPen = (HPEN)SelectObject(surface, m_BluePen);

		if (m_bRenderBest)
		{  		
			//render the best sweepers memory cells
			m_vecBestSweepers[m_iViewThisSweeper].Render(surface);

			//render the best sweepers from the last generation
			RenderSweepers(surface, m_vecBestSweepers);

			//render the best sweepers sensors
			RenderSensors(surface, m_vecBestSweepers);
		}


		else
		{
			//render the sweepers
			RenderSweepers(surface, m_vecSweepers);
		}



		SelectObject(surface, m_OldPen);



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

		

	}//end if

	else
	{    
		PlotStats(surface);

		RECT sr;
		sr.top    = m_cyClient-50;
		sr.bottom = m_cyClient;
		sr.left   = 0;
		sr.right  = m_cxClient;

		//render the species chart
		m_pPop->RenderSpeciesInfo(surface, sr);

	}

}
示例#3
0
文件: CController.cpp 项目: Supy/ml
//------------------------------------Render()--------------------------------------
//
//----------------------------------------------------------------------------------
void CController::Render(HDC surface)
{
	if ( hasTrained)
	{

		//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_vecObjects.size(); ++i)
			{
				if ( m_vecObjects[i].getType() == CCollisionObject::Mine)
				{
					SelectObject(surface, m_BluePen);
				}
				else if ( m_vecObjects[i].getType() == CCollisionObject::SuperMine)
				{
					SelectObject(surface, m_RedPen);
				}
				//grab the vertices for the mine shape
				vector<SPoint> mineVB = m_MineVB;

				WorldTransform(mineVB, m_vecObjects[i].getPosition());

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

				LineTo(surface, (int)mineVB[1].x, (int)mineVB[1].y);
				LineTo(surface, (int)mineVB[2].x, (int)mineVB[2].y);			
				LineTo(surface, (int)mineVB[3].x, (int)mineVB[3].y);					
				LineTo(surface, (int)mineVB[0].x, (int)mineVB[0].y);

				LineTo(surface, (int)mineVB[2].x, (int)mineVB[2].y);
				MoveToEx(surface, (int)mineVB[1].x, (int)mineVB[1].y, NULL);
				LineTo(surface, (int)mineVB[3].x, (int)mineVB[3].y);
			
			}
       		
			//we want some sweepers displayed in red
			SelectObject(surface, m_RedPen);

			//render the sweepers
			for (int i=0; i<m_vecSweepers.size(); i++)
			{
				if(!m_vecSweepers[i].IsActive())
					continue;

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

		}
		else
		{
			PlotStats(surface);
		}

	
		//render the stats
		string s = "Iteration:          " + itos(m_iIterations);
		TextOut(surface, 5, 0, s.c_str(), s.size());
	
		string s2 = "Progress:   " + itos(m_iTicks) + "/" + itos(CParams::iNumTicks) + " ticks";
		TextOut(surface, 5, 20, s2.c_str(), s2.size());
	}
	else
	{

		string s = "Training...";
		TextOut(surface, 5, 0, s.c_str(), s.size());

		s = "This generally takes under 10 seconds.";
		TextOut(surface, 5, 20, s.c_str(), s.size());

		hasRendered = true;
	}
}