fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. struct Point
  5. {
  6. int x;
  7. int y;
  8. bool isAlive;
  9. };
  10. std::vector<Point> gameBoard;
  11. std::vector<Point> bufferGirlNextDoor;
  12. std::vector<Point> bufferNewBorn;
  13.  
  14. void checkNumForBorn(Point);
  15. void checkNumForDead(Point&);
  16. void checkGirlNextDoor(Point);
  17. void createGameBoard()
  18. {
  19. gameBoard.push_back(Point{ 0,0,true });
  20. gameBoard.push_back(Point{ 1,0,true });
  21. gameBoard.push_back(Point{ 2,0,true });
  22. }
  23.  
  24. void mainLoop()
  25. {
  26. createGameBoard();
  27. while (true)
  28. {
  29. bufferNewBorn.clear();
  30. for each (Point p in gameBoard)
  31. {
  32. checkGirlNextDoor(p);
  33. checkNumForBorn(Point{ p.x-1, p.y, true });
  34. checkNumForBorn(Point{ p.x-1, p.y+1, true });
  35. checkNumForBorn(Point{ p.x, p.y+1, true });
  36. checkNumForBorn(Point{ p.x+1, p.y+1, true });
  37. checkNumForBorn(Point{ p.x+1, p.y, true });
  38. checkNumForBorn(Point{ p.x+1, p.y-1, true });
  39. checkNumForBorn(Point{ p.x, p.y-1, true });
  40. checkNumForBorn(Point{ p.x-1, p.y-1, true });
  41. checkNumForDead(p);
  42. }
  43. for each (Point p in gameBoard)
  44. {
  45. if (p.isAlive) bufferNewBorn.push_back(p);
  46. }
  47. gameBoard.clear();
  48. gameBoard = bufferNewBorn;
  49. std::cout << gameBoard.size() << std::endl;
  50. }
  51. }
  52. void checkNumForBorn(Point currentPoint)
  53. {
  54. int num = 0;
  55. bool isGirlNextDoor = false;
  56. for each (Point p in bufferGirlNextDoor)
  57. {
  58. if (p.x == currentPoint.x && p.y == currentPoint.y)
  59. {
  60. isGirlNextDoor = true;
  61. break;
  62. }
  63. }
  64. if (!isGirlNextDoor)
  65. {
  66. for each (Point p in bufferGirlNextDoor)
  67. {
  68. if (p.x > currentPoint.x - 2 && p.x < currentPoint.x + 2 && p.y > currentPoint.y - 2 && p.y < currentPoint.y + 2)
  69. ++num;
  70. //добавить после тестов if (num > 2) break;
  71. }
  72. }
  73. if (num > 2) bufferNewBorn.push_back(currentPoint);
  74. }
  75. void checkNumForDead(Point &currentPoint)
  76. {
  77. int num = 0;
  78. for each (Point p in bufferGirlNextDoor)
  79. {
  80. if (p.x > currentPoint.x - 2 && p.x < currentPoint.x + 2 && p.y > currentPoint.y - 2 && p.y < currentPoint.y + 2 && p.x != currentPoint.x && p.y != currentPoint.y)
  81. ++num;
  82. //добавить после тестов if (num > 3) break;
  83. }
  84. if (num < 2 || num > 3) currentPoint.isAlive = false;
  85. }
  86. void checkGirlNextDoor(Point currentPoint)
  87. {
  88. bufferGirlNextDoor.clear();
  89. for each(Point p in gameBoard)
  90. {
  91. if (p.x > currentPoint.x - 3 && p.x < currentPoint.x + 3 && p.y > currentPoint.y - 3 && p.y < currentPoint.y + 3 && p.x != currentPoint.x && p.y != currentPoint.y)
  92. bufferGirlNextDoor.push_back(p);
  93. }
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void mainLoop()’:
prog.cpp:30:7: error: expected ‘(’ before ‘each’
   for each (Point p in gameBoard)
       ^~~~
       (
prog.cpp:30:19: error: expected primary-expression before ‘p’
   for each (Point p in gameBoard)
                   ^
prog.cpp:30:7: error: ‘each’ was not declared in this scope
   for each (Point p in gameBoard)
       ^~~~
prog.cpp:43:3: error: expected primary-expression before ‘for’
   for each (Point p in gameBoard)
   ^~~
prog.cpp:42:4: error: expected ‘;’ before ‘for’
   }
    ^
    ;
   for each (Point p in gameBoard)
   ~~~
prog.cpp:43:3: error: expected primary-expression before ‘for’
   for each (Point p in gameBoard)
   ^~~
prog.cpp:42:4: error: expected ‘)’ before ‘for’
   }
    ^
    )
   for each (Point p in gameBoard)
   ~~~
prog.cpp:30:7: note: to match this ‘(’
   for each (Point p in gameBoard)
       ^~~~
prog.cpp:43:7: error: expected ‘(’ before ‘each’
   for each (Point p in gameBoard)
       ^~~~
       (
prog.cpp:43:19: error: expected primary-expression before ‘p’
   for each (Point p in gameBoard)
                   ^
prog.cpp:47:18: error: could not convert ‘gameBoard.std::vector<Point>::clear()’ from ‘void’ to ‘bool’
   gameBoard.clear();
   ~~~~~~~~~~~~~~~^~
prog.cpp:48:28: error: expected ‘)’ before ‘;’ token
   gameBoard = bufferNewBorn;
                            ^
                            )
prog.cpp:43:7: note: to match this ‘(’
   for each (Point p in gameBoard)
       ^~~~
prog.cpp: In function ‘void checkNumForBorn(Point)’:
prog.cpp:56:6: error: expected ‘(’ before ‘each’
  for each (Point p in bufferGirlNextDoor)
      ^~~~
      (
prog.cpp:56:18: error: expected primary-expression before ‘p’
  for each (Point p in bufferGirlNextDoor)
                  ^
prog.cpp:56:6: error: ‘each’ was not declared in this scope
  for each (Point p in bufferGirlNextDoor)
      ^~~~
prog.cpp:64:2: error: expected primary-expression before ‘if’
  if (!isGirlNextDoor)
  ^~
prog.cpp:63:3: error: expected ‘;’ before ‘if’
  }
   ^
   ;
  if (!isGirlNextDoor)
  ~~
prog.cpp:64:2: error: expected primary-expression before ‘if’
  if (!isGirlNextDoor)
  ^~
prog.cpp:63:3: error: expected ‘)’ before ‘if’
  }
   ^
   )
  if (!isGirlNextDoor)
  ~~
prog.cpp:56:6: note: to match this ‘(’
  for each (Point p in bufferGirlNextDoor)
      ^~~~
prog.cpp:66:7: error: expected ‘(’ before ‘each’
   for each (Point p in bufferGirlNextDoor)
       ^~~~
       (
prog.cpp:66:19: error: expected primary-expression before ‘p’
   for each (Point p in bufferGirlNextDoor)
                   ^
prog.cpp:72:2: error: expected primary-expression before ‘}’ token
  }
  ^
prog.cpp:71:4: error: expected ‘;’ before ‘}’ token
   }
    ^
    ;
  }
  ~  
prog.cpp:72:2: error: expected primary-expression before ‘}’ token
  }
  ^
prog.cpp:71:4: error: expected ‘)’ before ‘}’ token
   }
    ^
    )
  }
  ~  
prog.cpp:66:7: note: to match this ‘(’
   for each (Point p in bufferGirlNextDoor)
       ^~~~
prog.cpp:72:2: error: expected primary-expression before ‘}’ token
  }
  ^
prog.cpp: In function ‘void checkNumForDead(Point&)’:
prog.cpp:78:6: error: expected ‘(’ before ‘each’
  for each (Point p in bufferGirlNextDoor)
      ^~~~
      (
prog.cpp:78:18: error: expected primary-expression before ‘p’
  for each (Point p in bufferGirlNextDoor)
                  ^
prog.cpp:78:6: error: ‘each’ was not declared in this scope
  for each (Point p in bufferGirlNextDoor)
      ^~~~
prog.cpp:84:2: error: expected primary-expression before ‘if’
  if (num < 2 || num > 3) currentPoint.isAlive = false;
  ^~
prog.cpp:83:3: error: expected ‘;’ before ‘if’
  }
   ^
   ;
  if (num < 2 || num > 3) currentPoint.isAlive = false;
  ~~
prog.cpp:84:2: error: expected primary-expression before ‘if’
  if (num < 2 || num > 3) currentPoint.isAlive = false;
  ^~
prog.cpp:83:3: error: expected ‘)’ before ‘if’
  }
   ^
   )
  if (num < 2 || num > 3) currentPoint.isAlive = false;
  ~~
prog.cpp:78:6: note: to match this ‘(’
  for each (Point p in bufferGirlNextDoor)
      ^~~~
prog.cpp: In function ‘void checkGirlNextDoor(Point)’:
prog.cpp:89:6: error: expected ‘(’ before ‘each’
  for each(Point p in gameBoard)
      ^~~~
      (
prog.cpp:89:17: error: expected primary-expression before ‘p’
  for each(Point p in gameBoard)
                 ^
prog.cpp:89:6: error: ‘each’ was not declared in this scope
  for each(Point p in gameBoard)
      ^~~~
prog.cpp:94:1: error: expected primary-expression before ‘}’ token
 }
 ^
prog.cpp:93:3: error: expected ‘;’ before ‘}’ token
  }
   ^
   ;
 }
 ~  
prog.cpp:94:1: error: expected primary-expression before ‘}’ token
 }
 ^
prog.cpp:93:3: error: expected ‘)’ before ‘}’ token
  }
   ^
   )
 }
 ~  
prog.cpp:89:6: note: to match this ‘(’
  for each(Point p in gameBoard)
      ^~~~
prog.cpp:94:1: error: expected primary-expression before ‘}’ token
 }
 ^
stdout
Standard output is empty