go2starr / CS-638-BWAPI

Starcraft: Broodwar AI bot
GNU Lesser General Public License v3.0
9 stars 7 forks source link

Remote army doesn't respond to attack at main base #45

Open djmayer101 opened 12 years ago

djmayer101 commented 12 years ago

Scouting armies don't respond to attacks on main base, instead they continue scouting for the enemy.

severity: high priority: high

Suggestions: When main base is under attack, and current at-base force is insufficient to repel invaders, recall attack unit.

djmayer101 commented 12 years ago
severity: blocker
jmloethen commented 12 years ago

Cases where enemies are attacking the base are not handled yet. Only the initial enemy starting location as an attack target is known at this time.

diansheng commented 12 years ago

i have written the logic of attacking whatever is in range. if add the logic 'go to the next enemy after killing current target' will do. haven't tested on starcraft yet but logic is there.

//skeleton //loop over every attackSquad //if enough soliders, go attack //if no enemy in sight, go to first target (enemy base), //else //compare force: //TODO:give weights to different type of enemies //if this squard is in favor, fight, //else, //if total force of all squads in favor //evade until not being attacked //get other attack squard come to help //else go back to base to defence

//implementation //if enough soliders, go attack if ((*it)->getSize() == AttackSquadSize && leader != NULL && numTroops > 50) { //check nearby units conditions for (UnitSetIter unitIt = unitsInRange.begin(); unitIt != unitsInRange.end(); unitIt++) { int numEnemy =0; int numAllies = 0;

    // check for enemy number and weakest target
    BWAPI::Unit * enemyTargetInRange = NULL;
    if ((*unitIt)->getPlayer() != Broodwar->self() &&

(_unitIt)->getType().canAttack()) { // also check shields int tempHitPoints = (_unitIt)->getHitPoints() + (*unitIt)->getShields();

        if (tempHitPoints == 0)
            continue;

        if ((*unitIt)->getType() == BWAPI::UnitTypes::Terran_Medic)
        {
            enemyTargetInRange = *unitIt;
            break;
        }
        else if (tempHitPoints < hitPoints)
        {
            hitPoints = tempHitPoints;
            enemyTargetInRange = *unitIt;
        }
        numEnemy++;
    }
    else if ((*unitIt)->getPlayer() != Broodwar->self()
            && ((*unitIt)->getType().canAttack()
            || (*unitIt)->getType() == BWAPI::UnitTypes::Terran_Medic
            || (*unitIt)->getType() ==

BWAPI::UnitTypes::Terran_Bunker)){ numAllies++; } }

//if no enemy in sight, go to first target (enemy base),
if (numEnemy == 0){
    leader->setState(AttackState);
    leader->setPositionTarget(enemyBase);
}
//else
else{//compare force:
    //if this squard is in favor, attack weakest unit
    if (numAllies>numEnemy){
        // find a target?
        if (enemyTargetInRange != NULL)
        {
            leader->setState(AttackState);
            leader->setUnitTarget(enemyTargetInRange);
        }
        else
        {
            // reset if no targets in range
            leader->setState(AttackState);
            leader->setPositionTarget(enemyBase);
        }
    }
    //else, TODO
            //if total force of all squads in favor
/*    else if (numSoliders > numEnemy){
        //evade until not being attacked
        //get other attack squard come to help
    }
*/    //else go back to base to defence TODO
    else{
    leader->setState(AttackState);
    leader->setPositionTarget(Base);////////////change to base to

currect variable } } }

On Mon, May 7, 2012 at 10:57 AM, James Loethen < reply@reply.github.com

wrote:

Cases where enemies are attacking the base are not handled yet. Our units have an attack radius only and the initial enemy starting location as an attack target.


Reply to this email directly or view it on GitHub: https://github.com/go2starr/CS-638-BWAPI/issues/45#issuecomment-5553310