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

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

?? genetic.cpp

?? 一個AI游戲的代碼
?? CPP
字號:
/****************************************************************
 * Implementation of Class Genetic
 ***************************************************************/

#include "Genetic.h"
#include "Simulation.h"
#include "Troll.h"
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>


/*****************************************************************
 * Populating the world with trolls...
 ****************************************************************/

void Genetic::MakeRandomIndividual( int which )
{
	Population[ which ].DNA.Priorities[ EATING_PRIORITY ] = (double) ( rand() % 10000 ) / 10000.0;
	Population[ which ].DNA.Priorities[ KILLING_PRIORITY ] = (double) ( rand() % 10000 ) / 10000.0;
	Population[ which ].DNA.Priorities[ FLEEING_PRIORITY ] = (double) ( rand() % 10000 ) / 10000.0;
	Population[ which ].DNA.Priorities[ EXPLORING_PRIORITY ] = (double) ( rand() % 10000 ) / 10000.0;
	Population[ which ].DNA.Priorities[ HEALING_PRIORITY ] = (double) ( rand() % 10000 ) / 10000.0;
}

void Genetic::CreateInitialPopulation()
{
	for( int i = 0; i < GA_POPULATION_SIZE; i++ )
	{
		MakeRandomIndividual( i );
	}
}

/*****************************************************************
 * The evolutionary process
 ****************************************************************/

// The mothership method for the whole process
void Genetic::RunEvolution()
{
	// Set up the gene pool
	CreateInitialPopulation();
	theSim.BuildTestCases();

	// And iterate the testing process over N generations
	for( int i = 0; i < GA_GENERATIONS; i++ )
	{
		RunGeneration();
		ReportGenerationResults( i );
		if( i < GA_GENERATIONS - 1 )
			BegetNextGeneration();
	}
}

// Helper function to classify individuals based on performance
int RankIndividuals( const void * a, const void * b )
{
	Individual * ia = ( Individual * ) a;
	Individual * ib = ( Individual * ) b;

	if( ia->Performance > ib->Performance )
		return -1;
	else
		return 1;
}

// Test an entire population of trolls
void Genetic::RunGeneration()
{
	for( int i = 0; i < GA_POPULATION_SIZE; i++ )
	{
		// Place the troll in the game world
		Troll theTroll( Population[ i ].DNA, rand() % WORLD_GRID_SIZE, rand() % WORLD_GRID_SIZE );
		Entity::AttachTroll( theTroll );

		// Run the simulation with this troll and extract the results
		Population[ i ].Performance = theSim.RunSim( theTroll );
		Population[ i ].StatsSheepEaten = theTroll.StatsSheepEaten;
		Population[ i ].StatsKnightsKilled = theTroll.StatsKnightsKilled;
		Population[ i ].StatsDamageTaken = theTroll.StatsDamageTaken;
		Population[ i ].StatsTimeAlive = theTroll.StatsTimeAlive;
		Population[ i ].StatsTimeCaptive = theTroll.StatsTimeCaptive;
	}

	// And classify the population
	qsort( Population, GA_POPULATION_SIZE, sizeof( Individual ), RankIndividuals );
}


// How do we generate a new population according to the results of
// their parents?
// WARNING: THIS FUNCTION WILL NOT WORK IF POPULATION SIZE IS LESS 
// THAN 90 INDIVIDUALS.  For smaller populations, you will have to
// change the parenting rules.
void Genetic::BegetNextGeneration()
{
	// First, we keep the top 20 individuals from the last 
	// generation, without change.

	// Then, we make 42 new individuals by mating the top
	// 7 performers, giving the higher-ranked individuals more
	// chances to reproduce.  The following chunk of code only
	// selects the parents; mating occurs later.
	int currentIndex = 20;
	for( int higher = 0; higher < 6; higher++ )
	{
		for( int lower = higher + 1; lower < 7; lower++ )
		{
			Population[ currentIndex++ ] = Population[ higher ];
			Population[ currentIndex++ ] = Population[ lower ];
		}
	}

	// Then, we mate 14 pairs of randomly-selected individuals
	// from the top third of the parent population.  Again, we
	// only select the parents here; mating for both this group
	// and the preceding one takes place later
	for( int i = 0; i < 14; i++ )
	{
		Population[ currentIndex++ ] = Population[ rand() % 10 ];
		Population[ currentIndex++ ] = Population[ rand() % 25 + 10 ];
	}

	// This is the actual mating process for the last two groups
	for( i = 20; i < 90; i += 2 )
	{
		// First, apply crossover to each pair of parents
		Crossover( Population[ i ].DNA, Population[ i + 1 ].DNA );

		// And then mutate the children, maybe
		Mutation( Population[ i ].DNA );
		Mutation( Population[ i + 1 ].DNA );
	}

	// Finally, complete the population with a handful of brand
	// new individuals to introduce new variety into the gene pool
	for( i = 90; i < GA_POPULATION_SIZE; i++ )
	{
		MakeRandomIndividual( i );
	}
}


