Skip to content
Snippets Groups Projects
Commit 9109a1f8 authored by Hannes Jämtner's avatar Hannes Jämtner
Browse files

Updated docs, not done yet. Fixed rendering sphere on resources

parent 3e2de875
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,13 @@ Difficulty
:members:
:undoc-members:
AIBuild
-------
.. autoclass:: library.AIBuild
:members:
:undoc-members:
Race
----
......
......@@ -127,6 +127,14 @@ However, your bot might will probably be able to play the game faster. If you
remove or comment out this line the game will run as fast as possible, only
waiting for your bot to return from `on_step`.
If you want to train your agent on certain type of bots. For example, If we
want the opponent to focus on air strategy. You can add the
following line to the bot.
.. code-block:: python
participant_2 = create_computer(Race.Random, Difficulty.Easy, AIBuild.Air)
We can also play two bots against each other by changing the row:
.. code-block:: python
......
......@@ -59,9 +59,13 @@ IDABot
Sends the string 'message' to the game chat
.. method:: IDABot.carry_vespene(self, unit) -> Boolean
"Returns true if unit carries a vespene"
.. method:: IDABot.has_creep(self, Point2D) -> Boolean
Returns if the position has a creep.
.. method:: IDABot.move_camera(self, Point2DI)
Move the camera to the position.
Attributes:
......@@ -74,3 +78,88 @@ IDABot
.. autoattribute:: max_supply
.. autoattribute:: current_frame
Debug
-----
When developing AI-methods or when simply having a problem.
The debug-methods are a great tool for speeding up the process.
.. method:: IDABot.debug_create_unit(self, UnitTypeID, Point2D, Player Constant, Int)
This method creates the nr (INT) of units on the position of the Point2D, the unit
belongs to the Player Constant.
.. method:: IDABot.debug_kill_unit(self, Unit)
Kills the unit.
.. method:: IDABot.debug_show_map(self)
Make the entire map visible.
.. method:: IDABot.debug_fast_build(self)
Set the build time in game to 1.
.. method:: IDABot.debug_enemy_control(self)
Gives the player full control over the enemy.
.. method:: IDABot.debug_fast_build(self)
Set the build time in game to 1.
.. method:: IDABot.debug_ignore_food(self)
Ignore food in game.
.. method:: IDABot.debug_ignore_resource_cost(self)
Ignore the resource cost in game. Everything cost 0 resources.
.. method:: IDABot.debug_give_all_resources(self)
Set the mineral and vespene gas to 5000.
.. method:: IDABot.debug_god_mode(self)
Give yourself god mode in the game.
.. method:: IDABot.debug_ignore_mineral(self)
Ignore the mineral cost in the game.
.. method:: IDABot.debug_no_cooldowns(self)
Deactivate cooldowns (Basically setting them to 0).
.. method:: IDABot.debug_give_all_tech(self)
Give yourself all tech.
.. method:: IDABot.debug_give_all_upgrades(self)
Give yourself all upgrades.
.. method:: IDABot.debug_set_score(self, Float)
Set the player score in game.
.. method:: IDABot.debug_end_game(self, Boolean)
End the game, if the Boolean is True then victory.
If False, defeat.
.. method:: IDABot.debug_set_energy(self, Float, Unit)
Set the amount (Float) of energy to the unit.
.. method:: IDABot.debug_set_life(self, Float, Unit)
Set the amount (Float) of life to the unit.
.. method:: IDABot.debug_set_shields(self, Float, Unit)
Set the amount (Float) of shield to the unit.
......@@ -77,7 +77,7 @@ Unit
Returns if this unit is currently holding minerals
.. autoattribute:: is_carrying_minerals
.. autoattribute:: is_carrying_gas
Returns if this unit is currently holding gas
......@@ -85,6 +85,19 @@ Unit
Returns target if unit has one, otherwise will fail the assertion (make sure not to call this unless certain that the unit has a target!).
.. autoattribute:: gas_left_in_refinery
This is used on the geyser.
Returns the amount of gas left in refinery.
.. autoattribute:: minerals_left_in_mineralfield
Returns the amount of minerals left in mineralfield.
.. autoattribute:: owner
Returns the Player ID, the owner of the unit.
Methods:
.. automethod:: ability
......
......@@ -20,6 +20,7 @@ void define_map_tools(py::module & m)
.def("draw_line", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawLine, py::const_), py::arg("start"), py::arg("stop"), py::arg("color") = sc2::Colors::White)
.def("draw_box", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawBox, py::const_), py::arg("top_left"), py::arg("bottom_right"), py::arg("color") = sc2::Colors::White)
.def("draw_circle", py::overload_cast<const CCPosition &, CCPositionType, const CCColor &>(&MapTools::drawCircle, py::const_), py::arg("center"), py::arg("radius"), py::arg("color") = sc2::Colors::White)
.def("draw_resource_circle", &MapTools::drawResourceCircle, py::arg("center"), py::arg("radius"), py::arg("color") = sc2::Colors::White)
.def("draw_text", &MapTools::drawText, "position"_a, "text"_a, "color"_a = sc2::Colors::White)
.def("draw_text_screen", &MapTools::drawTextScreen, "percentage_x"_a, "percentage_y"_a, "text"_a, "color"_a = sc2::Colors::White)
.def("is_valid_tile", py::overload_cast<int, int>(&MapTools::isValidTile, py::const_), "x"_a, "y"_a)
......
......@@ -95,7 +95,7 @@ PYBIND11_MODULE(library, m)
.def("debug_end_game", &IDABot::DebugEndGame, "End the game through debug mode")
.def("debug_set_energy", &IDABot::DebugSetEnergy, "Set the energy on a unit through debug mode")
.def("debug_set_life", &IDABot::DebugSetLife, "Set the life on a unit through debug mode")
.def("debug_set_shield", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode")
.def("debug_set_shields", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode")
.def("get_enemy_base_location", &IDABot::GetEnemyBaseLocations, "Return the CCpostion of the enemy base")
.def("move_camera", &IDABot::CameraMove, "Move the camera to p postion", "p"_a)
.def("has_creep", &IDABot::HasCreep, "Returns true if there is creep at position p", "p"_a)
......@@ -132,7 +132,8 @@ PYBIND11_MODULE(library, m)
.value("Rush", sc2::AIBuild::Rush)
.value("Timing", sc2::AIBuild::Timing)
.value("Power", sc2::AIBuild::Power)
.value("Macro", sc2::AIBuild::Air);
.value("Macro", sc2::AIBuild::Macro)
.value("Air", sc2::AIBuild::Air);
m.def("create_participants", &sc2::CreateParticipant, "Create participant from bot", "race"_a, "bot"_a, "player_name"_a = "");
......
......@@ -202,7 +202,9 @@ void BaseLocation::draw()
{
CCPositionType radius = Util::TileToPosition(1.0f);
m_bot.Map().drawCircle(m_centerOfResources, radius, CCColor(255, 255, 0));
// Take first mineral for the Z-pos.
sc2::Point3D center_pos = sc2::Point3D(m_centerOfResources.x, m_centerOfResources.y, m_minerals[0].getUnitPtr()->pos.z);
m_bot.Map().drawResourceCircle(center_pos, radius, CCColor(255, 255, 0));
std::stringstream ss;
ss << "BaseLocation: " << m_baseID << "\n";
......@@ -237,14 +239,14 @@ void BaseLocation::draw()
//m_bot.Map().drawLine(m_left, y, m_right, y, CCColor(160, 160, 160));
}
for (auto & mineralPos : m_mineralPositions)
for (auto & mineral : m_minerals)
{
m_bot.Map().drawCircle(mineralPos, radius, CCColor(0, 128, 128));
m_bot.Map().drawResourceCircle(mineral.getUnitPtr()->pos, radius, CCColor(0, 128, 128));
}
for (auto & geyserPos : m_geyserPositions)
for (auto & geyser : m_geysers)
{
m_bot.Map().drawCircle(geyserPos, radius, CCColor(0, 255, 0));
m_bot.Map().drawResourceCircle(geyser.getUnitPtr()->pos, radius, CCColor(0, 255, 0));
}
if (m_isStartLocation)
......
......@@ -269,7 +269,7 @@ void BaseLocationManager::drawBaseLocations()
const BaseLocation * next_expansion = getNextExpansion(Players::Self);
CCTilePosition nextExpansionPosition = next_expansion->getDepotPosition();
m_bot.Map().drawCircle(Util::GetPosition(nextExpansionPosition), 1, CCColor(255, 0, 255));
m_bot.Map().drawResourceCircle(sc2::Point3D(Util::GetPosition(nextExpansionPosition).x, Util::GetPosition(nextExpansionPosition).y, next_expansion->getMinerals()[0].getUnitPtr()->pos.z), 1, CCColor(255, 0, 255));
m_bot.Map().drawText(Util::GetPosition(nextExpansionPosition), "Next Expansion Location", CCColor(255, 0, 255));
}
......
......@@ -322,6 +322,8 @@ void IDABot::DebugSetShields(float value, const Unit unit)
// There is a bug in the latest SC2
// This a function to get the enemy base instead of using build location manager
// Switched over to other API where this is solved
// Leaving function incase of it breaking
const std::vector<Point2D> IDABot::GetEnemyBaseLocations()
{
return Observation()->GetGameInfo().enemy_start_locations;
......
......@@ -401,6 +401,15 @@ void MapTools::drawCircle(const CCPosition & pos, CCPositionType radius, const C
#endif
}
void MapTools::drawResourceCircle(const sc2::Point3D & pos, CCPositionType radius, const CCColor & color) const
{
#ifdef SC2API
m_bot.Debug()->DebugSphereOut(pos, radius, color);
#else
BWAPI::Broodwar->drawCircleMap(pos, radius, color);
#endif
}
void MapTools::drawCircle(CCPositionType x, CCPositionType y, CCPositionType radius, const CCColor & color) const
{
#ifdef SC2API
......
......@@ -54,6 +54,7 @@ public:
void drawBox(const CCPosition & tl, const CCPosition & br, const CCColor & color = CCColor(255, 255, 255)) const;
void drawCircle(CCPositionType x1, CCPositionType x2, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const;
void drawCircle(const CCPosition & pos, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const;
void drawResourceCircle(const sc2::Point3D & pos, CCPositionType radius, const CCColor & color = CCColor(255, 255, 255)) const;
void drawText(const CCPosition & pos, const std::string & str, const CCColor & color = CCColor(255, 255, 255)) const;
void drawTextScreen(float xPerc, float yPerc, const std::string & str, const CCColor & color = CCColor(255, 255, 255)) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment