Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Represents taking one step in a random direction. If the step would be outside of the board
- /// the ant reevaluates that decision by generating a new random number.
- /// <param name="&x">The address of the value for the x-axis.</param>
- /// <param name="&y">The address of the value for the y-axis.</param>
- /// <param name="&stepsTaken">The address of the value for number of total steps taken.</param>
- /// </summary>
- void takeStep(int &x, int &y, int &stepsTaken)
- {
- int step;
- int *axis;
- do
- {
- step = getRandomNumber(1, 4);
- if(step % 2 == 1) //I.e., step was 1 or 3
- {
- step -= 2; //step will now be -1 or 1
- axis = &x;
- }
- else
- {
- step -= 3; //step will now be -1 or 1
- axis = &y;
- }
- } while (*axis + step < 0 || *axis + step >= BOARD_SIZE);
- *axis += step;
- stepsTaken++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement