Giter Site home page Giter Site logo

starcraftunitinfo's Introduction

StarCraftUnitInfo

A module to store StarCraft Information of units behind the fog-of-war. Many bot developers must spend some time to develop such unit tracking modules, and the idea here is to offer this as a library. For example, UAlbertaBot has this module nicely implemented there, but it is not trivial to extract and use it in your own bot. So this module is basically an extraction of UAlbertaBot's code, regarding unit tracking.

The module stores information (position, HP, shields, etc.) concerning the last time a unit was seen. It also has functions for drawing boxes and unit names on such positions to aid visual inspecting and debugging.

The master branch contains code for BWAPI 4.1.2. If you're looking for information and instructions for the version compatible with BWAPI 3.7.5, please take a look here: https://github.com/andertavares/StarCraftUnitInfo/tree/bwapi3

Preparing the library

  • Download the version you need in Releases. Each release has a library (UnitInfoLib) and an example AI module (UnitInfoExampleAI). For these steps, select the library.
  • Extract the contents inside your AI module. There's an include and a lib directory.
  • Add include directory to your project in both Debug and Release configurations (right click on your AI Module's project -> Properties -> C/C++ -> Additional Include Directories)
  • Add lib/UnitInfo.lib to your project under Release configuration and lib/UnitInfo.lib to your Debug configuration. In either case, the steps are: right click on your AI Module's project -> Properties -> Linker -> Input -> Additional dependencies.
  • Open your AI Module's source file and add #include "UnitInfoManager.h" in your preamble.
  • Add scutil::UnitInfoManager::getInstance(); to your onStart() to initialize the module.
  • Add the callbacks to scutil::UnitInfoManager at the following callbacks of your AI Module: onFrame, onUnitDiscover, onUnitEvade, onUnitShow, onUnitHide, onUnitCreate, onUnitDestroy, onUnitMorph, onUnitRenegade, onUnitComplete. The callbacks are on the form: scutil::UnitInfoManager::getInstance().on*, where you replace the * with the corresponding name, passing the same parameters received by the callback of your AI Module.

Using the library

Data Structures

The structures and classes concerned with unit information are:

  • UnitInfoManager: has the callbacks and the methods to access the other structures
  • UnitData: takes care of consistency of unit data
  • UIMap: maps a BWAPI::Unit to a UnitInfo, which actually stores the information.
  • UnitInfo: allows you to retrieve unitID, lastHealth, lastShields, player, unit, lastPosition, type, completed of a unit you cannot see anymore.

Example of use

To retrieve information of units, please take a look at the following piece of code:

// Example of use of enemy unit information:
UIMap enemyUnitInfo = UnitInfoManager::getInstance().getUnitInfoMapOfPlayer(Broodwar->enemy());

for (auto iterator : enemyUnitInfo) {
	Unit u = iterator.first;
	UnitInfo uInfo = iterator.second;

	Broodwar->printf(
		"%s at (%d, %d)", uInfo.type.c_str(),
		uInfo.lastPosition.x, uInfo.lastPosition.y
	);
	// see UnitData.h for all attributes of UnitInfo struct ;)
}

First, you get the UIMap with units of the enemy, then you traverse it querying data of each unit that has been seen at least once, and is still alive.

Also, in our releases, there is a UnitInfoExampleAI, which is the basic ExampleAIModule of BWAPI, with the project configuration and the code to use the module.

Contact

If you found some error, please open an Issue. For general questions, feel free to contact the author: andersonrochatavares .at. gmail.com

Credits

Most of this code was extracted from UAlbertaBot. Some code and inspiration came from OpprimoBot.

starcraftunitinfo's People

Contributors

andertavares avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

starcraftunitinfo's Issues

Clear or mark position data of unit not seen anymore

We store the position a unit was last seen, if we visit that position again, we don't update that the unit is not there anymore. We should either set that unit's position to an invalid value or add a field to mark the previously stored value as incorrect

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.