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

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

?? troll.cpp

?? 一個AI游戲的代碼
?? CPP
字號:
/*****************************************************************
 * TROLL IMPLEMENTATION
 ****************************************************************/

#include "Troll.h"
#include "Chromosome.h"
#include <iostream.h>
#include <stdlib.h>


/*****************************************************************
 * THE MESSAGES
 ****************************************************************/

// Take some damage, either from a fight or from incoming fire
// from a Tower.  HitPoints stores the current health of the 
// troll; StatsDamageTaken stores the cumulative damage taken
// since the beginning of the simulation
void Troll::SendDamageMessage( int ouch )
{
	HitPoints -= ouch;
	StatsDamageTaken += ouch;

	if ( HitPoints <= 0 )
		IsDead = true;
}

// Capture message sent by traps
void Troll::SendCaptureMessage()
{
	IsCaptured = true;
}

// Fight message, sent by knights.  Returns true if the
// troll wins the duel
bool Troll::SendFightMessage()
{
	// Not a very elaborate fight system: we just roll the damage
  // caused by the knight in the whole fight at once, randomly

	// Fighting while captive ain't a smart idea
	if( IsCaptured )
	{
		SendDamageMessage( rand() % 15 + 5 );
	}
	else
	{
		SendDamageMessage( rand() % 10 );
	}

	if( IsDead )
	{
	  // Troll is killed
		return false;
	}
	else
	{
		// Knight is killed
		StatsKnightsKilled++;
		return true;
	}
}


/*****************************************************************
 * TURN UPDATE
 ****************************************************************/

bool Troll::Update()
{
	// We should never get here with a dead troll, but just in case...
	if( IsDead )
		return true;

  // If the troll hasn't eaten in a while, it sustains damage
	if( StatsTimeSinceLastMeal++ > 25 )
		SendDamageMessage( 1 );
	
	StatsTimeAlive++;

	// A captured troll will attempt to escape.  If he fails, he 
	// can't do a thing.
	if( IsCaptured && ( rand() % 10 < 7 ) )
	{
		StatsTimeCaptive++;
		return true;
	}

	IsCaptured = false;

	// Which goal do we follow?
	switch( PickStrategy() )
	{
		case EATING_PRIORITY: ImplementEatingStrategy(); break;
		case KILLING_PRIORITY: ImplementKillingStrategy(); break;
		case EXPLORING_PRIORITY: ImplementExploringStrategy(); break;
		case FLEEING_PRIORITY: ImplementFleeingStrategy(); break;
		case HEALING_PRIORITY: ImplementHealingStrategy(); break;
		default: break;
	}

	return true;
}


/****************************************************************
 * STRATEGY SELECTION
 ***************************************************************/

int Troll::PickStrategy()
{
	// Look at the state of the world around the troll and pick a
  // strategy that makes sense.  The biases encoded in the troll's
	// DNA play a crucial role here

	double bestSoFar = DNA->Priorities[ EATING_PRIORITY ] * EatingStrategy();
	int choice = EATING_PRIORITY;

	double newCandidate = DNA->Priorities[ KILLING_PRIORITY ] * KillingStrategy();

	if ( newCandidate > bestSoFar )
	{
		bestSoFar = newCandidate;
		choice = KILLING_PRIORITY;
	}

	newCandidate = DNA->Priorities[ HEALING_PRIORITY ] * HealingStrategy();
	if ( newCandidate > bestSoFar )
	{
		bestSoFar = newCandidate;
		choice = HEALING_PRIORITY;
	}

	newCandidate = DNA->Priorities[ FLEEING_PRIORITY ] * FleeingStrategy();
	if ( newCandidate > bestSoFar )
	{
		bestSoFar = newCandidate;
		choice = FLEEING_PRIORITY;
	}

	newCandidate = DNA->Priorities[ EXPLORING_PRIORITY ] * ExploringStrategy();
	if ( newCandidate > bestSoFar )
	{
		bestSoFar = newCandidate;		// Unnecessary, but kept there in case I add other goals later
		choice = EXPLORING_PRIORITY;
	}

	return choice;
}


// Trolls like to kill isolated adventurers, but stay away from
// packs of them.  Plus, a fight sounds a lot better when healthy!
double Troll::KillingStrategy()
{
	double score;
	int knights = ptrGrid->HowManyCloseToTroll( ENTITY_KNIGHT, 6 );
	if ( knights == 0 )
		score = 0.0;
	else if ( knights <= 2 )
		score = 0.8;
	else if ( knights <= 4 )
		score = 0.4;
	else
		score = 0.25;

	score -= 0.02 * ( FULL_HEALTH - HitPoints );
	return score;
}


