コード例 #1
0
ファイル: UnitMng.cpp プロジェクト: b4rdos/StarBard
double UnitMng::assessFitness()
{
	// fitness assess for every command issue 
	// takes into mind if the unit is under attack, if there is an enemy around end the NN 
	// issues an attack command, the kill count the rate it loses HP, if it follows group commands
	// and the organism's fitness. 
	if(conUnit)
	{
		double AttF,ComF;
		double nAttF=enemyExists(conUnit)?1.0:0.0;
		AttF=(ATTACK-act)?-5.0:5.0;
		ComF=(groupCommand-act)?5:-5;
		//Maybe 
		KillCount=conUnit->getKillCount();
		double tempDist=(1-(conUnit->getDistance(UnitGroup->getPosition())/96.0))<0?0:(1-(conUnit->getDistance(UnitGroup->getPosition())/96.0));
		double tempFit=underAttack()*AttF+(1.0-nAttF)*AttF+10*(1.0-lastHP+getHitPoints())+40*(KillCount+pastKC)/(1+DeathCount)+15*tempDist+ComF+fitness;
		//double tempFit=3*(1.0-lastHP+getHitPoints())+10*(KillCount+pastKC)/(1+DeathCount)+ComF+6*tempDist;
		fitness=tempFit<0?0:tempFit;
		lastHP=getHitPoints();
	}
	else
	{
		fitness=40*(KillCount+pastKC)/(1+DeathCount)+fitness;
	}
	timeAlive++;
	return fitness;
}
コード例 #2
0
ファイル: UnitShared.cpp プロジェクト: oenayet/bwapi
 //------------------------------------- INITIAL INFORMATION FUNCTIONS --------------------------------------
 void UnitImpl::saveInitialState()
 {
   initialType      = getType();
   initialPosition  = getPosition();
   initialResources = getResources();
   initialHitPoints = getHitPoints();
 }
コード例 #3
0
ファイル: Actor.cpp プロジェクト: laurenyeung/BoulderBlast
void Player::getsDamaged(int d)
{
	ActorWithHit::getsDamaged(d);
	if (getHitPoints() > 0)
		getWorld()->playSound(SOUND_PLAYER_IMPACT);
	else
		getWorld()->playSound(SOUND_PLAYER_DIE);	
}
コード例 #4
0
ファイル: Actor.cpp プロジェクト: laurenyeung/BoulderBlast
void Robot::getsDamaged(int damage, int points)
{
	ActorWithHit::getsDamaged(damage);
	if (getHitPoints() > 0)
		getWorld()->playSound(SOUND_ROBOT_IMPACT);
	else
	{
		getWorld()->playSound(SOUND_ROBOT_DIE);
		getWorld()->increaseScore(points);
	}
}
コード例 #5
0
ファイル: character.cpp プロジェクト: pelagos/amarlon
void Character::modifyHitPoints(int modifier)
{
  int toSet = getHitPoints() + modifier;
  if ( toSet > getMaxHitPoints() )
  {
    toSet = getMaxHitPoints();
  }
  else if ( toSet < 0 )
  {
    toSet = 0;
  }

  setHitPoints( toSet );
}
コード例 #6
0
ファイル: UnitMng.cpp プロジェクト: b4rdos/StarBard
void UnitMng::generateInputs()
{
	BWAPI::Unit *enemyUnit=0;
	BWAPI::Unit *tempUnit=getUnit();
	
	//Units position

	//mapWidth() is in TilePosition Units which is 32 pixels
	inputs[0]=((tempUnit->getPosition().x())/(BWAPI::Broodwar->mapWidth()*32.0));
	inputs[1]=(tempUnit->getPosition().y())/(BWAPI::Broodwar->mapHeight()*32.0);
	//Group leader position
	inputs[2]=(UnitGroup->getPosition().x())/(BWAPI::Broodwar->mapWidth()*32.0);
	inputs[3]=(UnitGroup->getPosition().y())/(BWAPI::Broodwar->mapHeight()*32.0);
	//How many hit points?
	inputs[4]=getHitPoints();
	// Is there an enemy within the unit's seek range?
	enemyUnit=enemyExists(tempUnit);
	inputs[5]=enemyUnit?1.0:0;
	// Find closest enemy
	enemyUnit=closestEnemy();
	inputs[6]=enemyUnit?(UnitGroup->getPosition().x())/(BWAPI::Broodwar->mapWidth()*32.0):1.0;
	inputs[7]=enemyUnit?(UnitGroup->getPosition().y())/(BWAPI::Broodwar->mapHeight()*32.0):1.0;
	inputs[8]=underAttack();
	//check surroundings
	//east
	inputs[9]=getBlocked(0,1);
	//north-east
	inputs[10]=getBlocked(1,1);
	//north
	inputs[11]=getBlocked(1,0);
	//north-west
	inputs[12]=getBlocked(1,-1);
	//west
	inputs[13]=getBlocked(0,-1);
	//south-west
	inputs[14]=getBlocked(-1,-1);
	//south
	inputs[15]=getBlocked(-1,0);
	//south-east
	inputs[16]=getBlocked(-1,1);
	//Get Group Command;
	inputs[17]=GroupCommand();
	//get last Command or not maybe useless
	inputs[18]=getLastCommand();	
	//bias
	inputs[19]=1.0;
	//return inputs;
}
コード例 #7
0
ファイル: UnitMng.cpp プロジェクト: b4rdos/StarBard
bool UnitMng::setUnit(BWAPI::Unit* unit)
{
	if(conUnit)
		DeathCount++;
	pastKC=KillCount+pastKC;
	conUnit=unit;
	if(conUnit)
	{
		KillCount=conUnit->getKillCount();
		lastHP=getHitPoints();
	}
	else
		KillCount=0;
	
	return true;
}
コード例 #8
0
ファイル: Enemy.cpp プロジェクト: Faianca/hikari
    void Enemy::update(float dt) {
        Entity::update(dt);

        if(getHitPoints() <= 0.0f) {
            if(auto eventManagetPtr = getEventBus().lock()) {
                eventManagetPtr->queueEvent(EventDataPtr(new EntityDeathEventData(getId(), EntityDeathEventData::Enemy)));
            }
        }
        
        if(brain) {
            brain->update(dt);
        }

        if(damageTickCounter > 0) {
            // setVulnerable(false);
            damageTickCounter++;
            damageTickCounter %= 2;
        } else {
            // setVulnerable(true);
        }
    }
コード例 #9
0
bool Battleship::checkEnd() {
	if (getHitPoints() == getScore()) { // Has all of battleship been hit?
		cout << "You sunk the battleship!" << endl;
		cout << "YOU WIN!" << endl;

		asciiThumbsUp();

		return true;
	}
	else if (getLives() == 0) {
		cout << "You have no shots left..." << endl << endl;
		cout << "YOU LOSE!" << endl << endl;
		cout << "Here is where the battleship was:" << endl;
		printBattleground();
		return true;
	}
	else {
		cout << "You have " << getScore() << " hits and " << getLives() << " shots left..." << endl << endl;
		return false;
	}
}
コード例 #10
0
ファイル: Object.hpp プロジェクト: Dimplexion/PutkaRTS
	/**
	 * Add (or subtract) object's hit points.
	 *
	 * @param change Hit points change.
	 */
	void addHitPoints(int change) {
		setHitPoints(getHitPoints() + change);
	}
コード例 #11
0
ファイル: Enemy.cpp プロジェクト: Faianca/hikari
 void Enemy::takeDamage(float amount) {
     setHitPoints(getHitPoints() - amount);
     damageTickCounter = 1;
 }