Page 1 of 1

Help! How to start my own AI

Posted: Wed Mar 14, 2012 3:23 pm
by Moonlove
I am a freshman to BWAPI. Now, I want to start to develop my own AI, but I found I can't "see" anything.
For example, I want to build a Barrack besides my Command Center, but I can't see the map, so how I code this command?
Does someone can told me something elementary things or good tutorial about BWAPI? I think I got lost.
Thanks.

Posted: Thu Mar 15, 2012 7:08 am
by krasi0
Hi,
the best "tutorial" is other people's source code. For example you can look at BWSAL for implementation ideas:
http://code.google.com/p/bwsal/source/b ... nk%2FBWSAL
The bot can't "see" the map. It finds suitable build locations by trial and error - the so called building placement.
I am a freshman to BWAPI. Now, I want to start to develop my own AI, but I found I can't "see" anything.
For example, I want to build a Barrack besides my Command Center, but I can't see the map, so how I code this command?
Does someone can told me something elementary things or good tutorial about BWAPI? I think I got lost.
Thanks.

Posted: Fri Mar 16, 2012 7:14 am
by Taranok
Just wondering, does BWSAL 0.9.12 work with BWAPI 3.7.2?

Posted: Wed Apr 18, 2012 9:13 am
by Moonlove
Thanks for your replied. I'm sorry I can't enter recently and reply it so late.
I will see the example and try to solve my problem. Like another Senior, BWSAL is still compatible with BWAPI 3.7.2 or not? I worry this very much...

Posted: Sun May 06, 2012 3:16 pm
by Heinermann
Finding a build location seems to be one of the biggest problems/challenges in BWAPI.
Though if you want to build a barracks next to your command center, try the following:

Code: Select all

using namespace BWAPI;
Unit *pCommandCenter; // assuming you have a pointer to the command center
Unit *pBuilder; // assuming you have a pointer to the SCV to construct


SOLUTION 1 (build to the right of the command center):

Code: Select all

TilePosition buildPosition( Position(pCommandCenter->getRight(), pCommandCenter->getTop()) );
pBuilder->build(buildPosition, UnitTypes::Terran_Barracks);


SOLUTION 2 (build on either side of the command center):

Code: Select all

TilePosition buildPosition(pCommandCenter->getTilePosition);
TilePosition shiftPosition(4,0);
if ( !pBuilder->build(buildPosition + shiftPosition, UnitTypes::Terran_Barracks) ) // if can't build on the right
  pBuilder->build(buildPosition - shiftPosition, UnitTypes::Terran_Barracks); // then build on the left


Note in BWAPI4 the parameters for Unit::build have been swapped so you would pass the UnitType as the first parameter in the new version. But build locations will be added in BWAPI4 and released before the end of the month, making such tasks easier.

Posted: Mon Nov 12, 2012 12:30 pm
by Willem.Esterhuizen
Hi, I'm new to coding AI for Broodwars, and my next goal is to just get a supply depot built next to the command centre once 100 minerals have been harvested. I'm using the "ExampleAIModule.cpp" source file.

My main problem is that looking at the header files, the Position and TilePosition classes don't have any means of changing their x and y values. (Or rather, maybe I just don't know some c++ tricks to doing this?) What I mean is: for example, I can't go:

TilePosition buildPosition();
buildPosition = (8,8);
buildPosition.setPosition((8,8));

Also, I don't know how to get a pointer to point to an address pointed to by an iterator. These are two things I think will be quite useful to sort out. My precise code is:

Code: Select all

void ExampleAIModule::onFrame()
{
...
Player* AIPlayer = Broodwar->self();
TilePosition buildablePosition();
TilePosition shiftPosition(8,8);
Unit* pBuilder();
  if(AIPlayer->minerals() >= 100)
  {
     for(std::set<Unit*>::const_iterator i=Broodwar->self()->getUnits().begin();i!=Broodwar->self()->getUnits().end();i++)//Loop through all AI's units
     {
        if ((*i)->getType().isWorker())
        {
           pBuilder = &i; // This doesn't work.... How should I go about pointing to the iterator adres?
        }
        if((*i)->getType() == UnitTypes::Terran_Command_Center)
        {
           TilePosition comCenTilePosition = (*i)->getTilePosition(); //get Command Centre Position
           buildablePosition = comCenTilePosition + shiftPosition;
        }

     }//for
          pBuilder->build(buildablePosition , UnitTypes::Terran_Supply_Depot);
}// if(min>100)

Any help will be appreciated. Thanks!

Posted: Tue Nov 13, 2012 9:19 am
by krasi0
you can't. A BWAPI::Position object is immutable. you should always create new position objects with the wanted coordinates

Posted: Sat Nov 17, 2012 5:05 am
by Heinermann
In BWAPI3 you can do

Code: Select all

TilePosition myPosition(8,8);
myPosition += TilePosition(4,0);
myPosition = TilePosition(5,5);


In BWAPI4 you can simply modify the x or y members of a Position type.

Posted: Wed Dec 05, 2012 3:18 am
by c3lm4ta

In BWAPI3 you can do

Code: Select all

TilePosition myPosition(8,8);
myPosition += TilePosition(4,0);
myPosition = TilePosition(5,5);

In BWAPI4 you can simply modify the x or y members of a Position type.



Just curious, and I don't mean to throw the thread off topic - but what was the motivation for changing the pos type to be mutable?

Posted: Wed Dec 05, 2012 9:48 am
by krasi0
Is it? Maybe it just returns a new object...?

In BWAPI3 you can do

Code: Select all

TilePosition myPosition(8,8);
myPosition += TilePosition(4,0);
myPosition = TilePosition(5,5);

In BWAPI4 you can simply modify the x or y members of a Position type.


Just curious, and I don't mean to throw the thread off topic - but what was the motivation for changing the pos type to be mutable?