Skip to content

Commit

Permalink
Add starting code for Blackboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Apr 17, 2024
1 parent b1f5b49 commit 170e9b1
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/other/behaviour_tree/include/behaviour_tree/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ namespace behaviour_tree {
bool Context::canRun() const {
return this->behaviour_tree->canRun();
}

void Context::setBlackboard(const std::string &key, const int value)
{
this->blackboard[key] = value;
}

int Context::getBlackboard(const std::string &key) const
{
return this->blackboard.at(key);
}
}
6 changes: 6 additions & 0 deletions app/other/behaviour_tree/include/behaviour_tree/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include <variant>
#include <unordered_map>

#include "Status.hpp"

Expand Down Expand Up @@ -40,11 +41,16 @@ namespace behaviour_tree

bool canRun() const;

void setBlackboard(const std::string& key, const int value);
int getBlackboard(const std::string& key) const;

// Necessary for the class to be a polymorphic
virtual void _() {};
private:
std::shared_ptr<BehaviourTree> behaviour_tree;
std::vector<std::pair<std::shared_ptr<node::Node>, int>> node_trace_list;

std::unordered_map<std::string, int> blackboard;
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef BEHAVIOUR_TREE_BLACKBOARD_LEAF_HPP
#define BEHAVIOUR_TREE_BLACKBOARD_LEAF_HPP

#pragma once

#include "../Node.hpp"

namespace behaviour_tree::node::blackboard
{
class BlackboardLeaf : public Node
{
public:
BlackboardLeaf(const std::string& name) : Node(name)
{
}
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef BEHAVIOUR_TREE_CHANGE_INTEGER_HPP
#define BEHAVIOUR_TREE_CHANGE_INTEGER_HPP

#pragma once

#include "BlackboardLeaf.hpp"

#include "enum/IntegerChangeType.hpp"

namespace behaviour_tree::node::blackboard
{
class ChangeInteger final : public BlackboardLeaf
{
public:
ChangeInteger(const std::string &name) : BlackboardLeaf(name) {}

const Status run(const int tick_count, std::shared_ptr<Context> context) final override
{
}

const std::string toString() const final override
{
const std::string &name = this->getName();
if (name != "")
return fmt::format(R"(<Blackboard:ChangeInteger name='{}' type='{}'/>)", name, out);
else
return fmt::format(R"(<Blackboard:ChangeInteger type='{}'/>)", out);
}

private:
std::string variable_name;
int value;
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef BEHAVIOUR_TREE_CHANGE_INTEGER_HPP
#define BEHAVIOUR_TREE_CHANGE_INTEGER_HPP

#pragma once

#include "BlackboardLeaf.hpp"

#include "enum/ConditionOperatorType.hpp"

namespace behaviour_tree::node::blackboard
{
class IntegerCondition final : public BlackboardLeaf
{
public:
IntegerCondition(const std::string &name) : BlackboardLeaf(name) {}

const Status run(const int tick_count, std::shared_ptr<Context> context) final override
{
}

const std::string toString() const final override
{
const std::string &name = this->getName();
if (name != "")
return fmt::format(R"(<Blackboard:IntegerCondition name='{}' operator='{}'/>)", name, out);
else
return fmt::format(R"(<Blackboard:IntegerCondition operator='{}'/>)", out);
}

private:
std::string variable_name;
ConditionOperatorType operator;
int value;
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef BEHAVIOUR_TREE_CONDITION_OPERATOR_TYPE_HPP
#define BEHAVIOUR_TREE_CONDITION_OPERATOR_TYPE_HPP

#pragma once

namespace behaviour_tree::node::blackboard
{
enum class ConditionOperatorType
{
Equal,
NotEqual,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual,
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef BEHAVIOUR_TREE_INTEGER_CHANGE_TYPE_HPP
#define BEHAVIOUR_TREE_INTEGER_CHANGE_TYPE_HPP

#pragma once

namespace behaviour_tree::node::blackboard
{
enum class IntegerChangeType
{
Set,
Add,
Subtract,
Multiply,
Divide,
};
}

#endif

0 comments on commit 170e9b1

Please sign in to comment.