Skip to content
Snippets Groups Projects
Commit 0cc5e877 authored by Daniel de Leng's avatar Daniel de Leng
Browse files

Introduce features proposed in old merge request 14

parent d1941511
No related branches found
No related tags found
No related merge requests found
Pipeline #133158 passed
import sys,os
import conf
import commandcenter
\ No newline at end of file
......@@ -22,6 +22,7 @@ void define_map_tools(py::module & m)
.def_property_readonly("height", &MapTools::height, "The height of the map.")
.def_property_readonly("map_name", &MapTools::name, "The name of the map.")
//.def("terrainHeight", &MapTools::terrainHeight, py::const_)
.def("terrainHeight", &MapTools::terrainHeightFromCoord, "x"_a, "y"_a)
.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, "Draws a line with the given color between to two points.")
.def("draw_tile", py::overload_cast<const CCTilePosition &, const CCColor &>(&MapTools::drawTile, py::const_), py::arg("tile"), py::arg("color") = sc2::Colors::White, "Draws an outline with the given color to the given tile.")
.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, "Draws a box with the given color from the top left corner to the botom right.")
......
......@@ -130,6 +130,7 @@ PYBIND11_MODULE(commandcenter, m)
.def("on_step", &IDABot::OnStep, R"(The on_step function in the IDABot class is a method that is called every game step (or frame) during a Starcraft II match.
This function is crucial for implementing the bot's logic that needs to be executed continuously throughout the game.
It's where the bot evaluates the current game state, makes decisions, and issues commands to units.)")
.def("on_game_end", &IDABot::OnGameEnd)
.def("send_chat", &IDABot::SendChat, "Sends the string 'message' to the game chat.", "message"_a)
.def("get_all_units", &IDABot::GetAllUnits, "Returns a list of all visible units, including minerals and geysers.")
.def("get_my_units", &IDABot::GetMyUnits, "Returns a list of all your units.")
......@@ -160,6 +161,7 @@ PYBIND11_MODULE(commandcenter, m)
.def("upgrade_gas_cost", &IDABot::UpgradeGasCost, "Vespene/gas cost of researching the upgrade.", "upgrade"_a)
.def("upgrade_research_time", &IDABot::UpgradeResearchTime, "Time in GameLoops to research this upgrade.", "upgrade"_a)
.def("effect_radius", &IDABot::RadiusEffect, "Size of the circle the effect impacts.", "effect"_a)
.def("save_replay", &IDABot::SaveReplay, "Saves the game as a replay", "path"_a)
.def_property_readonly("base_location_manager", &IDABot::Bases, "An instance of the class :class:`commandcenter.BaseLocationManager`. ")
.def_property_readonly("tech_tree", &IDABot::GetTechTree, "An instance of the class :class:`commandcenter.TechTree`.")
.def_property_readonly("map_tools", &IDABot::Map, "An instance of the class :class:`commandcenter.MapTools`.")
......@@ -171,6 +173,9 @@ PYBIND11_MODULE(commandcenter, m)
.def_property_readonly("max_supply", &IDABot::GetMaxSupply, "How much supply we can currently use.")
.def_property_readonly("gas", &IDABot::GetGas, "How much gas we currently have.")
.def_property_readonly("current_frame", &IDABot::GetCurrentFrame, "Which frame we are currently on.")
.def_property_readonly("score", &IDABot::GetScore, "The current score.")
.def_property_readonly("player_result", &IDABot::GetPlayerResults, "The match result for the player.")
.doc() = R"(This is a stripped-down version of a bot. It contains all available managers and basic methods.)";
......
......@@ -60,6 +60,15 @@ public:
OnStep
);
}
void OnGameEnd() override
{
PYBIND11_OVERLOAD_NAME(
void,
IDABot,
"on_game_end",
OnGameEnd
);
}
};
......
#include "IDABot.h"
#include "Util.h"
#include "sc2api/sc2_score.h"
IDABot::IDABot()
......@@ -158,6 +159,10 @@ int IDABot::GetGas() const
Unit IDABot::GetUnit(const CCUnitID & tag) const
{
if (Observation()->GetUnit(tag) == nullptr) {
return Unit();
}
return Unit(Observation()->GetUnit(tag), *(IDABot *)this);
}
......@@ -384,3 +389,24 @@ float IDABot::RadiusEffect(sc2::EffectID effect_id) const
{
return Observation()->GetEffectData()[effect_id].radius;
}
float IDABot::GetScore() const
{
return Observation()->GetScore().score;
}
const sc2::GameResult IDABot::GetPlayerResults() const
{
auto res = Observation()->GetResults();
for(int i = 0; i < res.size(); i++)
{
if (res.at(i).player_id == Observation()->GetPlayerID()) return res.at(i).result;
}
std::cout << "The player can not be found" << std::endl;
return sc2::GameResult::Undecided;
}
bool IDABot::SaveReplay(const std::string& path)
{
return this->Control()->SaveReplay(path);
}
\ No newline at end of file
......@@ -93,6 +93,11 @@ public:
float UpgradeResearchTime(sc2::UpgradeID upgrade_id) const;
float RadiusEffect(sc2::EffectID effect_id) const;
float GetScore() const;
const sc2::GameResult GetPlayerResults() const;
bool SaveReplay(const std::string & path);
// Not needed, just convenience functions
......
......@@ -280,7 +280,7 @@ bool MapTools::isPowered(int tileX, int tileY) const
#endif
}
float MapTools::terrainHeight(float x, float y) const
float MapTools::terrainHeightFromCoord(float x, float y) const
{
return m_terrainHeight[(int)x][(int)y];
}
......
......@@ -47,7 +47,7 @@ public:
int width() const;
int height() const;
std::string name() const;
float terrainHeight(float x, float y) const;
float terrainHeightFromCoord(float x, float y) const;
void drawLine(CCPositionType x1, CCPositionType y1, CCPositionType x2, CCPositionType y2, const CCColor & color = CCColor(255, 255, 255)) const;
void drawLine(const CCPosition & p1, const CCPosition & p2, const CCColor & color = CCColor(255, 255, 255)) const;
......
#include "Unit.h"
#include "IDABot.h"
#include "sc2api/sc2_gametypes.h"
Unit::Unit()
: m_bot(nullptr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment