Ejemplo n.º 1
0
void UnitMng::attack()
{
	BWAPI::Unit* enemy=enemyExists(this->conUnit);
	if(enemy)
		this->conUnit->rightClick(enemy);
	else
	{
		enemy=closestEnemy();
		//BWAPI::Broodwar->printf("Unit Cannot attack this unit");
		this->conUnit->rightClick(enemy);
		//this->move();
	}
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
void AI::omniact(int i)
{
  cout << "OMNIVORE FOR " << i << endl;
  //Determine target
  Point2D next;

  //CURRENT LOCATION
  Point2D cur;
  cur.x = myCreatures[i].cre->x();
  cur.y = myCreatures[i].cre->y();

  //CLOSEST PLANT
  Point2D cp;
  Point2D ce;
  Point2D tgt;
  float cpDist;
  float ceDist;

  int attempt = 0;
  cout << "STARTING HERB WHILE LOOP" << endl;
  while(myCreatures[i].cre->movementLeft() > 0 && attempt < 100)
  {
    //UPDATE
    cur.x = myCreatures[i].cre->x();
    cur.y = myCreatures[i].cre->y();
    
    cp = closestPlant( cur.x, cur.y );
    ce = closestEnemy( cur.x, cur.y );
    cpDist = dist( cur.x, cur.y, cp.x, cp.y);
    ceDist = dist( cur.x, cur.y, ce.x, ce.y);
    
    //ATTEMPT TO EAT
    if(ceDist == 1)
    {
      cout<<"ATTEMPTING TO EAT CREATURE"<<endl;
      myCreatures[i].cre->eat(ce.x, ce.y);
      return;
    }
    else if(cpDist == 1)
    {
        cout<<"ATTEMPTING TO EAT CREATURE"<<endl;
        myCreatures[i].cre->eat(cp.x, cp.y);
        return;
    }
    else
    {
      if(ceDist < cpDist + 3)
        tgt = ce;
      else
        tgt = cp;
    }

    //MOVE RIGHT - CURRENT X LESS THAN CLOSEST X
    if( cur.x < tgt.x )
    {
      cout << "HEADING RIGHT" << endl;
      if( !myCreatures[i].cre->move(cur.x + 1, cur.y) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x, cur.y + 1);
        else
          myCreatures[i].cre->move(cur.x, cur.y - 1);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //MOVE LEFT IF NOT OVER LOCATION
    else if( cur.x > tgt.x )
    {
      cout << "HEADING LEFT" << endl;
      if( !myCreatures[i].cre->move(cur.x - 1, cur.y) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x, cur.y + 1);
        else
          myCreatures[i].cre->move(cur.x, cur.y - 1);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //DIRECTLY OVER - MOVE UP/DOWN
    //MOVE UP - CURRENT Y LESS THAN CLOSEST Y
    else if( cur.y > tgt.y )
    {
      cout << "HEADING UP" << endl;
      if( !myCreatures[i].cre->move(cur.x, cur.y - 1) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x + 1, cur.y);
        else
          myCreatures[i].cre->move(cur.x - 1, cur.y);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //MOVE DOWN - CURRENT Y GREATER THAN CLOSEST Y
    else if( cur.y < tgt.y )
    {
      cout << "HEADING DOWN" << endl;
      if( !myCreatures[i].cre->move(cur.x, cur.y + 1) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x + 1, cur.y);
        else
          myCreatures[i].cre->move(cur.x - 1, cur.y);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //DIRECTLY ON TOP OF TARGET
    else
    {
      cout << "LOL WHUT IS GOING ON IDK MAHN" << endl;
      //LOLWHUT
    }
    
    //UPDATE
    cur.x = myCreatures[i].cre->x();
    cur.y = myCreatures[i].cre->y();
    
    cp = closestPlant( cur.x, cur.y );
    ce = closestEnemy( cur.x, cur.y );
    cpDist = dist( cur.x, cur.y, cp.x, cp.y);
    ceDist = dist( cur.x, cur.y, ce.x, ce.y);
    
    //ATTEMPT TO EAT
    if(ceDist == 1)
    {
      cout<<"ATTEMPTING TO EAT CREATURE"<<endl;
      myCreatures[i].cre->eat(ce.x, ce.y);
      return;
    }
    else if(cpDist == 1)
    {
      cout<<"ATTEMPTING TO EAT PLANT"<<endl;
      myCreatures[i].cre->eat(cp.x, cp.y);
      return;
    }
    else
    {
      if(ceDist < cpDist)
        tgt = ce;
      else
        tgt = cp;
    }
  }
  return;
}
Ejemplo n.º 4
0
void AI::carnact(int i)
{
  cout << "CARNIVORE FOR " << i << endl;
  //Determine target
  Point2D next;

  //CURRENT LOCATION
  Point2D cur;
  cur.x = myCreatures[i].cre->x();
  cur.y = myCreatures[i].cre->y();

  //CLOSEST PLANT
  Point2D cp;
  float cpDist;

  int attempt = 0;
  cout << "STARTING HERB WHILE LOOP" << endl;
  while(myCreatures[i].cre->movementLeft() > 0 && attempt < 100)
  {
    //UPDATE
    cur.x = myCreatures[i].cre->x();
    cur.y = myCreatures[i].cre->y();
    cp = closestEnemy( cur.x, cur.y );
    cpDist = dist( cur.x, cur.y, cp.x, cp.y);
    
    cout<<"at "<<cur.x<<','<<cur.y<<" heading to "<<cp.x<<','<<cp.y<<endl;
    
    //ATTEMPT TO EAT
    if(cpDist == 1)
    {
      cout<<"uhhhhh"<<endl;
      myCreatures[i].cre->eat(cp.x, cp.y);
      return;
    }

    //MOVE RIGHT - CURRENT X LESS THAN CLOSEST X
    if( cur.x < cp.x )
    {
      cout << "HEADING RIGHT" << endl;
      if( !myCreatures[i].cre->move(cur.x + 1, cur.y) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x, cur.y + 1);
        else
          myCreatures[i].cre->move(cur.x, cur.y - 1);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //MOVE LEFT IF NOT OVER LOCATION
    else if( cur.x > cp.x )
    {
      cout << "HEADING LEFT" << endl;
      if( !myCreatures[i].cre->move(cur.x - 1, cur.y) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x, cur.y + 1);
        else
          myCreatures[i].cre->move(cur.x, cur.y - 1);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //DIRECTLY OVER - MOVE UP/DOWN
    //MOVE UP - CURRENT Y LESS THAN CLOSEST Y
    else if( cur.y > cp.y )
    {
      cout << "HEADING UP" << endl;
      if( !myCreatures[i].cre->move(cur.x, cur.y - 1) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x + 1, cur.y);
        else
          myCreatures[i].cre->move(cur.x - 1, cur.y);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //MOVE DOWN - CURRENT Y GREATER THAN CLOSEST Y
    else if( cur.y < cp.y )
    {
      cout << "HEADING DOWN" << endl;
      if( !myCreatures[i].cre->move(cur.x, cur.y + 1) )
      {
        if(rand()%2 == 0)
          myCreatures[i].cre->move(cur.x + 1, cur.y);
        else
          myCreatures[i].cre->move(cur.x - 1, cur.y);
        cout << "FAILED MOVEMENT" << endl;
        attempt++;
      }
    }
    //DIRECTLY ON TOP OF TARGET
    else
    {
      cout << "LOL WHUT IS GOING ON IDK MAHN" << endl;
      //LOLWHUT
    }
    //ATTEMPT TO EAT
    cp = closestEnemy( cur.x, cur.y );
    cpDist = dist( cur.x, cur.y, cp.x, cp.y);
    if(cpDist == 1)
    {
      myCreatures[i].cre->eat(cp.x, cp.y);
      return;
    }
  }
  return;
}