Skip to content

Commit

Permalink
another qt changes the interface bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Robosturm committed Oct 8, 2023
1 parent c560bfa commit af4479e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 86 deletions.
95 changes: 61 additions & 34 deletions ai/heavyai/situationevaluator.cpp
Original file line number Diff line number Diff line change
@@ -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<qint32>(Features::Max)),
m_searchRange(GlobalUtils::getSpCircle(0, SEARCH_RANGE))
{
}

void SituationEvaluator::updateInputVector(GameMap* pMap, const QPoint & searchPoint)
{
std::vector<Unit*> units;
getUnitsInRange(units, pMap, searchPoint);

}

void SituationEvaluator::getUnitsInRange(std::vector<Unit*> & 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<qint32>(Features::Max)),
m_searchRange(GlobalUtils::getSpCircle(0, SEARCH_RANGE)),
m_pOwner(pOwner)
{
}

void SituationEvaluator::updateInputVector(GameMap* pMap, const QPoint & searchPoint)
{
std::array<Unit*, UNIT_COUNT> 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<Unit*, UNIT_COUNT> & 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;
}
}
}
}
}
88 changes: 45 additions & 43 deletions ai/heavyai/situationevaluator.h
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
#pragma once

#include <QObject>

#include "3rd_party/opennn/opennn/opennn.h"

class Unit;
class GameMap;
class QmlVectorPoint;
using spQmlVectorPoint = std::shared_ptr<QmlVectorPoint>;

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<Unit*> & units, GameMap* pMap, const QPoint & searchPoint);

private:
opennn::Tensor<opennn::type, 2> m_inputVector;
spQmlVectorPoint m_searchRange;
};

#pragma once

#include <QObject>

#include "3rd_party/opennn/opennn/opennn.h"

class Player;
class Unit;
class GameMap;
class QmlVectorPoint;
using spQmlVectorPoint = std::shared_ptr<QmlVectorPoint>;

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<Unit*, UNIT_COUNT> & units, GameMap* pMap, const QPoint & searchPoint);

private:
opennn::Tensor<opennn::type, 2> m_inputVector;
spQmlVectorPoint m_searchRange;
Player* m_pOwner{nullptr};
};

14 changes: 8 additions & 6 deletions coreengine/globalutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <QDirIterator>
#include <QDateTime>

#include <cmath>

#include "coreengine/qmlvector.h"
#include "coreengine/globalutils.h"
#include "coreengine/gameconsole.h"
Expand Down Expand Up @@ -537,32 +539,32 @@ QVector<qint32> GlobalUtils::calcWidths(const QVector<qint32> & 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)
Expand Down
4 changes: 2 additions & 2 deletions game/gameanimation/gameanimationcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ void GameAnimationCapture::addSoldierSprite(const QString spriteID, Player* pPl
const float startPercentDone = (static_cast<float>(m_startPoints) / static_cast<float>(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<oxygine::Sprite>();
if (pAnim->getTotalFrames() > 1)
Expand Down

0 comments on commit af4479e

Please sign in to comment.