Skip to content

Commit

Permalink
`Wfc::copy_knowledge(const std::optional&, const std::optional&, cons…
Browse files Browse the repository at this point in the history
…t std::optional&)`: add member function

misc. other less notable changes
  • Loading branch information
fl4shk committed Nov 20, 2022
1 parent 579993b commit fab2b6f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
42 changes: 19 additions & 23 deletions dungeon_simple_1.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
~~~~~~~~~#~~~~~~~~~~~~~~~~~#~~~~~~~~~
~~~~~~~~~#~~~~~~~~~~~~~~~~~#~~~~~~~~~
~~~~############~~~~~~~~~~~#~~~~~~~~~
~~~~############~~~~~~############~~~
~~~~############~~~~~~############~~~
#####################################
~~~~############~~~~~~############~~~
~~~~############~~~~~~############~~~
~~~~############~~~~~~~~~~~~~~#~~~~~~
~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~#~~~~~~
~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~#~~~~~~
~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~#~~~~~~
~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~#~~~~~~
~~~~~~~~~~#~~~~~~~~~~~~~###########~~
~~~###########~~~~~~~~~~###########~~
~~~###########~~~~~~~~~~###########~~
~~~###########~~~~~~~~~~###########~~
##############~~~~~~~~~~#############
~~~################################~~
~~~###########~~~~~~~~~~###########~~
~~~###########~~~~~~~~~~###########~~
~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~#~~~~~~
~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~#~~~~~~
#,# #,#
#,# #,#
####+### ####+#####
###......#####........###
,,+......+,,,+........+,,
###......#####........###
#......# #####+####
#......# #,#
####+### #,#
#,# #,#
#,# ####+####
#,# #.......#
####+#### #.......#
###.......#####.......###
,,+.......+,,,+.......+,,
###.......#####.......###
####+#### ###+#####
#,# #,#
#,# #,#
20 changes: 17 additions & 3 deletions src/wfc_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,21 @@ void Wfc::learn(const std::vector<std::vector<size_t>>& input_tiles) {
}
//--------
}
void Wfc::copy_knowledge(
const std::optional<MtDarr>& n_mt_darr,
const std::optional<R2wUmap>& n_r2w_umap,
const std::optional<WeightDarr>& n_weight_darr
) {
if (n_mt_darr) {
_mt_darr = *n_mt_darr;
}
if (n_r2w_umap) {
_r2w_umap = *n_r2w_umap;
}
if (n_weight_darr) {
_weight_darr = *n_weight_darr;
}
}
void Wfc::copy_knowledge(const Wfc& to_copy) {
if (mt_dim() != to_copy.mt_dim()) {
throw std::invalid_argument(sconcat
Expand All @@ -544,9 +559,8 @@ void Wfc::copy_knowledge(const Wfc& to_copy) {
"`opt_reflect() (", opt_reflect(), ") "
"!= to_copy.opt_reflect() (", to_copy.opt_reflect(), ")`"));
}
_mt_darr = to_copy.mt_darr();
_r2w_umap = to_copy.r2w_umap();
_weight_darr = to_copy.weight_darr();
copy_knowledge
(to_copy.mt_darr(), to_copy.r2w_umap(), to_copy.weight_darr());
}
void Wfc::gen() {
//while (_gen_iteration()) {
Expand Down
20 changes: 17 additions & 3 deletions src/wfc_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,20 @@ class Wfc final {
//std::unordered_map<size_t, RuleUset> _rules_umap;
//RuleUset _rule_uset;

std::vector<Metatile> _mt_darr;
public: // types
using MtDarr = std::vector<Metatile>;
using R2wUmap = std::unordered_map<Rule, double>;
using WeightDarr = std::vector<double>;
private: // variables
MtDarr _mt_darr;
//std::unordered_map<size_t, Metatile> _input_to_mt_umap;

// This maps rules to their weights
std::unordered_map<Rule, double> _r2w_umap;
R2wUmap _r2w_umap;

// This maps tiles to their weights
//std::unordered_map<size_t, double> _weight_umap;
std::vector<double> _weight_darr;
WeightDarr _weight_darr;
public: // types
using Rng = pcg64;
using Ddist = std::discrete_distribution<u64>;
Expand All @@ -338,6 +343,15 @@ class Wfc final {
GEN_CM_BOTH_CONSTRUCTORS_AND_ASSIGN(Wfc);
~Wfc();
void learn(const std::vector<std::vector<size_t>>& input_tiles);

// Use this function wisely, as it could potentially make this class
// not work properly.
void copy_knowledge(
const std::optional<MtDarr>& n_mt_darr,
const std::optional<R2wUmap>& n_r2w_umap,
const std::optional<WeightDarr>& n_weight_darr
);

void copy_knowledge(const Wfc& to_copy);
void gen();
void set_orig_state(const PotentialUmap& to_inject);
Expand Down

0 comments on commit fab2b6f

Please sign in to comment.