Advertisement
TripleAlpha

Untitled

Dec 2nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1.  
  2. //initializes colonies matrix
  3. void populateColonies(int** colonies, int patrolSize) {
  4. int colonyPos; //will hold random int representing position of colony
  5. //iterates through each column in the colonies matrix
  6. for(int col = 0; col < SIZE; col++) {
  7. //iterates through each position in each column
  8. for(int colPos = 0; colPos < SIZE; colPos++) {
  9. //assigns each patrol's size a to a number between 1 and 10 (inc.)
  10. patrolSize = rand() % 10 + 1;
  11. colonies[col][colPos] = patrolSize;
  12. }
  13. //randomly determines position of colony and sets to 0
  14. colonyPos = rand() % 10;
  15. colonies[col][colonyPos] = 0;
  16. }
  17. }
  18.  
  19. int main () {
  20. //prints header and introduction by calling corresponding functions
  21. printHeader();
  22. printIntro();
  23.  
  24. //dynamic colonies matrix declared
  25. int** colonies = new int[SIZE][SIZE];
  26. //arrays declared iteratively within matrix to eliminate null pointers
  27. for(int col = 0; col < SIZE; col++) {
  28. colonies[col] = new int[SIZE];
  29. }
  30.  
  31. int patrolSize; //int to hold number of ants in each cell
  32. //passes colony matrix by pointer to populate it
  33. populateColonies(&colonies, patrolSize);
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement