-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'group_2/development' into development
- Loading branch information
Showing
31 changed files
with
2,023 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
#include <string> | ||
#include "JsonBuilder.hpp" | ||
|
||
namespace DataCollection { | ||
|
||
/** | ||
* @brief A data collector class to quantify agent interactions. | ||
* | ||
* Useful for setting up graphs for common interactions. | ||
*/ | ||
class AgentInteractionCollector { | ||
private: | ||
std::unordered_map<std::string, int> interactionData; /// Data storage map of agent name to interactions. | ||
public: | ||
/** | ||
* Default constructor for AgentInteractionCollector | ||
*/ | ||
AgentInteractionCollector() = default; | ||
|
||
/** | ||
* Getter for interaction data | ||
* @return Const reference to the interaction data storage. | ||
*/ | ||
const std::unordered_map<std::string, int>& GetInteractionData() { return interactionData; } | ||
|
||
/** | ||
* Get the amount of unique agents that occured | ||
* @return int amount of agent occurances | ||
*/ | ||
size_t GetUniqueInteractions() { return interactionData.size(); } | ||
|
||
/** | ||
* Increment occurance amount for a certain agent. | ||
* @param agentName Agent name to record new interaction with | ||
*/ | ||
void RecordInteraction(const std::string& agentName) { interactionData[agentName]++; } | ||
|
||
void WriteToInteractionFile(const std::string filename){ | ||
JsonBuilder json_builder; | ||
std::ofstream jsonfilestream(filename); | ||
json_builder.StartArray("agentInteractions"); | ||
for (auto& [agentName, interactionCount] : interactionData) { | ||
json_builder.AddName(agentName); | ||
json_builder.AddInt("interactionCount", interactionCount); | ||
json_builder.InputToArray("agentInteractions", json_builder.GetJSON()); | ||
json_builder.ClearJSON(); | ||
} | ||
json_builder.WriteToFile(jsonfilestream, json_builder.GetJSONArray()); | ||
jsonfilestream.close(); | ||
} | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
#include <string> | ||
#include <vector> | ||
#include <numeric> | ||
#include <fstream> | ||
#include "JsonBuilder.hpp" | ||
|
||
namespace DataCollection { | ||
|
||
/** | ||
* @brief A data collector class for damage of game items. | ||
* | ||
* Useful for setting up graphs for analysis of item balancing. | ||
*/ | ||
class DamageCollector { | ||
private: | ||
std::unordered_map<std::string, std::vector<double>> damageData; // Damage storage map of item name to damage amounts | ||
public: | ||
/** | ||
* @brief Default constructor for DamageCollector. | ||
*/ | ||
DamageCollector() = default; | ||
|
||
/** | ||
* Store a damage amount for a certain item. | ||
* @param itemName Name of the item to store the damage for | ||
* @param damageAmt Amount of damage this item did | ||
*/ | ||
void RecordDamageResult(const std::string& itemName, double damageAmt) { | ||
damageData[itemName].push_back(damageAmt); | ||
} | ||
|
||
/** | ||
* Get the damage amounts for a certain item. | ||
* @param itemName Name of the item to get damage amounts for | ||
* @return Reference to the vector of damage amounts | ||
*/ | ||
std::vector<double>& GetDamageAmounts(std::string itemName) { | ||
if (damageData.contains(itemName)) { | ||
return damageData[itemName]; | ||
} else { | ||
// Created only once, subsequent calls will reference this | ||
static std::vector<double> empty; | ||
return empty; | ||
} | ||
} | ||
|
||
/** | ||
* Calculate average damage for a certain item | ||
* @param itemName Item name to calculate average for | ||
* @return The average damage as a double, -1 if the item does not exist | ||
*/ | ||
double CalculateAverageDamage(const std::string& itemName) { | ||
if (damageData.contains(itemName)) { | ||
std::vector<double>& damages = damageData[itemName]; | ||
return std::accumulate(damages.begin(), damages.end(), 0.0) / damages.size(); | ||
} | ||
|
||
return -1.0; | ||
} | ||
|
||
void WriteToDamageFile(std::string path) { | ||
std::ofstream jsonfilestream(path); | ||
JsonBuilder json_builder; | ||
for (auto& damage : damageData) { | ||
json_builder.AddName(damage.first); | ||
for (auto& damageAmt : damage.second) { | ||
json_builder.AddDamage(damageAmt); | ||
} | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <utility> | ||
#include "../core/Entity.hpp" | ||
#include "../core/AgentBase.hpp" | ||
|
||
namespace DataCollection { | ||
|
||
/** | ||
* @brief Represents damage related data between an agent and other entities (agents, items, grids, etc) | ||
*/ | ||
class DamageData { | ||
private: | ||
std::shared_ptr<cse491::AgentBase> agent; /// The agent that took damage | ||
std::shared_ptr<cse491::Entity> source; /// The source entity that inflicted the damage | ||
int amount; /// The amount of damage taken from this source | ||
|
||
public: | ||
/** | ||
* @brief Default constructor for a DamageData | ||
* @param src Damage source entity | ||
* @param amt Amount of damage taken | ||
*/ | ||
DamageData(std::shared_ptr<cse491::AgentBase> agnt, | ||
std::shared_ptr<cse491::Entity> src, | ||
int amt) : agent(std::move(agnt)), source(std::move(src)), amount(amt) {} | ||
|
||
/** | ||
* @brief Destructor for DamageData class. | ||
*/ | ||
~DamageData() = default; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "DataReceiver.hpp" | ||
#include "DamageData.hpp" | ||
|
||
namespace DataCollection { | ||
|
||
/** | ||
* @brief Data receiver class specialized for storing DamageData objects. | ||
* | ||
* This class extends DataReceiver class and provides specific functionality | ||
* for storing DamageData objects along with damage sources and amounts. | ||
*/ | ||
class DamageReceiver : public DataReceiver<DamageData> { | ||
|
||
}; | ||
} |
Oops, something went wrong.