Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include "Object.h"
- #include "NatureObjects.h"
- #include <map>
- #include <random>
- #include <chrono>
- #include <vector>
- typedef std::vector<std::unique_ptr<Object>> VectorObject;
- void GenerateForest(unsigned int numGen, VectorObject& vecObj ) {
- std::map<int, int> tM;
- std::map<int, int> tMplus1;
- auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
- static std::mt19937 gen(seed);
- std::uniform_int_distribution<int> uni(0, 1);
- for(unsigned int i = 0; i < 60; i++) {
- for( unsigned int j = 0; j < 80; j++ ) {
- if( uni(gen) <= 0 )
- tM[i * 80 + j] = 0;
- else
- tM[i * 80 + j] = 1;
- }
- }
- for(unsigned int i = 0; i < 60; i++)
- for( unsigned int j = 0; j < 80; j++ )
- tMplus1[i * 80 + j] = 0;
- TreeObject tO;
- int cI = 0;
- int num = 0;
- for(unsigned int i = 0; i < numGen; i++) {
- for(unsigned int i = 0; i < 60; i++) {
- for( unsigned int j = 0; j < 80; j++ ) {
- cI = i * 80 + j;
- if( i == 0 && j == 0) {
- num = tM[cI + 1] + tM[cI + 80] + tM[cI + 80 + 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if( i == 0 && j == 79) {
- num = tM[cI - 1] + tM[cI + 80 - 1] + tM[cI + 80];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if( i == 59 && j == 0) {
- num = tM[cI - 80] + tM[cI - 80 + 1] + tM[cI + 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if( i == 59 && j == 79) {
- num =tM[cI - 80 - 1] + tM[cI - 80] + tM[cI - 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if(i == 0) {
- num = tM[cI - 1] + tM[cI + 1] + tM[cI + 80 - 1]+ tM[cI + 80] + tM[cI + 80 + 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if(i == 59) {
- num = tM[cI - 80 - 1] + tM[cI - 80] + tM[cI - 80 + 1] + tM[cI - 1] + tM[cI + 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if(j == 0) {
- num = tM[cI - 80] + tM[cI - 80 + 1] + tM[cI + 1] + tM[cI + 80] + tM[cI + 80 + 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else if(j == 79) {
- num = tM[cI - 80 - 1] + tM[cI - 80] + tM[cI - 1] + tM[cI + 80 - 1] + tM[cI + 80];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- } else {
- num = tM[cI - 80 - 1 ] + tM[cI - 80] + tM[cI - 80 + 1] + tM[cI - 1] + tM[cI + 1] +
- tM[cI + 80 - 1] + tM[cI + 80] + tM[cI + 80 + 1];
- if(num < 2 || num > 3)
- tMplus1[cI] = 0;
- else if(num == 3)
- tMplus1[cI] = 1;
- else
- tMplus1[cI]= tM[cI];
- }
- }
- }
- tM = tMplus1;
- }
- TreeObject* p;
- for(unsigned int i = 0; i < 60; i++)
- for( unsigned int j = 0; j < 80; j++ ) {
- if(tMplus1[i * 80 + j] == 1) {
- p = new TreeObject;
- p->GetShape()->setPosition(i*80, j);
- vecObj.emplace_back(p);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment