mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-29 19:40:35 +00:00
basic generate_random_path in strict_tree_rules
This commit is contained in:
parent
3972e5a6bb
commit
c8b4d6b159
@ -71,6 +71,7 @@ struct arbi_tiling {
|
|||||||
|
|
||||||
int order;
|
int order;
|
||||||
bool have_line, have_ph, have_tree;
|
bool have_line, have_ph, have_tree;
|
||||||
|
int yendor_backsteps;
|
||||||
|
|
||||||
vector<shape> shapes;
|
vector<shape> shapes;
|
||||||
string name;
|
string name;
|
||||||
@ -397,6 +398,7 @@ EX void load(const string& fname, bool after_sliding IS(false)) {
|
|||||||
c.floor_scale = .5;
|
c.floor_scale = .5;
|
||||||
c.have_ph = c.have_line = false;
|
c.have_ph = c.have_line = false;
|
||||||
c.have_tree = false;
|
c.have_tree = false;
|
||||||
|
c.yendor_backsteps = 0;
|
||||||
exp_parser ep;
|
exp_parser ep;
|
||||||
ep.s = s;
|
ep.s = s;
|
||||||
ld angleunit = 1, distunit = 1, angleofs = 0;
|
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(")) {
|
else if(ep.eat("treestate(")) {
|
||||||
rulegen::parse_treestate(c, ep);
|
rulegen::parse_treestate(c, ep);
|
||||||
}
|
}
|
||||||
|
else if(ep.eat("yendor_backsteps(")) {
|
||||||
|
c.yendor_backsteps = ep.iparse();
|
||||||
|
ep.force_eat(")");
|
||||||
|
}
|
||||||
else if(ep.eat("range(")) {
|
else if(ep.eat("range(")) {
|
||||||
c.range = ep.iparse();
|
c.range = ep.iparse();
|
||||||
ep.force_eat(")");
|
ep.force_eat(")");
|
||||||
|
@ -144,6 +144,7 @@ void expansion_analyzer::preliminary_grouping() {
|
|||||||
|
|
||||||
void expansion_analyzer::reduce_grouping() {
|
void expansion_analyzer::reduce_grouping() {
|
||||||
if(reg3::in_rule()) return;
|
if(reg3::in_rule()) return;
|
||||||
|
if(currentmap->strict_tree_rules()) return;
|
||||||
int old_N = N;
|
int old_N = N;
|
||||||
vector<int> grouping;
|
vector<int> grouping;
|
||||||
grouping.resize(N);
|
grouping.resize(N);
|
||||||
@ -208,6 +209,7 @@ bignum& expansion_analyzer::get_descendants(int level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bignum& expansion_analyzer::get_descendants(int level, int type) {
|
bignum& expansion_analyzer::get_descendants(int level, int type) {
|
||||||
|
if(!N) preliminary_grouping(), reduce_grouping();
|
||||||
auto& pd = descendants;
|
auto& pd = descendants;
|
||||||
size_upto(pd, level+1);
|
size_upto(pd, level+1);
|
||||||
for(int d=0; d<=level; d++)
|
for(int d=0; d<=level; d++)
|
||||||
|
@ -872,6 +872,7 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
|
|||||||
int t = -1;
|
int t = -1;
|
||||||
bignum full_id;
|
bignum full_id;
|
||||||
bool onlychild = true;
|
bool onlychild = true;
|
||||||
|
bool launched = false;
|
||||||
|
|
||||||
cellwalker ycw = start;
|
cellwalker ycw = start;
|
||||||
if(for_yendor) setdist(p.path[0], 7, NULL);
|
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))];
|
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()) {
|
else if(trees_known()) {
|
||||||
auto sdist = [start] (cell *c) { return celldistance(start.at, c); };
|
auto sdist = [start] (cell *c) { return celldistance(start.at, c); };
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
@ -951,6 +983,7 @@ EX pathgen generate_random_path(cellwalker start, int length, bool for_yendor, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
stupid:
|
||||||
// stupid
|
// stupid
|
||||||
ycw += rev;
|
ycw += rev;
|
||||||
// well, make it a bit more clever on bitruncated a4 grids
|
// well, make it a bit more clever on bitruncated a4 grids
|
||||||
|
Loading…
Reference in New Issue
Block a user