/****************************************************************
 * The Genetic Operators
 ***************************************************************/


// We crossover using the Disruption method (each gene can
// crossover independantly from the others).  Given the small
// number of genes in our scenario, this sounds like a reasonable
// approach.
void Genetic::Crossover( Chromosome & c1, Chromosome & c2 )
{
	for( int i = 0; i < ALL_PRIORITIES; i++ )
	{
		if( rand() % 2 == 0 )
		{
			double tmp = c1.Priorities[ i ];
			c1.Priorities[ i ] = c2.Priorities[ i ];
			c2.Priorities[ i ] = tmp;
		}
	}
}

// We mutate by replacing one gene by a random number, once
// in a while
void Genetic::Mutation( Chromosome & c )
{
	for( int i = 0; i < ALL_PRIORITIES; i++ )
	{
		if( rand() % 100 < MUTATION_RATE )
		{
			c.Priorities[ i ] = (double) (rand() % 10000) / 10000.0;
		}
	}
}


/****************************************************************
 * REPORTING RESULTS
 ***************************************************************/

void Genetic::ReportGenerationResults( int which )
{
	cout << "RESULTS FOR GENERATION " << which << endl;
	cout << "-------------------------" << endl << endl;

	cout << "   EAT   KILL   HEAL   FLEE   EXPL    SHEEP  KNIGHT  ALIVE  CAPTV  DAMAG    PERF" << endl;
	for( int i = 0; i < GA_POPULATION_SIZE; i++ )
	{
		cout << setw( 6 ) << setprecision( 5 ) << Population[ i ].DNA.Priorities[ EATING_PRIORITY ] << " "
				 << setw( 6 ) << setprecision( 5 ) << Population[ i ].DNA.Priorities[ KILLING_PRIORITY ] << " "
				 << setw( 6 ) << setprecision( 5 ) << Population[ i ].DNA.Priorities[ HEALING_PRIORITY ] << " "
				 << setw( 6 ) << setprecision( 5 ) << Population[ i ].DNA.Priorities[ FLEEING_PRIORITY ] << " "
				 << setw( 6 ) << setprecision( 5 ) << Population[ i ].DNA.Priorities[ EXPLORING_PRIORITY ] << " "
				 << setw( 8 ) << Population[ i ].StatsSheepEaten << " "
				 << setw( 7 ) << Population[ i ].StatsKnightsKilled << " "
				 << setw( 6 ) << Population[ i ].StatsTimeAlive << " "
				 << setw( 6 ) << Population[ i ].StatsTimeCaptive << " "
				 << setw( 6 ) << Population[ i ].StatsDamageTaken << " "
				 << setw( 8 ) << setprecision( 6 ) << Population[ i ].Performance
				 << endl;
	}

	cout << endl << endl;
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www国产精品av| 蜜臀av一区二区| 亚洲大片一区二区三区| 国模一区二区三区白浆| 欧美综合在线视频| 国产午夜精品在线观看| 三级不卡在线观看| 91丨porny丨首页| 精品国产一区二区三区四区四| 中文字幕亚洲视频| 在线亚洲欧美专区二区| 国产亚洲欧洲997久久综合| 婷婷综合另类小说色区| 成人永久aaa| xvideos.蜜桃一区二区| 日本美女一区二区三区| 欧美午夜理伦三级在线观看| 中文字幕在线播放不卡一区| 国产综合久久久久影院| 欧美一区二区三区在线电影 | 欧美视频一区二区三区在线观看| 久久精品视频在线免费观看| 蜜臀va亚洲va欧美va天堂| 欧洲精品一区二区三区在线观看| 国产精品福利一区二区三区| 国产高清亚洲一区| 久久久99久久精品欧美| 国产在线麻豆精品观看| 精品日韩一区二区三区| 蜜臂av日日欢夜夜爽一区| 欧美日韩精品欧美日韩精品| 一区二区在线电影| 在线视频欧美区| 国产精品护士白丝一区av| 懂色av中文一区二区三区| 久久久国产一区二区三区四区小说| 美国一区二区三区在线播放| 欧美电影免费观看高清完整版| 丝袜亚洲另类欧美综合| 91精品国产综合久久福利软件| 午夜精品成人在线| 欧美日韩免费视频| 免费观看91视频大全| 亚洲激情图片一区| 色香色香欲天天天影视综合网| 亚洲视频一二三| 在线观看免费亚洲| 热久久国产精品| 久久亚洲综合av| 国产美女精品人人做人人爽 | 蜜桃视频一区二区三区| 精品国产制服丝袜高跟| 国产精品一区二区无线| 国产精品久久久久久久岛一牛影视 | 亚洲精品在线观| 国产麻豆精品theporn| 欧美国产激情一区二区三区蜜月 | 久久se这里有精品| 久久久久久免费网| 国内精品久久久久影院一蜜桃| 久久精品网站免费观看| 99精品国产一区二区三区不卡| 亚洲大片精品永久免费| 精品国产乱码久久久久久闺蜜| 国产盗摄精品一区二区三区在线| ●精品国产综合乱码久久久久| 欧美三级乱人伦电影| 精品中文字幕一区二区| 中文字幕日韩一区| 日本乱人伦aⅴ精品| 麻豆91在线播放| **网站欧美大片在线观看| 欧美日韩一级片网站| 国产精品一二三区在线| 亚洲综合av网| 久久久综合激的五月天| 91搞黄在线观看| 麻豆成人91精品二区三区| 国产精品久久福利| 日韩免费观看高清完整版| 97se亚洲国产综合自在线不卡| 日韩精品欧美精品| 国产精品夫妻自拍| 欧美成人在线直播| 精品视频免费看| 成人免费福利片| 久久99精品久久只有精品| 亚洲最新视频在线播放| 久久精品人人爽人人爽| 欧美一区二区三区爱爱| 色综合久久久久综合体桃花网| 韩国精品在线观看| 香港成人在线视频| 亚洲男帅同性gay1069| 精品粉嫩超白一线天av| 欧美久久一二三四区| 99re热这里只有精品免费视频| 国产一区二区三区免费| 奇米色777欧美一区二区| 亚洲精品乱码久久久久久日本蜜臀| 久久综合av免费| 日韩视频一区二区三区在线播放| 欧美亚洲日本国产| av一区二区三区黑人| 国产精品1区二区.| 精品制服美女丁香| 免费观看日韩电影| 日韩高清一区二区| 丝袜美腿成人在线| 午夜精品久久久久久久久| 怡红院av一区二区三区| 亚洲视频综合在线| 亚洲区小说区图片区qvod| 国产精品久久久久久久久果冻传媒| 欧美精品一区二区精品网| 欧美一区二区视频网站| 91精品免费在线| 欧美一区二视频| 日韩一区二区电影网| 国产精品久久毛片a| 亚洲欧洲精品一区二区精品久久久| 国产精品视频九色porn| 国产精品丝袜91| 亚洲视频在线一区| 亚洲人成网站精品片在线观看 | 99久久亚洲一区二区三区青草| 国产一区二区三区在线观看精品| 国产一区二区三区黄视频 | 麻豆91精品视频| 精品一区中文字幕| 国产一区二区视频在线| 国产在线国偷精品产拍免费yy| 国产成人一区在线| aaa亚洲精品一二三区| 91福利视频在线| 在线观看亚洲精品| 欧美精品aⅴ在线视频| 精品国偷自产国产一区| 中文子幕无线码一区tr| 亚洲欧美日韩国产综合| 亚洲国产一区在线观看| 日本午夜精品视频在线观看| 久久精品国产免费看久久精品| 狠狠色丁香婷婷综合| 成人av电影免费观看| 欧美日韩的一区二区| 26uuu久久天堂性欧美| 中文字幕中文字幕一区| 亚洲国产日韩a在线播放| 蜜桃视频一区二区三区| 成人av网在线| 欧美精品18+| 日本一区二区高清| 亚洲一区二区三区在线| 精品一区二区三区在线观看国产| 高清不卡一区二区| 欧美午夜电影在线播放| 久久日韩精品一区二区五区| 亚洲精品视频一区二区| 久久99久国产精品黄毛片色诱| av高清不卡在线| 欧美成人一级视频| 亚洲精品久久久蜜桃| 久草精品在线观看| 色婷婷综合久久久久中文| 日韩三级中文字幕| 亚洲精品久久嫩草网站秘色| 精品一区二区免费看| 欧美影片第一页| 国产亚洲欧美在线| 日本欧美一区二区三区乱码| 色综合天天天天做夜夜夜夜做| 精品免费一区二区三区| 亚洲超碰97人人做人人爱| 成人丝袜18视频在线观看| 欧美一区二区三区男人的天堂| 成人免费在线视频观看| 国产在线一区二区综合免费视频| 欧洲国内综合视频| 国产精品久久久久久一区二区三区| 婷婷综合另类小说色区| 一本大道av伊人久久综合| 国产欧美日韩精品一区| 激情综合网天天干| 日韩欧美一区在线| 亚洲一区二区三区三| 91丨九色丨蝌蚪丨老版| 国产精品美女一区二区| 精品欧美一区二区在线观看| 丝袜美腿亚洲一区| 欧美色电影在线| 亚洲一区免费在线观看| 色综合亚洲欧洲| 亚洲人成伊人成综合网小说| 成人精品在线视频观看| 欧美高清在线精品一区| 豆国产96在线|亚洲| 国产精品人成在线观看免费| 国产成人在线网站| 国产日韩欧美精品一区|