1. // Draft of the game of life
  2. #include <iostream>
  3. using namespace std;
  4. char world[10] [10];
  5. int a = 0;
  6. int xSeed[256]; //Initiating the variable that will get the user input for the X coordinate of the Seed
  7. int ySeed[256]; //Same as the xSeed, except for the y coordinate
  8. int Seeds; //Initiating the variable that will tell me how high I will have to list upwards in the array
  9. int neighbors; //Used in the function birth to count how many neighbors a cell has
  10. char var2[4]; //Variable used to enter another seed, only will be used once.
  11. //Creating function that will print the gameboard onto the screen.
  12. int gameboard(){ // Making the gameboard. Helped to learn about line continuation :P
  13. cout << "\n__| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10" << \
  14. "\n1 | " << world[1] [1] << " " << world[2] [1] << " " << world[3] [1] << " " << world[4] [1] << " " << world[5] [1] << " " << world[6] [1] << " " << world[7] [1] << " " << world[8] [1] << " " << world[9] [1] << " " << world[10] [1] << \
  15. "\n2 | " << world[1] [2] << " " << world[2] [2] << " " << world[3] [2] << " " << world[4] [2] << " " << world[5] [2] << " " << world[6] [2] << " " << world[7] [2] << " " << world[8] [2] << " " << world[9] [2] << " " << world[10] [2] << \
  16. "\n3 | " << world[1] [3] << " " << world[2] [3] << " " << world[3] [3] << " " << world[4] [3] << " " << world[5] [3] << " " << world[6] [3] << " " << world[7] [3] << " " << world[8] [3] << " " << world[9] [3] << " " << world[10] [3] << \
  17. "\n4 | " << world[1] [4] << " " << world[2] [4] << " " << world[3] [4] << " " << world[4] [4] << " " << world[5] [4] << " " << world[6] [4] << " " << world[7] [4] << " " << world[8] [4] << " " << world[9] [4] << " " << world[10] [4] << \
  18. "\n5 | " << world[1] [5] << " " << world[2] [5] << " " << world[3] [5] << " " << world[4] [5] << " " << world[5] [5] << " " << world[6] [5] << " " << world[7] [5] << " " << world[8] [5] << " " << world[9] [5] << " " << world[10] [5] << \
  19. "\n6 | " << world[1] [6] << " " << world[2] [6] << " " << world[3] [6] << " " << world[4] [6] << " " << world[5] [6] << " " << world[6] [6] << " " << world[7] [6] << " " << world[8] [6] << " " << world[9] [6] << " " << world[10] [6] << \
  20. "\n7 | " << world[1] [7] << " " << world[2] [7] << " " << world[3] [7] << " " << world[4] [7] << " " << world[5] [7] << " " << world[6] [7] << " " << world[7] [7] << " " << world[8] [7] << " " << world[9] [7] << " " << world[10] [7] << \
  21. "\n8 | " << world[1] [8] << " " << world[2] [8] << " " << world[3] [8] << " " << world[4] [8] << " " << world[5] [8] << " " << world[6] [8] << " " << world[7] [8] << " " << world[8] [8] << " " << world[9] [8] << " " << world[10] [8] << \
  22. "\n9 | " << world[1] [9] << " " << world[2] [9] << " " << world[3] [9] << " " << world[4] [9] << " " << world[5] [9] << " " << world[6] [9] << " " << world[7] [9] << " " << world[8] [9] << " " << world[9] [9] << " " << world[10] [9] << \
  23. "\n10| " << world[1] [10] << " " << world[2] [10] << " " << world[3] [10] << " " << world[4] [20] << " " << world[5] [10] << " " << world[6] [10] << " " << world[7] [10] << " " << world[8] [10] << " " << world[9] [10] << " " << world[10] [10];
  24. return 0; // Returning a vaulue to the function to signify that the function ran without a hitch
  25. }
  26. //Creating a function that places the cells on the board
  27. int cells(){
  28. for(int a=0; a != 11; a++){
  29. world[a] [1] = '-'; // This changes every cell on the x axis on the 1 y coordinate to '-'
  30. }
  31. for(int b=0; b != 11; b++){
  32. int inc = 0;
  33. inc++;
  34. world[inc] [b] = '-'; // InC increases the X coordinate, while B stays on the same Y coordinate, changing the whole line to a dash
  35. inc++;
  36. world[inc] [b] = '-'; // Same as before comment
  37. inc++;
  38. world[inc] [b] = '-';
  39. inc++;
  40. world[inc] [b] = '-';
  41. inc++;
  42. world[inc] [b] = '-';
  43. inc++;
  44. world[inc] [b] = '-';
  45. inc++;
  46. world[inc] [b] = '-';
  47. inc++;
  48. world[inc] [b] = '-';
  49. inc++;
  50. world[inc] [b] = '-';
  51. inc++;
  52. world[inc] [b] = '-';
  53. }
  54. return 0; //Returning a value to the function to signify that the function ran without a problem
  55. }
  56. //Creating function that allows the user to create seed cells.
  57. int seeds(){
  58. cout << "\n\nHow many seed cells would you wish to have? ";
  59. cin >> Seeds;
  60. cout << "\n\nPlease enter the X and Y coordinates for the seed.";
  61. cout << "\nX: ";
  62. cin >> xSeed[1];
  63. cout << "\nY: ";
  64. cin >> ySeed[1];
  65. int SeedY = 1;
  66. int q=1;
  67. while(SeedY != Seeds){
  68. SeedY++;
  69. q++;
  70. if(q <= Seeds){
  71. cout << "\n\nPlease enter the X and Y coordinates for the seed.";
  72. cout << "\nX: ";
  73. cin >> xSeed[q];
  74. cout << "\nY: ";
  75. cin >> ySeed[q];
  76. }
  77. }
  78. int q2 = q; //Alright, variable q is the number of seeds there are in the arrays in the variables xSeed and ySeed, this just assigns that number to a new variable.
  79. q = 0;
  80. while(q2 != 0){ //Finnally found a way to change all the seed cells to alive on the gameboard, and let the user chose how many he wants!
  81. world[xSeed[q2]] [ySeed[q2]] = '+';
  82. q2--;
  83. }
  84. return 0;
  85. }
  86. // Function that creates the neighbors of the seed cells :P
  87. int birth(){
  88. for (int m = 0; m < 11; m++){ //This will start at 1, making the Y coordinate 1, and will increase each time
  89. for (int n = 0; n < 11; n++){ //When the first for loop executes, this one will execute, making the X coordinate 1, and will increase once each thru unctil it is 10.
  90. if(world[m] [n] == '-'){ //This checks if a cell (ex. 1,1) is dead, if so it checks if surrounding cells are alive
  91. if(world[m++] [n] == '+'){ //Check if 2,1 is alive, if so move on
  92. neighbors++;
  93. }
  94. if(world[m] [n++] == '+'){ //Check if 1,2 is alive if so, make 2,2 alive.
  95. neighbors++;
  96. }
  97. if(world[m--] [n] == '+'){
  98. neighbors++;
  99. }
  100. else if(world[m] [n--] == '+'){
  101. neighbors++;
  102. }
  103. else if(world [m++] [n++] == '+'){
  104. neighbors++;
  105. }
  106. else if(world [m--] [n--] == '+'){
  107. neighbors++;
  108. }
  109. else if(world [m++] [n--] == '+'){
  110. neighbors++;
  111. }
  112. else if(world [n--] [m++] == '+'){
  113. neighbors++;
  114. }
  115. else{
  116. cout << "";
  117. }
  118. }
  119. if(neighbors == 3){
  120. world[m] [n] = '+';
  121. neighbors = 0;
  122. }
  123. }
  124. }
  125. }
  126. int main(){
  127. cells(); //Assigning values to world[] []
  128. gameboard(); //Prints gameboard to screen
  129. seeds();//Allows user to be prompted for seed coordinates
  130. cout << "\n\nInput (Seed Cells)\n";
  131. gameboard();
  132. birth();
  133. cout << "\n\nOutput\n";
  134. gameboard();
  135. cin.sync();
  136. cin.get();
  137. return 0;
  138. }