Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <ctime>
- #include <vector>
- using namespace std;
- struct cell{
- bool hasRW;
- bool hasBW;
- int cellID;
- cell(int cellID){
- hasRW = true;
- hasBW = false;
- this->cellID = cellID;
- }
- };
- vector<vector<cell>> field;
- vector<int> idcount;
- vector<int> bottomcount;
- void draw(int x, int y){
- cout << " ";
- for(int i = 0; i < 2*x - 1; i++){
- cout << "_";
- }
- for(int j = 0; j < y; j++){
- cout << endl << "|";
- for(int i = 0; i < x; i++){
- if(field[j][i].hasRW && field[j][i].hasBW){
- cout << "_|";
- }else if(field[j][i].hasRW){
- cout << " |";
- }else if(field[j][i].hasBW){
- cout << "_ ";
- }else{
- cout << " ";
- }
- }
- for(int i = 0; i < x; i++){
- cout << " " << field[j][i].cellID << " ";
- }
- }
- }
- void gen(int x, int y){
- for(int j = 0; j < y; j++){
- vector<cell> stroka;
- for(int i = 0; i < x; i++){
- idcount[i] = 0;
- bottomcount[i] = 0;
- }
- if(j == 0){
- for(int i = 0; i < x; i++){
- cell temp(i);
- idcount[i]++;
- stroka.push_back(temp);
- }
- }else{
- stroka = field[j-1];
- for(int i = 0; i < x; i++){
- stroka[i].hasRW = false;
- if(stroka[i].hasBW){
- stroka[i].cellID = -1;
- stroka[i].hasBW = false;
- }
- }
- stroka[x-1].hasRW = true;
- int max = stroka[0].cellID;
- for(int i = 0; i < x; i++){
- if(stroka[i].cellID == -1){
- stroka[i].cellID = max + 1;
- idcount[stroka[i].cellID]++;
- max += 1;
- }
- }
- }
- for(int i = 0; i < x - 1; i++){
- if(rand() % 2 == 0 && stroka[i+1].cellID != stroka[i].cellID){
- stroka[i].hasRW = false;
- stroka[i+1].cellID = stroka[i].cellID;
- idcount[stroka[i].cellID]++;
- }else{
- stroka[i].hasRW = true;
- }
- if(rand() % 2 == 0 && idcount[stroka[i].cellID] > bottomcount[stroka[i].cellID] + 1){
- stroka[i].hasBW = true;
- bottomcount[stroka[i].cellID]++;
- }
- }
- stroka[x-1].hasRW = true;
- if(rand() % 2 == 0 && idcount[stroka[x-1].cellID] > bottomcount[stroka[x-1].cellID] + 1){
- stroka[x-1].hasBW = true;
- bottomcount[stroka[x-1].cellID]++;
- }
- field.push_back(stroka);
- }
- for(int i = 0; i < x; i++){
- field[y-1][i].hasBW = true;
- }
- /*for(int i = 0; i < x - 1; i++){
- if(field[y-1][i].cellID != field[y-1][i+1].cellID){
- field[y-1][i].hasRW = false;
- field[y-1][i+1].cellID = field[y-1][i].cellID;
- }
- }*/
- }
- int main(){
- srand(time(NULL));
- int x, y;
- cin >> x >> y;
- idcount.resize(x);
- bottomcount.resize(x);
- gen(x,y);
- draw(x,y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement