diff --git a/complex.cpp b/complex.cpp index f9c92b2c..38369652 100644 --- a/complex.cpp +++ b/complex.cpp @@ -3239,13 +3239,23 @@ namespace prairie { EX namespace ca { EX ld prob = .2; - string carule[8][2]; + static const int MAX_NEIGHBOR = 60; /* may be larger than MAX_EDGE due to mineadj */ + string carule[MAX_NEIGHBOR][2]; + + EX eWall wlive = waFloorA; + + // you can also do -mineadj + + EX string fillup(string s) { + while(isize(s) < MAX_NEIGHBOR) s += '0'; + return s; + } EX void init() { // hexagonal variant of Game of Life, as suggested by Wikipedia - for(int i=0; i<8; i++) - carule[i][0] = "00100000", - carule[i][1] = "00011000"; + for(int i=0; i 1) return 1; int nei = -1; if(args()[3]) { - nei = args()[3] - '0'; - if(nei < 0 || nei > 7) return 1; - if(args()[4]) return 1; + nei = atoi(argcs()+3); + if(nei < 0 || nei >= MAX_NEIGHBOR) return 1; } shift(); - string s = args(); s += "00000000"; - if(nei == -1) for(int i=0; i<8; i++) - carule[i][livedead] = s; + string s = args(); + if(nei == -1) for(int i=0; i& allcells = currentmap->allcells(); int dcs = isize(allcells); std::vector willlive(dcs); + int old = 0, xold = 0; for(int i=0; iland != laCA) return; int nei = 0, live = 0; - forCellEx(c2, c) if(c2->land == laCA) { - nei++; if(c2->wall == waFloorA) live++; + for(cell *c2: adj_minefield_cells(c)) { + nei++; if(c2->wall == wlive) live++; } - int welive = 0; if(c->wall == waFloorA) welive++; + int welive = 0; if(c->wall == wlive) welive++; willlive[i] = carule[nei][welive][live] == '1'; + old += welive, xold += live; } for(int i=0; iwall = willlive[i] ? waFloorA : waNone; + c->wall = willlive[i] ? wlive : waNone; } + println(hlog, tie(dcs, old, xold)); } EX } diff --git a/geom-exp.cpp b/geom-exp.cpp index d775fb93..40e78e68 100644 --- a/geom-exp.cpp +++ b/geom-exp.cpp @@ -750,7 +750,7 @@ EX void showEuclideanMenu() { }); } - if(specialland == laMinefield && geometry_has_alt_mine_rule()) { + if(among(specialland, laMinefield, laCA) && geometry_has_alt_mine_rule()) { dialog::addSelItem(XLAT("mine adjacency rule"), XLAT(mine_adjacency_rule ? "vertex" : WDIM == 3 ? "face" : "edge"), 'M'); dialog::add_action([] { stop_game(); diff --git a/help.cpp b/help.cpp index b141a699..62f70169 100644 --- a/help.cpp +++ b/help.cpp @@ -706,8 +706,10 @@ EX string generateHelpForLand(eLand l) { s += "\n\n" + XLAT(lv.msg); #if !ISMOBILE - if(l == laCA) + if(l == laCA) { + s += XLAT("\n\nOption -mineadj 1 can be added for Moore neighborhoods."); s += XLAT("\n\nHint: use 'm' to toggle cells quickly"); + } #endif return s; diff --git a/landgen.cpp b/landgen.cpp index 5bb9a2cc..614c4d1f 100644 --- a/landgen.cpp +++ b/landgen.cpp @@ -981,7 +981,7 @@ EX void giantLandSwitch(cell *c, int d, cell *from) { case laCA: if(fargen) - c->wall = (hrand(1000000) < ca::prob * 1000000) ? waFloorA : waNone; + c->wall = (hrand(1000000) < ca::prob * 1000000) ? ca::wlive : waNone; break; case laLivefjord: