basic generate_random_path in strict_tree_rules

This commit is contained in:
Zeno Rogue 2021-07-31 13:36:57 +02:00
parent 3972e5a6bb
commit c8b4d6b159
3 changed files with 41 additions and 0 deletions

View File

@ -71,6 +71,7 @@ struct arbi_tiling {
int order;
bool have_line, have_ph, have_tree;
int yendor_backsteps;
vector<shape> shapes;
string name;
@ -397,6 +398,7 @@ EX void load(const string& fname, bool after_sliding IS(false)) {
c.floor_scale = .5;
c.have_ph = c.have_line = false;
c.have_tree = false;
c.yendor_backsteps = 0;
exp_parser ep;
ep.s = s;
ld angleunit = 1, distunit = 1, angleofs = 0;
@ -511,6 +513,10 @@ EX void load(const string& fname, bool after_sliding IS(false)) {
else if(ep.eat("treestate(")) {
rulegen::parse_treestate(c, ep);
}
else if(ep.eat("yendor_backsteps(")) {
c.yendor_backsteps = ep.iparse();
ep.force_eat(")");
}
else if(ep.eat("range(")) {
c.range = ep.iparse();
ep.force_eat(")");

View File

@ -144,6 +144,7 @@ void expansion_analyzer::preliminary_grouping() {
void expansion_analyzer::reduce_grouping() {
if(reg3::in_rule()) return;
if(currentmap->strict_tree_rules()) return;
int old_N = N;
vector<int> grouping;
grouping.resize(N);
@ -208,6 +209,7 @@ bignum& expansion_analyzer::get_descendants(int level) {
}
bignum& expansion_analyzer::get_descendants(int level, int type) {
if(!N) preliminary_grouping(), reduce_grouping();
auto& pd = descendants;
size_upto(pd, level+1);
for(int d=0; d<=level; d++)

View File

@ -872,6 +872,7 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
int t = -1;
bignum full_id;
bool onlychild = true;
bool launched = false;
cellwalker ycw = start;
if(for_yendor) setdist(p.path[0], 7, NULL);
@ -901,6 +902,37 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
if(isize(ds)) ycw += ds[hrand(isize(ds))];
}
else if(currentmap->strict_tree_rules()) {
if(for_yendor && i < arb::current.yendor_backsteps) {
println(hlog, i, " < ", arb::current.yendor_backsteps);
ycw.spin = 0;
}
else {
if(!launched) {
t = ycw.at->master->fieldval;
bignum b = expansion.get_descendants(length-i, t);
p.full_id_0 = full_id = hrand(b);
/* it may happen that the subtree dies out */
if(!full_id.approx_int()) goto stupid;
launched = true;
}
ycw.spin = 0;
auto& r = rulegen::treestates[t];
for(int ri=0; ri<isize(r.rules); ri++) {
int tch = r.rules[ri];
if(tch < 0) continue;
auto& sub_id = expansion.get_descendants(length-1-i, tch);
if(full_id < sub_id) {
t = tch; ycw += ri; break;
}
full_id.addmul(sub_id, -1);
}
}
}
else if(trees_known()) {
auto sdist = [start] (cell *c) { return celldistance(start.at, c); };
if(i == 0) {
@ -951,6 +983,7 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
}
else {
stupid:
// stupid
ycw += rev;
// well, make it a bit more clever on bitruncated a4 grids