Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Robosturm committed Oct 11, 2023
1 parent af4479e commit 0a28628
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
48 changes: 41 additions & 7 deletions ai/heavyai/situationevaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<qint32>(Features::Max)),
m_searchRange(GlobalUtils::getSpCircle(0, SEARCH_RANGE)),
Expand All @@ -12,23 +14,48 @@ SituationEvaluator::SituationEvaluator(Player* pOwner)

void SituationEvaluator::updateInputVector(GameMap* pMap, const QPoint & searchPoint)
{
std::array<Unit*, UNIT_COUNT> 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<qint32>(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<qint32>(Features::Max); ++feature)
{
qint32 basePosition = UNIT_COUNT * UNIT_COUNT * feature + i * UNIT_COUNT;

}
}
}
}

void SituationEvaluator::getUnitsInRange(std::array<Unit*, UNIT_COUNT> & 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;
Expand All @@ -43,12 +70,14 @@ void SituationEvaluator::getUnitsInRange(std::array<Unit*, UNIT_COUNT> & 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)
Expand All @@ -58,4 +87,9 @@ void SituationEvaluator::getUnitsInRange(std::array<Unit*, UNIT_COUNT> & units,
}
}
}
for (qint32 i = alliedPosition; i <= enemyPosition; ++i)
{
m_unitsInfo[enemyPosition].pUnit = nullptr;
m_unitsInfo[enemyPosition].multiplier = 1;
}
}
9 changes: 8 additions & 1 deletion ai/heavyai/situationevaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,10 +41,11 @@ class SituationEvaluator : public QObject
void updateInputVector(GameMap* pMap, const QPoint & searchPoint);

private:
void getUnitsInRange(std::array<Unit*, UNIT_COUNT> & units, GameMap* pMap, const QPoint & searchPoint);
void getUnitsInRange(GameMap* pMap, const QPoint & searchPoint);

private:
opennn::Tensor<opennn::type, 2> m_inputVector;
std::array<UnitInfo, UNIT_COUNT> m_unitsInfo;
spQmlVectorPoint m_searchRange;
Player* m_pOwner{nullptr};
};
Expand Down
5 changes: 4 additions & 1 deletion game/ui/playerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ void PlayerInfo::updateData()
}
pSprite = MemoryManagement::create<oxygine::Sprite>();
pSprite->setResAnim(pAnim);
pSprite->setWidth(pAnim->getWidth());
if (pAnim != nullptr)
{
pSprite->setWidth(pAnim->getWidth());
}
pSprite->setY(yPos);
if (pAnim != nullptr)
{
Expand Down
8 changes: 7 additions & 1 deletion menue/editormenue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0a28628

Please sign in to comment.