Added custom move behaviour to creeps
This commit is contained in:
33
douwco_hivemind/include/Tools/JsonTool.hpp
Normal file
33
douwco_hivemind/include/Tools/JsonTool.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef DOUWCO_HIVEMIND_JSON_TOOLS_HPP
|
||||
#define DOUWCO_HIVEMIND_JSON_TOOLS_HPP
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace DouwcoHivemind
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> jsonToVector(const nlohmann::json &json)
|
||||
{
|
||||
std::vector<T> vector;
|
||||
for (const auto &item : json)
|
||||
{
|
||||
vector.emplace_back(item.get<T>());
|
||||
}
|
||||
return vector;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
nlohmann::json vectorToJson(const std::vector<T> &vector)
|
||||
{
|
||||
nlohmann::json json;
|
||||
for (const auto &item : vector)
|
||||
{
|
||||
json.emplace_back(item);
|
||||
}
|
||||
return json;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // DOUWCO_HIVEMIND_JSON_TOOLS_HPP
|
||||
35
douwco_hivemind/include/Tools/PathTool.hpp
Normal file
35
douwco_hivemind/include/Tools/PathTool.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef DOUWCO_HIVEMIND_PATH_TOOL_HPP
|
||||
#define DOUWCO_HIVEMIND_PATH_TOOL_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <Screeps/ReturnTypes.hpp>
|
||||
|
||||
namespace DouwcoHivemind
|
||||
{
|
||||
|
||||
static std::vector<int> flattenPathSteps(const std::vector<Screeps::PathStep> &pathSteps)
|
||||
{
|
||||
std::vector<int> flattened;
|
||||
for (const auto &step : pathSteps)
|
||||
{
|
||||
flattened.push_back(step.x);
|
||||
flattened.push_back(step.y);
|
||||
flattened.push_back(step.dx);
|
||||
flattened.push_back(step.dy);
|
||||
flattened.push_back(step.direction);
|
||||
}
|
||||
return flattened;
|
||||
}
|
||||
|
||||
static std::vector<Screeps::PathStep> unflattenPathSteps(const std::vector<int> &flattened)
|
||||
{
|
||||
std::vector<Screeps::PathStep> pathSteps;
|
||||
for (size_t i = 0; i < flattened.size(); i += 5)
|
||||
{
|
||||
pathSteps.emplace_back(Screeps::PathStep(flattened[i], flattened[i + 1], flattened[i + 2], flattened[i + 3], flattened[i + 4]));
|
||||
}
|
||||
return pathSteps;
|
||||
}
|
||||
} // namespace Screeps
|
||||
|
||||
#endif // DOUWCO_HIVEMIND_PATH_TOOL_HPP
|
||||
Reference in New Issue
Block a user