Habsburg

Untitled

Oct 19th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3. #include "Object.h"
  4. #include "NatureObjects.h"
  5. #include <map>
  6. #include <random>
  7. #include <chrono>
  8. #include <vector>
  9. typedef std::vector<std::unique_ptr<Object>> VectorObject;
  10.  
  11. void GenerateForest(unsigned int numGen, VectorObject& vecObj ) {
  12. std::map<int, int> tM;
  13. std::map<int, int> tMplus1;
  14.  
  15. auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
  16. static std::mt19937 gen(seed);
  17. std::uniform_int_distribution<int> uni(0, 1);
  18.  
  19. for(unsigned int i = 0; i < 60; i++) {
  20. for( unsigned int j = 0; j < 80; j++ ) {
  21. if( uni(gen) <= 0 )
  22. tM[i * 80 + j] = 0;
  23. else
  24. tM[i * 80 + j] = 1;
  25. }
  26. }
  27.  
  28. for(unsigned int i = 0; i < 60; i++)
  29. for( unsigned int j = 0; j < 80; j++ )
  30. tMplus1[i * 80 + j] = 0;
  31.  
  32. TreeObject tO;
  33.  
  34. int cI = 0;
  35. int num = 0;
  36.  
  37. for(unsigned int i = 0; i < numGen; i++) {
  38. for(unsigned int i = 0; i < 60; i++) {
  39. for( unsigned int j = 0; j < 80; j++ ) {
  40. cI = i * 80 + j;
  41. if( i == 0 && j == 0) {
  42. num = tM[cI + 1] + tM[cI + 80] + tM[cI + 80 + 1];
  43. if(num < 2 || num > 3)
  44. tMplus1[cI] = 0;
  45. else if(num == 3)
  46. tMplus1[cI] = 1;
  47. else
  48. tMplus1[cI]= tM[cI];
  49. } else if( i == 0 && j == 79) {
  50. num = tM[cI - 1] + tM[cI + 80 - 1] + tM[cI + 80];
  51. if(num < 2 || num > 3)
  52. tMplus1[cI] = 0;
  53. else if(num == 3)
  54. tMplus1[cI] = 1;
  55. else
  56. tMplus1[cI]= tM[cI];
  57.  
  58. } else if( i == 59 && j == 0) {
  59. num = tM[cI - 80] + tM[cI - 80 + 1] + tM[cI + 1];
  60. if(num < 2 || num > 3)
  61. tMplus1[cI] = 0;
  62. else if(num == 3)
  63. tMplus1[cI] = 1;
  64. else
  65. tMplus1[cI]= tM[cI];
  66.  
  67. } else if( i == 59 && j == 79) {
  68. num =tM[cI - 80 - 1] + tM[cI - 80] + tM[cI - 1];
  69. if(num < 2 || num > 3)
  70. tMplus1[cI] = 0;
  71. else if(num == 3)
  72. tMplus1[cI] = 1;
  73. else
  74. tMplus1[cI]= tM[cI];
  75.  
  76. } else if(i == 0) {
  77. num = tM[cI - 1] + tM[cI + 1] + tM[cI + 80 - 1]+ tM[cI + 80] + tM[cI + 80 + 1];
  78. if(num < 2 || num > 3)
  79. tMplus1[cI] = 0;
  80. else if(num == 3)
  81. tMplus1[cI] = 1;
  82. else
  83. tMplus1[cI]= tM[cI];
  84.  
  85. } else if(i == 59) {
  86. num = tM[cI - 80 - 1] + tM[cI - 80] + tM[cI - 80 + 1] + tM[cI - 1] + tM[cI + 1];
  87. if(num < 2 || num > 3)
  88. tMplus1[cI] = 0;
  89. else if(num == 3)
  90. tMplus1[cI] = 1;
  91. else
  92. tMplus1[cI]= tM[cI];
  93.  
  94. } else if(j == 0) {
  95. num = tM[cI - 80] + tM[cI - 80 + 1] + tM[cI + 1] + tM[cI + 80] + tM[cI + 80 + 1];
  96. if(num < 2 || num > 3)
  97. tMplus1[cI] = 0;
  98. else if(num == 3)
  99. tMplus1[cI] = 1;
  100. else
  101. tMplus1[cI]= tM[cI];
  102.  
  103. } else if(j == 79) {
  104. num = tM[cI - 80 - 1] + tM[cI - 80] + tM[cI - 1] + tM[cI + 80 - 1] + tM[cI + 80];
  105. if(num < 2 || num > 3)
  106. tMplus1[cI] = 0;
  107. else if(num == 3)
  108. tMplus1[cI] = 1;
  109. else
  110. tMplus1[cI]= tM[cI];
  111.  
  112. } else {
  113. num = tM[cI - 80 - 1 ] + tM[cI - 80] + tM[cI - 80 + 1] + tM[cI - 1] + tM[cI + 1] +
  114. tM[cI + 80 - 1] + tM[cI + 80] + tM[cI + 80 + 1];
  115. if(num < 2 || num > 3)
  116. tMplus1[cI] = 0;
  117. else if(num == 3)
  118. tMplus1[cI] = 1;
  119. else
  120. tMplus1[cI]= tM[cI];
  121. }
  122. }
  123. }
  124. tM = tMplus1;
  125. }
  126. TreeObject* p;
  127. for(unsigned int i = 0; i < 60; i++)
  128. for( unsigned int j = 0; j < 80; j++ ) {
  129. if(tMplus1[i * 80 + j] == 1) {
  130. p = new TreeObject;
  131. p->GetShape()->setPosition(i*80, j);
  132. vecObj.emplace_back(p);
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment