Ejemplo n.º 1
0
        public CController(IImageByte hwndMain, int iNumSweepers, int iNumMines, double _dMutationRate, double _dCrossoverRate, double dMaxPerturbation,
                           int NumElite, int NumCopiesElite, int NumTicksPerGeneration)
        {
            Random Rand = new Random();

            m_MineScale    = 1;
            m_SweeperScale = 3;

            m_pGA                   = null;
            m_bFastRender           = (false);
            m_TicksThisGeneration   = 0;
            m_NumTicksPerGeneration = NumTicksPerGeneration;
            m_hwndMain              = hwndMain;
            m_iGenerations          = (0);
            cxClient                = (int)hwndMain.Width;
            cyClient                = (int)hwndMain.Height;
            dMutationRate           = _dMutationRate;
            dCrossoverRate          = _dCrossoverRate;
            //let's create the mine sweepers
            for (int i = 0; i < iNumSweepers; ++i)
            {
                m_vecSweepers.Add(new CMinesweeper((int)hwndMain.Width, (int)hwndMain.Height, m_SweeperScale, .3));
            }

            //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(iNumSweepers, dMutationRate, dCrossoverRate, m_NumWeightsInNN, dMaxPerturbation,
                                NumElite, NumCopiesElite);

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

            for (int i = 0; i < iNumSweepers; i++)
            {
                m_vecSweepers[i].PutWeights(m_vecThePopulation[i].Weights);
            }

            //initialize mines in random positions within the application window
            for (int i = 0; i < iNumMines; ++i)
            {
                m_vecMines.Add(new Vector3(Rand.NextDouble() * cxClient,
                                           Rand.NextDouble() * cyClient, 0));
            }

            //create a pen for the graph drawing
            m_BlackPen = new RGBA_Bytes(0, 0, 0, 255);
            m_BluePen  = new RGBA_Bytes(0, 0, 255);
            m_RedPen   = new RGBA_Bytes(255, 0, 0);
            m_GreenPen = new RGBA_Bytes(0, 150, 0);

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

            for (int i = 0; i < mine.Length; ++i)
            {
                m_MineVB.Add(mine[i]);
            }
        }
Ejemplo n.º 2
0
		public CController(IImageByte hwndMain, int iNumSweepers, int iNumMines, double _dMutationRate, double _dCrossoverRate, double dMaxPerturbation,
			int NumElite, int NumCopiesElite, int NumTicksPerGeneration)
		{
			Random Rand = new Random();

			m_MineScale = 1;
			m_SweeperScale = 3;

			m_pGA = null;
			m_bFastRender = (false);
			m_TicksThisGeneration = 0;
			m_NumTicksPerGeneration = NumTicksPerGeneration;
			m_hwndMain = hwndMain;
			m_iGenerations = (0);
			cxClient = (int)hwndMain.Width;
			cyClient = (int)hwndMain.Height;
			dMutationRate = _dMutationRate;
			dCrossoverRate = _dCrossoverRate;
			//let's create the mine sweepers
			for (int i = 0; i < iNumSweepers; ++i)
			{
				m_vecSweepers.Add(new CMinesweeper((int)hwndMain.Width, (int)hwndMain.Height, m_SweeperScale, .3));
			}

			//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(iNumSweepers, dMutationRate, dCrossoverRate, m_NumWeightsInNN, dMaxPerturbation,
				NumElite, NumCopiesElite);

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

			for (int i = 0; i < iNumSweepers; i++)
			{
				m_vecSweepers[i].PutWeights(m_vecThePopulation[i].Weights);
			}

			//initialize mines in random positions within the application window
			for (int i = 0; i < iNumMines; ++i)
			{
				m_vecMines.Add(new Vector3(Rand.NextDouble() * cxClient,
										   Rand.NextDouble() * cyClient, 0));
			}

			//create a pen for the graph drawing
			m_BlackPen = new RGBA_Bytes(0, 0, 0, 255);
			m_BluePen = new RGBA_Bytes(0, 0, 255);
			m_RedPen = new RGBA_Bytes(255, 0, 0);
			m_GreenPen = new RGBA_Bytes(0, 150, 0);

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

			for (int i = 0; i < mine.Length; ++i)
			{
				m_MineVB.Add(mine[i]);
			}
		}