mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-06-07 08:54:07 +00:00
rulegen:: simplified since we know LEFT/RIGHT directions
This commit is contained in:
parent
0f0aef8dd9
commit
749b8aead6
45
rulegen.cpp
45
rulegen.cpp
@ -1115,27 +1115,15 @@ void advance(vector<branchdata>& bdata, branchdata at, int dir, bool start_forwa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map<int, branchdata> split;
|
void verify_lr(branchdata bd, int dir) {
|
||||||
|
|
||||||
void assign_lr(branchdata bd, int dir) {
|
|
||||||
if(dir) { bd.spin_full(dir); if(bd.dir == 0) bd.dir = bd.at.at->type; }
|
if(dir) { bd.spin_full(dir); if(bd.dir == 0) bd.dir = bd.at.at->type; }
|
||||||
auto& r = treestates[bd.id].rules;
|
auto& r = treestates[bd.id].rules;
|
||||||
for(int i=0; i<isize(r); i++) {
|
for(int i=0; i<isize(r); i++) {
|
||||||
if(!among(r[i], DIR_UNKNOWN, DIR_LEFT, DIR_RIGHT)) continue;
|
|
||||||
int val = i < bd.dir ? DIR_LEFT : DIR_RIGHT;
|
int val = i < bd.dir ? DIR_LEFT : DIR_RIGHT;
|
||||||
if(r[i] == DIR_UNKNOWN)
|
int wrong = val ^ DIR_LEFT ^ DIR_RIGHT;
|
||||||
r[i] = val;
|
if(r[i] == wrong)
|
||||||
else if(r[i] != val) {
|
throw rulegen_failure("assign_lr direction error");
|
||||||
if(debugflags & DF_GEOM) {
|
|
||||||
println(hlog, "state ", bd.id, " index ", i, ":", bd.dir, "/", bd.at.at->type, " was ", split[bd.id]);
|
|
||||||
println(hlog, important);
|
|
||||||
}
|
|
||||||
important.push_back(bd.at.at);
|
|
||||||
important.push_back(split[bd.id].at.at);
|
|
||||||
throw mismatch_error();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
split[bd.id] = bd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set<vector<int> > branch_hashes;
|
set<vector<int> > branch_hashes;
|
||||||
@ -1180,13 +1168,13 @@ void examine_branch(int id, int left, int right) {
|
|||||||
if(!bdata[i].temporary && !bdata[i+1].temporary && paired(bdata[i].at, bdata[i+1].at) && min(bdata[i].at.at->dist, bdata[i+1].at.at->dist) <= dist_at) {
|
if(!bdata[i].temporary && !bdata[i+1].temporary && paired(bdata[i].at, bdata[i+1].at) && min(bdata[i].at.at->dist, bdata[i+1].at.at->dist) <= dist_at) {
|
||||||
advcount++;
|
advcount++;
|
||||||
if(bdata2.size() && !bdata2.back().temporary && equiv(bdata2.back().at, bdata[i].at)) {
|
if(bdata2.size() && !bdata2.back().temporary && equiv(bdata2.back().at, bdata[i].at)) {
|
||||||
assign_lr(bdata[i], 0);
|
verify_lr(bdata[i], 0);
|
||||||
eatcount++; bdata2.pop_back();
|
eatcount++; bdata2.pop_back();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
advance(bdata2, bdata[i], -1, false, true, dist_at+dlbonus);
|
advance(bdata2, bdata[i], -1, false, true, dist_at+dlbonus);
|
||||||
if(i+2 < isize(bdata) && !bdata[i+1].temporary && !bdata[i+2].temporary && equiv(bdata[i+1].at, bdata[i+2].at)) {
|
if(i+2 < isize(bdata) && !bdata[i+1].temporary && !bdata[i+2].temporary && equiv(bdata[i+1].at, bdata[i+2].at)) {
|
||||||
assign_lr(bdata[i+1], +1);
|
verify_lr(bdata[i+1], +1);
|
||||||
eatcount++; i += 2; bdata2.push_back(bdata[i+1]);
|
eatcount++; i += 2; bdata2.push_back(bdata[i+1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1305,6 +1293,12 @@ void rules_iteration() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<isize(r); i++) if(r[i] == DIR_UNKNOWN) {
|
||||||
|
int val = treestates[id].code.second[i+1];
|
||||||
|
if(val < 2 || val >= 8) throw rulegen_failure("wrong code in gen_rule");
|
||||||
|
r[i] = ((val & 1) ? DIR_RIGHT : DIR_LEFT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// print_rules();
|
// print_rules();
|
||||||
@ -1321,13 +1315,9 @@ void rules_iteration() {
|
|||||||
if(first_live_branch == -1) first_live_branch = i;
|
if(first_live_branch == -1) first_live_branch = i;
|
||||||
if(last_live_branch >= 0)
|
if(last_live_branch >= 0)
|
||||||
examine_branch(id, last_live_branch, i);
|
examine_branch(id, last_live_branch, i);
|
||||||
else for(int a=0; a<i; a++)
|
|
||||||
if(r[a] == DIR_UNKNOWN) r[a] = DIR_LEFT;
|
|
||||||
last_live_branch = i;
|
last_live_branch = i;
|
||||||
}
|
}
|
||||||
if(treestates[id].is_root) examine_branch(id, last_live_branch, first_live_branch);
|
if(treestates[id].is_root) examine_branch(id, last_live_branch, first_live_branch);
|
||||||
for(int a=last_live_branch; a<isize(r); a++)
|
|
||||||
if(r[a] == DIR_UNKNOWN) r[a] = DIR_RIGHT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_distance_errors();
|
handle_distance_errors();
|
||||||
@ -1337,12 +1327,6 @@ void rules_iteration() {
|
|||||||
minimize_rules();
|
minimize_rules();
|
||||||
find_possible_parents();
|
find_possible_parents();
|
||||||
|
|
||||||
for(int id=0; id<isize(treestates); id++) {
|
|
||||||
auto& ts = treestates[id];
|
|
||||||
for(auto& r: ts.rules) if(r == DIR_UNKNOWN)
|
|
||||||
throw rulegen_failure("UNKNOWN remaining");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isize(important) != N)
|
if(isize(important) != N)
|
||||||
throw mismatch_error();
|
throw mismatch_error();
|
||||||
handle_distance_errors();
|
handle_distance_errors();
|
||||||
@ -1359,13 +1343,13 @@ void clear_tcell_data() {
|
|||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
for(auto& c: t_origin) c->dist = 0;
|
for(auto& c: t_origin) c->dist = 0;
|
||||||
|
in_fixing = false; fix_queue = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup() {
|
void cleanup() {
|
||||||
clear_tcell_data();
|
clear_tcell_data();
|
||||||
analyzers.clear();
|
analyzers.clear();
|
||||||
code_to_id.clear();
|
code_to_id.clear();
|
||||||
split.clear();
|
|
||||||
important.clear();
|
important.clear();
|
||||||
shortcuts.clear();
|
shortcuts.clear();
|
||||||
}
|
}
|
||||||
@ -1408,7 +1392,6 @@ EX void generate_rules() {
|
|||||||
clear_all();
|
clear_all();
|
||||||
|
|
||||||
analyzers.clear();
|
analyzers.clear();
|
||||||
split.clear();
|
|
||||||
|
|
||||||
t_origin.clear();
|
t_origin.clear();
|
||||||
for(auto& ts: arb::current.shapes) {
|
for(auto& ts: arb::current.shapes) {
|
||||||
@ -1537,8 +1520,6 @@ struct hrmap_rulegen : hrmap {
|
|||||||
hsconnect(hs, hs1);
|
hsconnect(hs, hs1);
|
||||||
return h1;
|
return h1;
|
||||||
}
|
}
|
||||||
else if(r == DIR_UNKNOWN)
|
|
||||||
throw rulegen_failure("UNKNOWN rule remained");
|
|
||||||
else if(r == DIR_MULTI_GO_LEFT) {
|
else if(r == DIR_MULTI_GO_LEFT) {
|
||||||
// hs = (hs - 1) + wstep;
|
// hs = (hs - 1) + wstep;
|
||||||
hsconnect(hs, hs - 1 + wstep - 1);
|
hsconnect(hs, hs - 1 + wstep - 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user