Help! How to start my own AI

https://github.com/bwapi/bwapi
Moonlove
Posts: 2
Joined: Wed Mar 14, 2012 3:16 pm

Help! How to start my own AI

Postby Moonlove » Wed Mar 14, 2012 3:23 pm

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.
krasi0
Posts: 254
Joined: Thu Dec 18, 2008 12:42 pm

Postby krasi0 » Thu Mar 15, 2012 7:08 am

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.
User avatar
Taranok
Posts: 256
Joined: Tue Sep 07, 2010 9:41 pm

Postby Taranok » Fri Mar 16, 2012 7:14 am

Just wondering, does BWSAL 0.9.12 work with BWAPI 3.7.2?
Moonlove
Posts: 2
Joined: Wed Mar 14, 2012 3:16 pm

Postby Moonlove » Wed Apr 18, 2012 9:13 am

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...
Heinermann
Posts: 362
Joined: Thu Apr 26, 2007 12:42 am

Postby Heinermann » Sun May 06, 2012 3:16 pm

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.
Willem.Esterhuizen
Posts: 1
Joined: Tue Nov 06, 2012 2:55 pm

Postby Willem.Esterhuizen » Mon Nov 12, 2012 12:30 pm

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!
krasi0
Posts: 254
Joined: Thu Dec 18, 2008 12:42 pm

Postby krasi0 » Tue Nov 13, 2012 9:19 am

you can't. A BWAPI::Position object is immutable. you should always create new position objects with the wanted coordinates
Heinermann
Posts: 362
Joined: Thu Apr 26, 2007 12:42 am

Postby Heinermann » Sat Nov 17, 2012 5:05 am

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.
User avatar
c3lm4ta
Posts: 8
Joined: Tue Dec 04, 2012 7:47 pm

Postby c3lm4ta » Wed Dec 05, 2012 3:18 am


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?
krasi0
Posts: 254
Joined: Thu Dec 18, 2008 12:42 pm

Postby krasi0 » Wed Dec 05, 2012 9:48 am

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?


Return to “BWAPI (wrappers in other languages / questions and announcements related to BWAPI itself)”

Who is online

Users browsing this forum: No registered users and 1 guest