-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/btree #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/btree #13
Changes from all commits
ee61c9c
2847435
24c6603
9ac4ddd
52cdbc6
a3799bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /*----------------------------------------------------------------------------------------------- | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2015-2026 Segfault by Kim Kulling | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software is furnished to do so, | ||
| subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| -----------------------------------------------------------------------------------------------*/ | ||
| #include "behavior_tree.h" | ||
| #include "core/filearchive.h" | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| using json = ::nlohmann::json; | ||
|
|
||
| namespace segfault::ai { | ||
|
|
||
| using namespace segfault::core; | ||
|
|
||
| BehaviorTree::BehaviorTree() { | ||
|
Check failure on line 34 in src/runtime/ai/behavior_tree.cpp
|
||
| // Constructor implementation (if needed) | ||
| } | ||
|
|
||
| BehaviorTree::~BehaviorTree() { | ||
|
Check failure on line 38 in src/runtime/ai/behavior_tree.cpp
|
||
| // Destructor implementation (if needed) | ||
| } | ||
|
|
||
| bool BehaviorTree::init(const char* configFile) { | ||
|
Check warning on line 42 in src/runtime/ai/behavior_tree.cpp
|
||
| if (configFile == nullptr) { | ||
| return false; | ||
| } | ||
|
|
||
| FileArchive archive(configFile, "r", true, false); | ||
| if (!archive.isValid()) { | ||
| return false; | ||
| } | ||
|
|
||
| // Read the entire file into a string | ||
| size_t size = archive.getSize(); | ||
| std::string content(size, '\0'); | ||
| archive.read(reinterpret_cast<uint8_t*>(&content[0]), size); | ||
| json Doc{ json::parse(content) }; | ||
|
|
||
|
kimkulling marked this conversation as resolved.
|
||
| return true; | ||
| } | ||
|
|
||
| void BehaviorTree::update() { | ||
| if (mRootNode == nullptr) { | ||
| return; | ||
| } | ||
|
|
||
| mRootNode->tick(); | ||
| } | ||
|
kimkulling marked this conversation as resolved.
|
||
|
|
||
| } // namespace segfault::ai | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /*----------------------------------------------------------------------------------------------- | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2015-2026 Segfault by Kim Kulling | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software is furnished to do so, | ||
| subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| -----------------------------------------------------------------------------------------------*/ | ||
| #pragma once | ||
|
|
||
| #include "core/segfault.h" | ||
|
|
||
| namespace segfault::ai { | ||
|
kimkulling marked this conversation as resolved.
|
||
| enum class NodeStatus { | ||
| IDLE = 0, | ||
| RUNNING = 1, | ||
| SUCCESS = 2, | ||
| FAILURE = 3, | ||
| SKIPPED = 4, | ||
| }; | ||
|
|
||
| //--------------------------------------------------------------------------------------------- | ||
| /// @class BehaviorTreeNode | ||
| /// @brief The BehaviorTreeNode class represents a single node in a behavior tree, which is a | ||
| /// hierarchical structure used to model the decision-making process of an AI agent. Each node | ||
| /// can represent an action, condition, or control flow, allowing for complex behaviors to be | ||
| /// defined in a modular and reusable way. | ||
| //--------------------------------------------------------------------------------------------- | ||
| class BehaviorTreeNode { | ||
| public: | ||
| // No copying | ||
| BehaviorTreeNode(const BehaviorTreeNode& rhs) = delete; | ||
| BehaviorTreeNode& operator = (const BehaviorTreeNode& rhs) = delete; | ||
|
|
||
| BehaviorTreeNode() = default; | ||
| virtual ~BehaviorTreeNode() = default; | ||
|
|
||
| /// @brief Pure virtual function to be implemented by derived classes | ||
| virtual NodeStatus tick() = 0; | ||
| }; | ||
|
|
||
| class LeafNode : public BehaviorTreeNode { | ||
| public: | ||
| NodeStatus tick() override { | ||
| // Implementation of the leaf node's behavior | ||
| return NodeStatus::IDLE; | ||
| } | ||
| }; | ||
|
|
||
| class SequenceNode : public BehaviorTreeNode { | ||
| public: | ||
| NodeStatus tick() override { | ||
| // Implementation of the sequence node's behavior | ||
| return NodeStatus::IDLE; | ||
| } | ||
| }; | ||
|
|
||
| class ConditionNode : public LeafNode { | ||
| public: | ||
| NodeStatus tick() override { | ||
| // Implementation of the condition node's behavior | ||
| return NodeStatus::IDLE; | ||
| } | ||
| }; | ||
|
|
||
| class ActionNode : public LeafNode { | ||
| public: | ||
| NodeStatus tick() override { | ||
| // Implementation of the action node's behavior | ||
| return NodeStatus::IDLE; | ||
| } | ||
| }; | ||
|
|
||
| //--------------------------------------------------------------------------------------------- | ||
| /// @class BehaviorTree | ||
| /// @brief The BehaviorTree class represents a behavior tree, which is a hierarchical structure | ||
| /// used to model the decision-making process of an AI agent. It consists of nodes that | ||
| /// represent actions, conditions, and control flow, allowing for complex behaviors to be | ||
| /// defined in a modular and reusable way. | ||
| //--------------------------------------------------------------------------------------------- | ||
| class SEGFAULT_EXPORT BehaviorTree final { | ||
| public: | ||
| // No copying | ||
| BehaviorTree(const BehaviorTree& rhs) = delete; | ||
| BehaviorTree& operator = (const BehaviorTree& rhs) = delete; | ||
|
|
||
| /// @brief The class constructor. | ||
| BehaviorTree(); | ||
|
|
||
| /// @brief The class destructor. | ||
| ~BehaviorTree(); | ||
|
|
||
| /// @brief Initializes the behavior tree with the specified parameters. | ||
| /// @param[ in ] configFile The path to the configuration file that defines the behavior tree structure. | ||
| /// @return True if initialization was successful, false otherwise. | ||
| bool init(const char* configFile); | ||
|
|
||
| /// @brief Updates the behavior tree, processing the nodes and executing actions as needed. | ||
| void update(); | ||
|
|
||
| private: | ||
| BehaviorTreeNode* mRootNode{ nullptr }; | ||
| }; | ||
|
|
||
| } // namespace segfault::ai | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Copyright notice in source files does not match the canonical LICENSE file.
The copyright notice should match what is specified in the LICENSE file as the copyright holder. This file (and all others with MIT headers) uses "Copyright (c) 2015-2026 Segfault by Kim Kulling", but the repository's LICENSE file specifies "Copyright (c) 2025 Kim Kulling".
These discrepancies create ambiguity about the correct copyright holder and years:
The MIT license requires that "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software", which means copyright notices must be consistent across the LICENSE file and source files for compliance.
This issue affects all 8 files receiving MIT headers in this PR. Update all headers to match the canonical LICENSE file:
Copyright (c) 2025 Kim Kulling.🤖 Prompt for AI Agents