Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //initializes colonies matrix
- void populateColonies(int** colonies, int patrolSize) {
- int colonyPos; //will hold random int representing position of colony
- //iterates through each column in the colonies matrix
- for(int col = 0; col < SIZE; col++) {
- //iterates through each position in each column
- for(int colPos = 0; colPos < SIZE; colPos++) {
- //assigns each patrol's size a to a number between 1 and 10 (inc.)
- patrolSize = rand() % 10 + 1;
- colonies[col][colPos] = patrolSize;
- }
- //randomly determines position of colony and sets to 0
- colonyPos = rand() % 10;
- colonies[col][colonyPos] = 0;
- }
- }
- int main () {
- //prints header and introduction by calling corresponding functions
- printHeader();
- printIntro();
- //dynamic colonies matrix declared
- int** colonies = new int[SIZE][SIZE];
- //arrays declared iteratively within matrix to eliminate null pointers
- for(int col = 0; col < SIZE; col++) {
- colonies[col] = new int[SIZE];
- }
- int patrolSize; //int to hold number of ants in each cell
- //passes colony matrix by pointer to populate it
- populateColonies(&colonies, patrolSize);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement