From 0a28628457109777c193bf3a03104c18ed3531bb Mon Sep 17 00:00:00 2001 From: Robosturm Date: Wed, 11 Oct 2023 16:30:25 +0200 Subject: [PATCH] #1701 --- ai/heavyai/situationevaluator.cpp | 48 ++++++++++++++++++++++++++----- ai/heavyai/situationevaluator.h | 9 +++++- game/ui/playerinfo.cpp | 5 +++- menue/editormenue.cpp | 8 +++++- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/ai/heavyai/situationevaluator.cpp b/ai/heavyai/situationevaluator.cpp index fcbafe808..d44f6d103 100644 --- a/ai/heavyai/situationevaluator.cpp +++ b/ai/heavyai/situationevaluator.cpp @@ -3,6 +3,8 @@ #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)), @@ -12,23 +14,48 @@ SituationEvaluator::SituationEvaluator(Player* pOwner) void SituationEvaluator::updateInputVector(GameMap* pMap, const QPoint & searchPoint) { - std::array units({nullptr}); - getUnitsInRange(units, pMap, searchPoint); + getUnitsInRange(pMap, searchPoint); for (qint32 i = 0; i < UNIT_COUNT; ++i) { - Unit* pUnit = units[i]; + Unit* pUnit = m_unitsInfo[i].pUnit; if (pUnit == nullptr) { - + for (qint32 feature = 0; feature < static_cast(Features::Max); ++feature) + { + qint32 basePosition = UNIT_COUNT * UNIT_COUNT * feature + i * UNIT_COUNT; + for (qint32 enemyUnit = 0; enemyUnit < UNIT_COUNT; ++enemyUnit) + { + m_inputVector(0, basePosition + enemyUnit) = 0; + } + } } else { + for (qint32 feature = 0; feature < static_cast(Features::Max); ++feature) + { + qint32 basePosition = UNIT_COUNT * UNIT_COUNT * feature + i * UNIT_COUNT; + } } } } -void SituationEvaluator::getUnitsInRange(std::array & units, GameMap* pMap, const QPoint & searchPoint) +//void SituationEvaluator::updateHp(qint32 basePosition, const UnitInfo & unitInfo) +//{ +// for (qint32 enemyUnit = 0; enemyUnit < UNIT_COUNT; ++enemyUnit) +// { +// if (unitInfo.multiplier != m_unitsInfo[enemyUnit].multiplier) +// { +// m_inputVector(0, basePosition + enemyUnit) = m_unitsInfo[enemyUnit].pUnit->getHpRounded(); +// } +// else +// { +// m_inputVector(0, basePosition + enemyUnit) = 0; +// } +// } +//} + +void SituationEvaluator::getUnitsInRange(GameMap* pMap, const QPoint & searchPoint) { qint32 alliedPosition = 0; qint32 enemyPosition = UNIT_COUNT - 1; @@ -43,12 +70,14 @@ void SituationEvaluator::getUnitsInRange(std::array & units, { if (m_pOwner->isEnemyUnit(pUnit)) { - units[enemyPosition] = pUnit; + m_unitsInfo[enemyPosition].pUnit = pUnit; + m_unitsInfo[enemyPosition].multiplier = -1; --enemyPosition; } else { - units[alliedPosition] = pUnit; + m_unitsInfo[alliedPosition].pUnit = pUnit; + m_unitsInfo[alliedPosition].multiplier = 1; ++alliedPosition; } if (alliedPosition > enemyPosition) @@ -58,4 +87,9 @@ void SituationEvaluator::getUnitsInRange(std::array & units, } } } + for (qint32 i = alliedPosition; i <= enemyPosition; ++i) + { + m_unitsInfo[enemyPosition].pUnit = nullptr; + m_unitsInfo[enemyPosition].multiplier = 1; + } } diff --git a/ai/heavyai/situationevaluator.h b/ai/heavyai/situationevaluator.h index f4379a46a..81863e152 100644 --- a/ai/heavyai/situationevaluator.h +++ b/ai/heavyai/situationevaluator.h @@ -14,6 +14,12 @@ class SituationEvaluator : public QObject { Q_OBJECT public: + struct UnitInfo + { + Unit* pUnit{nullptr}; + qint32 multiplier{0}; + }; + static constexpr qint32 UNIT_COUNT = 40; static constexpr qint32 SEARCH_RANGE = 30; enum class Features @@ -35,10 +41,11 @@ class SituationEvaluator : public QObject void updateInputVector(GameMap* pMap, const QPoint & searchPoint); private: - void getUnitsInRange(std::array & units, GameMap* pMap, const QPoint & searchPoint); + void getUnitsInRange(GameMap* pMap, const QPoint & searchPoint); private: opennn::Tensor m_inputVector; + std::array m_unitsInfo; spQmlVectorPoint m_searchRange; Player* m_pOwner{nullptr}; }; diff --git a/game/ui/playerinfo.cpp b/game/ui/playerinfo.cpp index d184ad26d..a4b0a6bf1 100644 --- a/game/ui/playerinfo.cpp +++ b/game/ui/playerinfo.cpp @@ -103,7 +103,10 @@ void PlayerInfo::updateData() } pSprite = MemoryManagement::create(); pSprite->setResAnim(pAnim); - pSprite->setWidth(pAnim->getWidth()); + if (pAnim != nullptr) + { + pSprite->setWidth(pAnim->getWidth()); + } pSprite->setY(yPos); if (pAnim != nullptr) { diff --git a/menue/editormenue.cpp b/menue/editormenue.cpp index 6212320b9..5e601e7f3 100644 --- a/menue/editormenue.cpp +++ b/menue/editormenue.cpp @@ -699,30 +699,35 @@ void EditorMenue::showExtendMap() void EditorMenue::extendMap(const QString & mapFile, GameEnums::Directions direction) { + createTempFile(); m_pMap->extendMap(mapFile, direction); setFocused(true); } void EditorMenue::flipX() { + createTempFile(); spGameMap pGameMap = m_pMap; pGameMap->flipX(); } void EditorMenue::flipY() { + createTempFile(); spGameMap pGameMap = m_pMap; pGameMap->flipY(); } void EditorMenue::rotateX() { + createTempFile(); spGameMap pGameMap = m_pMap; pGameMap->rotateX(); } void EditorMenue::rotateY() { + createTempFile(); spGameMap pGameMap = m_pMap; pGameMap->rotateY(); } @@ -798,7 +803,8 @@ void EditorMenue::copy() } void EditorMenue::resizeMap(qint32 left, qint32 top, qint32 right, qint32 bottom) -{ +{ + createTempFile(); CONSOLE_PRINT("EditorMenue::resizeMap", GameConsole::eDEBUG); m_pMap->resizeMap(left, top, right, bottom); updateGrids();