diff --git a/3rd_party/opennn b/3rd_party/opennn index 3cc0682c4..3dd1573b9 160000 --- a/3rd_party/opennn +++ b/3rd_party/opennn @@ -1 +1 @@ -Subproject commit 3cc0682c41e399aab4a06ba8499797a611419ef6 +Subproject commit 3dd1573b99879a6ce4112d0353f6b21d855be001 diff --git a/ai/heavyai/situationevaluator.cpp b/ai/heavyai/situationevaluator.cpp index c162728e8..fcbafe808 100644 --- a/ai/heavyai/situationevaluator.cpp +++ b/ai/heavyai/situationevaluator.cpp @@ -1,34 +1,61 @@ -#include "ai/heavyai/situationevaluator.h" - -#include "coreengine/globalutils.h" -#include "game/gamemap.h" - -SituationEvaluator::SituationEvaluator() - : m_inputVector(1, UNIT_COUNT * UNIT_COUNT * static_cast(Features::Max)), - m_searchRange(GlobalUtils::getSpCircle(0, SEARCH_RANGE)) -{ -} - -void SituationEvaluator::updateInputVector(GameMap* pMap, const QPoint & searchPoint) -{ - std::vector units; - getUnitsInRange(units, pMap, searchPoint); - -} - -void SituationEvaluator::getUnitsInRange(std::vector & units, GameMap* pMap, const QPoint & searchPoint) -{ - for (const auto & point : m_searchRange->getVector()) - { - QPoint mapPoint = point + searchPoint; - Terrain* pTerrain = pMap->getTerrain(mapPoint); - if (pTerrain != nullptr) - { - Unit* pUnit = pTerrain->getUnit(); - if (pUnit != nullptr) - { - units.push_back(pUnit); - } - } - } -} +#include "ai/heavyai/situationevaluator.h" + +#include "coreengine/globalutils.h" +#include "game/gamemap.h" + +SituationEvaluator::SituationEvaluator(Player* pOwner) + : m_inputVector(1, UNIT_COUNT * UNIT_COUNT * static_cast(Features::Max)), + m_searchRange(GlobalUtils::getSpCircle(0, SEARCH_RANGE)), + m_pOwner(pOwner) +{ +} + +void SituationEvaluator::updateInputVector(GameMap* pMap, const QPoint & searchPoint) +{ + std::array units({nullptr}); + getUnitsInRange(units, pMap, searchPoint); + for (qint32 i = 0; i < UNIT_COUNT; ++i) + { + Unit* pUnit = units[i]; + if (pUnit == nullptr) + { + + } + else + { + + } + } +} + +void SituationEvaluator::getUnitsInRange(std::array & units, GameMap* pMap, const QPoint & searchPoint) +{ + qint32 alliedPosition = 0; + qint32 enemyPosition = UNIT_COUNT - 1; + for (const auto & point : m_searchRange->getVector()) + { + QPoint mapPoint = point + searchPoint; + Terrain* pTerrain = pMap->getTerrain(mapPoint); + if (pTerrain != nullptr) + { + Unit* pUnit = pTerrain->getUnit(); + if (pUnit != nullptr) + { + if (m_pOwner->isEnemyUnit(pUnit)) + { + units[enemyPosition] = pUnit; + --enemyPosition; + } + else + { + units[alliedPosition] = pUnit; + ++alliedPosition; + } + if (alliedPosition > enemyPosition) + { + break; + } + } + } + } +} diff --git a/ai/heavyai/situationevaluator.h b/ai/heavyai/situationevaluator.h index fae213971..f4379a46a 100644 --- a/ai/heavyai/situationevaluator.h +++ b/ai/heavyai/situationevaluator.h @@ -1,43 +1,45 @@ -#pragma once - -#include - -#include "3rd_party/opennn/opennn/opennn.h" - -class Unit; -class GameMap; -class QmlVectorPoint; -using spQmlVectorPoint = std::shared_ptr; - -class SituationEvaluator : public QObject -{ - Q_OBJECT -public: - static constexpr qint32 UNIT_COUNT = 40; - static constexpr qint32 SEARCH_RANGE = 30; - enum class Features - { - HP, - HpDamage, - FundsDamage, - MovementPoints, - Distance, - HasMoved, - Defense, - RepairsOnPosition, - Max, - }; - - - explicit SituationEvaluator(); - - void updateInputVector(GameMap* pMap, const QPoint & searchPoint); - -private: - void getUnitsInRange(std::vector & units, GameMap* pMap, const QPoint & searchPoint); - -private: - opennn::Tensor m_inputVector; - spQmlVectorPoint m_searchRange; -}; - +#pragma once + +#include + +#include "3rd_party/opennn/opennn/opennn.h" + +class Player; +class Unit; +class GameMap; +class QmlVectorPoint; +using spQmlVectorPoint = std::shared_ptr; + +class SituationEvaluator : public QObject +{ + Q_OBJECT +public: + static constexpr qint32 UNIT_COUNT = 40; + static constexpr qint32 SEARCH_RANGE = 30; + enum class Features + { + HP, + HpDamage, + FundsDamage, + MovementPoints, + Distance, + HasMoved, + Defense, + RepairsOnPosition, + Max, + }; + + + explicit SituationEvaluator(Player* pOwner); + + void updateInputVector(GameMap* pMap, const QPoint & searchPoint); + +private: + void getUnitsInRange(std::array & units, GameMap* pMap, const QPoint & searchPoint); + +private: + opennn::Tensor m_inputVector; + spQmlVectorPoint m_searchRange; + Player* m_pOwner{nullptr}; +}; + diff --git a/coreengine/globalutils.cpp b/coreengine/globalutils.cpp index 24e7140f6..a01291b5e 100644 --- a/coreengine/globalutils.cpp +++ b/coreengine/globalutils.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include "coreengine/qmlvector.h" #include "coreengine/globalutils.h" #include "coreengine/gameconsole.h" @@ -537,32 +539,32 @@ QVector GlobalUtils::calcWidths(const QVector & maxWidths, const float GlobalUtils::roundFloor(float value, float precision) { - return qFloor(value * precision) / precision; + return std::floor(value * precision) / precision; } double GlobalUtils::roundFloor(double value, double precision) { - return qFloor(value * precision) / precision; + return std::floor(value * precision) / precision; } float GlobalUtils::roundCeil(float value, float precision) { - return qCeil(value * precision) / precision; + return std::ceil(value * precision) / precision; } double GlobalUtils::roundCeil(double value, double precision) { - return qCeil(value * precision) / precision; + return std::ceil(value * precision) / precision; } qint32 GlobalUtils::roundFloorToInt(float value, float precision) { - return qFloor(value * precision); + return std::floor(value * precision); } qint32 GlobalUtils::roundFloorToInt(qreal value, qreal precision) { - return qFloor(value * precision); + return std::floor(value * precision); } QByteArray GlobalUtils::toByteArray(const QJsonArray & jsonArray) diff --git a/game/gameanimation/gameanimationcapture.cpp b/game/gameanimation/gameanimationcapture.cpp index 4b12c9a11..6ae2a3c35 100644 --- a/game/gameanimation/gameanimationcapture.cpp +++ b/game/gameanimation/gameanimationcapture.cpp @@ -202,8 +202,8 @@ void GameAnimationCapture::addSoldierSprite(const QString spriteID, Player* pPl const float startPercentDone = (static_cast(m_startPoints) / static_cast(m_maxPoints)); constexpr qint32 unitOffset = 6; float buildingHigh = m_BuildingEndPos - m_BuildingStartPos; - float startPosition = unitOffsetY + qCeil(unitOffset * (1.0f - startPercentDone)) + qCeil(startPercentDone * buildingHigh); - float endPosition = unitOffsetY + qCeil(unitOffset * ( 1.0f - percentDone)) + qCeil(percentDone * buildingHigh); + float startPosition = unitOffsetY + std::ceil(unitOffset * (1.0f - startPercentDone)) + std::ceil(startPercentDone * buildingHigh); + float endPosition = unitOffsetY + std::ceil(unitOffset * ( 1.0f - percentDone)) + std::ceil(percentDone * buildingHigh); oxygine::spSprite pSprite = MemoryManagement::create(); if (pAnim->getTotalFrames() > 1)