Percolation/Bond percolation: Difference between revisions

Content added Content deleted
(C++ version)
(C++ version enhanced)
Line 166: Line 166:
#include <iostream>
#include <iostream>
#include <string>
#include <string>

// cell states:
enum {
FILL = 1,
RWALL = 2, // right wall
BWALL = 4 // bottom wall
};


using namespace std;
using namespace std;
Line 186: Line 179:
cells = start + m;
cells = start + m;
for (auto i = 0u; i < m; i++)
for (auto i = 0u; i < m; i++)
start[i] = BWALL | RWALL;
start[i] = RBWALL;


end = cells;
end = cells;
Line 231: Line 224:


private:
private:
enum cell_state {
FILL = 1 << 0,
RWALL = 1 << 1, // right wall
BWALL = 1 << 2, // bottom wall
RBWALL = RWALL | BWALL // right/bottom wall
};

typedef unsigned int cell;
typedef unsigned int cell;


Line 239: Line 239:


return (!(p[0] & BWALL) && fill(p + m)) || (!(p[0] & RWALL) && fill(p + 1)) ||
return (!(p[0] & BWALL) && fill(p + m)) || (!(p[0] & RWALL) && fill(p + 1)) ||
(!(p[-1] & RWALL) && fill(p - 1)) || (!(p[0-m] & BWALL) && fill(p - m));
(!(p[-1] & RWALL) && fill(p - 1)) || (!(p[0 - m] & BWALL) && fill(p - m));
}
}