// Eating is more interesting if there are sheep nearby and if
// the troll is hungry
double Troll::EatingStrategy()
{
	double score = 0.02 * StatsTimeSinceLastMeal;
	score += 0.1 * ptrGrid->HowManyCloseToTroll( ENTITY_SHEEP, 5 );
	return score;
}


// Exploring is always a decent option, except when heavily wounded
double Troll::ExploringStrategy()
{
	return 0.5 - 0.01 * ( FULL_HEALTH - HitPoints );
}


// If there are too many enemies around, and/or the troll is
// wounded, he should get away if he can.  Especially if there is
// a safe haven nearby!
double Troll::FleeingStrategy()
{
	double score;

	if ( HitPoints > REASONABLY_HEALTHY )
		score = 0.0;
	else if ( HitPoints > HEAVILY_DAMAGED )
		score = 0.3;
	else if ( HitPoints > CRITICALLY_DAMAGED )
		score = 0.6;

	score += 0.1 * ptrGrid->HowManyCloseToTroll( ENTITY_KNIGHT, 4 );
	score += 0.05 * ptrGrid->HowManyCloseToTroll( ENTITY_TOWER, 3 );
	if( ptrGrid->HowManyCloseToTroll( ENTITY_HAVEN, 3 ) > 0 )
		score += 0.2;

	return 0.2;
}


// Is it time to just do nothing and heal?  Well, if we are within
// range of a firing tower, we're wasting our time because the
// damage will just keep piling on.  And if we're very close to a
// haven without actually being in it, we probably should go there
// first because we'll heal faster.
double Troll::HealingStrategy()
{
	double score = 0.02 * ( FULL_HEALTH - HitPoints );
	if( ptrGrid->HowManyCloseToTroll( ENTITY_TOWER, 3 ) > 0 )
		score -= 0.2;
	if( ptrGrid->HowManyCloseToTroll( ENTITY_KNIGHT, 3 ) > 0 )
		score -= 0.1;
	if( ptrGrid->HowManyCloseToTroll( ENTITY_HAVEN, 2 ) > 0 )
		score -= 0.1;
	if( ptrGrid->HowManyCloseToTroll( ENTITY_HAVEN, 0 ) > 0 )
		score += 0.5;

	return score;
}


/*****************************************************************
 * STRATEGY IMPLEMENTATIONS
 * These methods are pretty dumb, but we're talking about a troll 
 * here, not the Dalai Lama.  Plus, this sample code is cluttered
 * enough as it is; no need to make it even worse! ;-)
 ****************************************************************/

void Troll::ImplementEatingStrategy()
{
	// Look for a sheep nearby
	int target = ptrGrid->FindClosestFromTroll( ENTITY_SHEEP );
	if ( target == -1 )
	{
		// No more sheep on the grid; wander instead
		ImplementExploringStrategy();	
	}

	// Can we reach it at once?  If so, let's do it
	if ( ptrGrid->DistanceFromTroll( target ) <= 4 )
	{
	  MoveEntity( ptrGrid->GetEntityX( target ) - GetX(), ptrGrid->GetEntityY( target ) - GetY() );
		StatsSheepEaten += ptrGrid->HowManyCloseToTroll( ENTITY_SHEEP, 0 );
	}

	// Otherwise, march towards the sheep in question
	else
	{
		int dx, dy;
		if( ptrGrid->GetEntityX( target ) > GetX() )
			dx = 2;
		else if ( ptrGrid->GetEntityX( target ) == GetX() )
			dx = 0;
		else
			dx = -2;
		if( ptrGrid->GetEntityY( target ) > GetY() )
			dy = 2;
		else if ( ptrGrid->GetEntityY( target ) == GetY() )
			dy = 0;
		else
			dy = -2;
		MoveEntity( dx, dy );
	}
}


void Troll::ImplementKillingStrategy()
{
	// Look for a suitable target
	int target = ptrGrid->FindClosestFromTroll( ENTITY_KNIGHT );
	if ( target == -1 )
	{
		ImplementExploringStrategy();	
	}

	// Can we attack it immediately?  If so, let's move into its square
	if ( ptrGrid->DistanceFromTroll( target ) <= 4 )
	{
		// the knight will initiate combat next turn, so we don't have to.
	  MoveEntity( ptrGrid->GetEntityX( target ) - GetX(), ptrGrid->GetEntityY( target ) - GetY() );
	}

	// Otherwise, march towards the target
	else
	{
		int dx, dy;
		if( ptrGrid->GetEntityX( target ) > GetX() )
			dx = 2;
		else if ( ptrGrid->GetEntityX( target ) == GetX() )
			dx = 0;
		else
			dx = -2;
		if( ptrGrid->GetEntityY( target ) > GetY() )
			dy = 2;
		else if ( ptrGrid->GetEntityY( target ) == GetY() )
			dy = 0;
		else
			dy = -2;
		MoveEntity( dx, dy );
	}
}


void Troll::ImplementHealingStrategy()
{
	// Doing nothing restores some health
	HitPoints += ( rand() % 3 );

	// Safe havens are filled with decaying flesh, carnivorous
	// plants, venomous mushrooms and other delicacies that speed
	// up troll healing.
	if( ptrGrid->HowManyCloseToTroll( ENTITY_HAVEN, 0 ) > 0 )
	{
		HitPoints += 2;
	}
	
	// Can't get healthier than perfect health
	if( HitPoints > FULL_HEALTH )
		HitPoints = FULL_HEALTH;
}


void Troll::ImplementFleeingStrategy()
{
	// Can we retreat to a safe haven?  If so, do it
	int haven = ptrGrid->FindClosestFromTroll( ENTITY_HAVEN );
	if( ptrGrid->DistanceFromTroll( haven ) <= 4 )
	{
	  MoveEntity( ptrGrid->GetEntityX( haven ) - GetX(), ptrGrid->GetEntityY( haven ) - GetY() );		
	}

	// Otherwise, run away from the closest knight
	else
	{
		int target = ptrGrid->FindClosestFromTroll( ENTITY_KNIGHT );
		int dx, dy;

		if( ptrGrid->GetEntityX( target ) > GetX() )
			dx = -2;
		else
			dx = 2;
		if( ptrGrid->GetEntityY( target ) > GetY() )
			dy = -2;
		else
			dy = 2;

		MoveEntity( dx, dy );
	}
}


// The troll's exploring "strategy" consists of 
// wandering about aimlessly.
void Troll::ImplementExploringStrategy()
{
	MoveEntity( rand() % 5 - 2, rand() % 5 - 2 );
}


/*****************************************************************
 * SIMULATION
 *****************************************************************/

void Troll::Reset()
{
	HitPoints = FULL_HEALTH;
	IsCaptured = false;
	IsDead = false;
	StatsTimeSinceLastMeal = 0;
	StatsKnightsKilled = 0;
	StatsSheepEaten = 0;
	StatsDamageTaken = 0;
	StatsTimeAlive = 0;
	StatsTimeCaptive = 0;
}


double Troll::GetEvaluation()
{
	double score = 8.0 * StatsKnightsKilled + 	10.0 * StatsSheepEaten +	1.5 * StatsTimeAlive -
					1.0 * StatsTimeCaptive - 2.50 * StatsDamageTaken;
	return score;
}




