main
Brett 2024-03-22 19:38:50 -04:00
parent 59c558d479
commit d8b4f1ec42
5 changed files with 15 additions and 39 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(lilfbtf5 VERSION 0.1.37) project(lilfbtf5 VERSION 0.1.38)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -66,8 +66,8 @@ namespace fb
[[nodiscard]] inline function_id getFunction() const [[nodiscard]] inline function_id getFunction() const
{ return function; } { return function; }
inline void call(blt::span<detail::node_t*> args) inline void call(blt::span<detail::node_t*> args, blt::unsafe::buffer_any_t extra_args)
{ func(*this, args); }; { func({*this, args, extra_args}); };
~func_t() = default; ~func_t() = default;
}; };
@ -99,9 +99,9 @@ namespace fb
children[i] = nullptr; children[i] = nullptr;
} }
inline void evaluate() inline void evaluate(blt::unsafe::buffer_any_t extra_args)
{ {
type.call(blt::span<node_t*>{children, type.argc()}); type.call(blt::span<node_t*>{children, type.argc()}, extra_args);
} }
inline blt::unsafe::any_t value() inline blt::unsafe::any_t value()
@ -173,7 +173,7 @@ namespace fb
static tree_t make_tree(detail::tree_construction_info_t tree_info, blt::size_t min_depth, blt::size_t max_depth, static tree_t make_tree(detail::tree_construction_info_t tree_info, blt::size_t min_depth, blt::size_t max_depth,
std::optional<type_id> starting_type = {}); std::optional<type_id> starting_type = {});
detail::tree_eval_t evaluate(const fitness_eval_func_t& fitnessEvalFunc); detail::tree_eval_t evaluate(blt::unsafe::buffer_any_t extra_args, const fitness_eval_func_t& fitnessEvalFunc);
blt::size_t depth(); blt::size_t depth();

@ -1 +1 @@
Subproject commit 16641a27cbe6fccb8f6a6518d903432311cbeb81 Subproject commit 1256ec201cdb3a8d3d9bb4ebe9c25637a718465e

View File

@ -63,7 +63,7 @@ namespace fb
return tree; return tree;
} }
detail::tree_eval_t tree_t::evaluate(const fitness_eval_func_t& fitnessEvalFunc) detail::tree_eval_t tree_t::evaluate(blt::unsafe::buffer_any_t extra_args, const fitness_eval_func_t& fitnessEvalFunc)
{ {
using detail::node_t; using detail::node_t;
std::stack<node_t*> nodes; std::stack<node_t*> nodes;
@ -83,7 +83,7 @@ namespace fb
while (!node_stack.empty()) while (!node_stack.empty())
{ {
node_stack.top()->evaluate(); node_stack.top()->evaluate(extra_args);
node_stack.pop(); node_stack.pop();
} }

View File

@ -25,36 +25,6 @@ struct pixel
const blt::size_t image_width = 128, image_height = 128; const blt::size_t image_width = 128, image_height = 128;
struct pixelator_t
{
private:
blt::size_t width, height;
blt::size_t x = 0, y = 0;
public:
pixelator_t(blt::size_t width, blt::size_t height): width(width), height(height)
{}
pixel next()
{
if (x > width)
{
x = 0;
y++;
}
return {x++, y};
}
[[nodiscard]] inline blt::size_t curX() const
{
return x;
}
[[nodiscard]] inline blt::size_t curY() const
{
return y;
}
} pixelator{image_width, image_height};
const fb::func_t_call_t add_f = [](const fb::detail::func_t_arguments& args) { const fb::func_t_call_t add_f = [](const fb::detail::func_t_arguments& args) {
args.self.setValue(args.arguments[0]->value().any_cast<blt::u8>() + args.arguments[1]->value().any_cast<blt::u8>()); args.self.setValue(args.arguments[0]->value().any_cast<blt::u8>() + args.arguments[1]->value().any_cast<blt::u8>());
}; };
@ -73,6 +43,12 @@ const fb::func_t_call_t div_f = [](const fb::detail::func_t_arguments& args) {
}; };
const fb::func_t_call_t empty_f = [](const fb::detail::func_t_arguments&) {}; const fb::func_t_call_t empty_f = [](const fb::detail::func_t_arguments&) {};
const fb::func_t_call_t coord_x_f = [](const fb::detail::func_t_arguments& args) {
args.self.setValue(args.extra_args.any_cast<pixel>().x);
};
const fb::func_t_call_t coord_y_f = [](const fb::detail::func_t_arguments& args) {
args.self.setValue(args.extra_args.any_cast<pixel>().y);
};
const fb::func_t_init_t value_init_f = [](fb::func_t& self) { const fb::func_t_init_t value_init_f = [](fb::func_t& self) {
self.setValue(fb::random_value()); self.setValue(fb::random_value());
}; };