Add some code from framework

This commit is contained in:
Bram verhulst
2025-05-18 11:03:51 +02:00
parent 294e9ab735
commit 620dafb591
18 changed files with 487 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
#pragma once
class BehaviorTree
{
public:
};

2
project/BehaviourTree.h Normal file
View File

@@ -0,0 +1,2 @@
#include "stdafx.h"
#include "BehaviorTree.h"

80
project/BlackBoard.h Normal file
View File

@@ -0,0 +1,80 @@
#pragma once
#include <unordered_map>
#include <string>
class IBlackBoardField
{
public:
IBlackBoardField() = default;
virtual ~IBlackBoardField() = default;
};
//BlackboardField does not take ownership of pointers whatsoever!
template<typename T>
class BlackboardField : public IBlackBoardField
{
public:
explicit BlackboardField(T data) : m_Data(data) {
}
T GetData() { return m_Data; };
void SetData(T data) { m_Data = data; }
private:
T m_Data;
};
class Blackboard final
{
public:
Blackboard() = default;
~Blackboard() {
for (auto el : m_BlackboardData)
delete el.second;
m_BlackboardData.clear();
}
Blackboard(const Blackboard& other) = delete;
Blackboard& operator=(const Blackboard& other) = delete;
Blackboard(Blackboard&& other) = delete;
Blackboard& operator=(Blackboard&& other) = delete;
template<typename T> bool AddData(const std::string& name, T data) {
auto it = m_BlackboardData.find(name);
if (it == m_BlackboardData.end()) {
m_BlackboardData[name] = new BlackboardField<T>(data);
return true;
}
printf("WARNING: Data '%s' of type '%s' already in Blackboard \n", name.c_str(), typeid(T).name());
return false;
}
template<typename T> bool ChangeData(const std::string& name, T data) {
auto it = m_BlackboardData.find(name);
if (it != m_BlackboardData.end()) {
BlackboardField<T>* p = dynamic_cast<BlackboardField<T>*>(m_BlackboardData[name]);
if (p) {
p->SetData(data);
return true;
}
}
printf("WARNING: Data '%s' of type '%s' not found in Blackboard \n", name.c_str(), typeid(T).name());
return false;
}
//Get the data from the blackboard
template<typename T> bool GetData(const std::string& name, T& data) {
BlackboardField<T>* p = dynamic_cast<BlackboardField<T>*>(m_BlackboardData[name]);
if (p != nullptr) {
data = p->GetData();
return true;
}
printf("WARNING: Data '%s' of type '%s' not found in Blackboard \n", name.c_str(), typeid(T).name());
return false;
}
private:
std::unordered_map<std::string, IBlackBoardField*> m_BlackboardData;
};

View File

@@ -3,7 +3,7 @@
# ADD NEW .cpp FILES HERE
add_library(Exam_Plugin SHARED
"stdafx.cpp"
"SurvivalAgentPlugin.cpp" )
"SurvivalAgentPlugin.cpp" "BehaviourTree.cpp" "BehaviourTree.h" "BlackBoard.h" "Thinker.h" "Thinker.cpp")
target_link_libraries(Exam_Plugin PUBLIC ${EXAM_LIB_DEBUG})
target_include_directories(Exam_Plugin PUBLIC ${EXAM_INCLUDE_DIR})

View File

@@ -12,10 +12,10 @@ void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& inf
m_pInterface = static_cast<IExamInterface*>(pInterface);
//Information for the leaderboards!
info.BotName = "MinionExam";
info.Student_Name = "Firstname_Lastname"; //No special characters allowed. Highscores won't work with special characters.
info.Student_Class = "2DAE00";
info.LB_Password = "TheChampIsHere123!";//Don't use a real password! This is only to prevent other students from overwriting your highscore!
info.BotName = "Cat";
info.Student_Name = "Bram Verhulst";//No special characters allowed. Highscores won't work with special characters.
info.Student_Class = "2DAE11";
info.LB_Password = "ILikeCuteCats!";//Don't use a real password! This is only to prevent other students from overwriting your highscore!
}
//Called only once

21
project/Thinker.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "stdafx.h"
#include "Thinker.h"
#include <algorithm>
void Thinker::CheckIfNewHouse(const HouseInfo& newHouse) {
auto it = std::find_if(m_HousesMemory.begin(), m_HousesMemory.end(),
[&newHouse](const HouseMemory& house) {
return house.info.Center == newHouse.Center;
});
if (it != m_HousesMemory.end()) {
//it->lastSaw = std::chrono::steady_clock::now();
//it->newHouse = false;
return;
}
HouseMemory houseToMemory{};
houseToMemory.info = newHouse;
m_HousesMemory.push_back(houseToMemory);
}

25
project/Thinker.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <Exam_HelperStructs.h>
#include <chrono>
#include <vector>
class Thinker final {
public:
struct HouseMemory {
bool newHouse{ true };
HouseInfo info;
std::chrono::steady_clock::time_point lastSaw;
};
Thinker() = default;
~Thinker() = default;
Thinker(const Thinker&) = default;
Thinker& operator=(const Thinker&) = default;
Thinker(Thinker&&) = default;
Thinker& operator=(Thinker&&) = default;
void CheckIfNewHouse(const HouseInfo& newHouse);
private:
std::vector<HouseMemory> m_HousesMemory{};
};