void Troll::Dump()
{
	cout << "TROLL DUMPED at x,y = " << GetX() << "," << GetY() << endl;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区不卡| 亚洲第一会所有码转帖| 欧美丰满一区二区免费视频| 成人美女视频在线看| 国产一区二区伦理片| 亚洲成人精品一区| 天天综合色天天| 亚洲一区二区三区免费视频| 亚洲最色的网站| 亚洲国产欧美一区二区三区丁香婷| 亚洲欧洲性图库| 成人欧美一区二区三区黑人麻豆 | 日韩二区在线观看| 午夜精品成人在线视频| 日日夜夜免费精品| 日本美女一区二区三区| 裸体歌舞表演一区二区| 国模一区二区三区白浆| 国产成人亚洲综合a∨婷婷| 国产精品白丝jk白祙喷水网站| 粉嫩在线一区二区三区视频| 色综合欧美在线| 欧美日韩高清一区二区三区| 日韩一区二区电影在线| 国产色一区二区| 日韩理论电影院| 亚洲一区二区三区四区在线免费观看 | 成人黄色av电影| av激情综合网| 欧美丰满嫩嫩电影| 久久久久久综合| 一区二区三区欧美日| 天天综合网 天天综合色| 精东粉嫩av免费一区二区三区| 国产在线一区观看| 91麻豆视频网站| 欧美一级欧美一级在线播放| 2024国产精品| 一区二区三区免费观看| 久久国产精品一区二区| 91在线精品一区二区三区| 在线成人av影院| 国产精品免费久久| 日韩成人av影视| 99re66热这里只有精品3直播| 欧美丰满嫩嫩电影| 亚洲愉拍自拍另类高清精品| 男女男精品视频| 91麻豆文化传媒在线观看| 欧美不卡123| 一二三区精品福利视频| 国产精品自拍网站| 欧美另类高清zo欧美| 亚洲欧洲精品成人久久奇米网| 三级一区在线视频先锋 | 免费成人av在线| 在线视频一区二区免费| 久久久久久电影| 久久精品免费观看| 欧美日韩亚洲综合| 亚洲欧美色综合| 国产69精品一区二区亚洲孕妇| 欧美一卡二卡三卡四卡| 亚洲最大的成人av| 99久久精品国产观看| 国产日韩三级在线| 狠狠狠色丁香婷婷综合激情| 欧美日韩午夜在线视频| 亚洲综合一区二区精品导航| 不卡视频免费播放| 欧美激情在线免费观看| 国产乱淫av一区二区三区| 日韩美一区二区三区| 日韩av一区二区在线影视| 欧美日韩中文一区| 亚洲一区二区高清| 欧美性大战xxxxx久久久| 一区在线播放视频| av一区二区不卡| √…a在线天堂一区| 99久久久久久| 中文字幕在线观看不卡视频| 成人h动漫精品一区二| 欧美激情综合在线| 成人性生交大片免费看在线播放| 久久在线免费观看| 国产一区二区三区久久悠悠色av| 精品国产凹凸成av人导航| 精品一区二区三区在线播放视频| 亚洲精品一区二区三区精华液 | 国产精品影视在线| 国产午夜亚洲精品理论片色戒| 国产麻豆视频一区| 国产日产欧美一区二区三区| 福利电影一区二区| 亚洲日本va在线观看| 色综合久久天天| 天堂成人国产精品一区| 欧美变态tickle挠乳网站| 国产成人亚洲综合a∨婷婷图片| 国产精品国产成人国产三级| 91久久国产最好的精华液| 国产精品自产自拍| 国产剧情在线观看一区二区| 久久久久久久性| 成人av集中营| 亚洲成人精品影院| 精品卡一卡二卡三卡四在线| 国产成人av影院| 亚洲另类一区二区| 日韩一区二区三区高清免费看看| 久久精品国产99国产| 国产精品美女www爽爽爽| 欧美日韩中文精品| 国产精品一二三区在线| 一区二区三国产精华液| 欧美不卡一区二区三区四区| 99热99精品| 蜜桃久久久久久| 亚洲三级电影全部在线观看高清| 欧美一区二区福利视频| 从欧美一区二区三区| 日韩av中文在线观看| 136国产福利精品导航| 日韩精品一区二区三区三区免费| 成人avav在线| 黄一区二区三区| 亚洲精品视频在线观看免费| 精品国产乱码久久久久久牛牛| 94色蜜桃网一区二区三区| 精品一区二区三区影院在线午夜| 亚洲激情网站免费观看| 日本一区二区免费在线| 日韩欧美三级在线| 欧美日韩一卡二卡三卡| 色呦呦国产精品| 国产成人免费在线观看| 久久99久久久久久久久久久| 亚洲一区二区高清| 亚洲男女一区二区三区| 国产精品久久久久久户外露出| 精品91自产拍在线观看一区| 欧美高清你懂得| 欧美性色aⅴ视频一区日韩精品| 成人aa视频在线观看| 粉嫩av一区二区三区| 国产一区二区三区电影在线观看| 青青草原综合久久大伊人精品优势| 一区2区3区在线看| 亚洲欧美成人一区二区三区| 国产精品电影一区二区| 国产精品乱人伦| 国产精品免费视频观看| 国产精品色一区二区三区| 久久精品夜夜夜夜久久| 久久精品免视看| 国产欧美日韩亚州综合| 欧美国产国产综合| 国产婷婷精品av在线| 国产欧美一区二区三区网站| 日本一区二区三区国色天香| 国产精品伦理在线| 亚洲三级理论片| 亚洲成a人在线观看| 亚洲午夜日本在线观看| 欧美老年两性高潮| 欧美二区乱c少妇| 777奇米成人网| 欧美电影在线免费观看| 日韩午夜在线播放| 精品粉嫩超白一线天av| 久久久久久影视| 亚洲视频一二三| 亚洲综合清纯丝袜自拍| 日韩精品亚洲一区| 激情丁香综合五月| av亚洲精华国产精华| 欧美在线观看你懂的| 欧美乱妇15p| 国产亚洲美州欧州综合国| 亚洲欧美中日韩| 亚洲成人av资源| 国产精品1区二区.| 95精品视频在线| 日韩欧美国产一区在线观看| 欧美国产欧美综合| 亚洲丝袜制服诱惑| 丝袜诱惑亚洲看片| 丰满少妇久久久久久久| 欧美亚洲一区二区在线| 精品国精品自拍自在线| 久久精品人人爽人人爽| 亚洲激情中文1区| 亚洲私人黄色宅男| 日本少妇一区二区| caoporn国产一区二区| 欧美视频三区在线播放| 国产亚洲一区二区三区四区 | 国产一区二区三区免费观看| 国产成人在线影院 |