Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(int k = 0; k < 1000; k++) { // loop to perform walks.
- direction = (rand() % 8);
- switch(direction) {
- // north.
- case 0:
- if((map[currentRow][currentColumn] == 'B') && (rowNum = 0)) { // if at row 0 (top) and on bridge and going north = success, end walk.
- numSuccess[rowNum][colNum] += 1;
- totalPathLength[rowNum][colNum] += tempPathLength; // sets total path length for the specified cell's walks (successful) to previous value + tempPathLength.
- indivPaths[element][pathNum] = tempPathLength; // stores individual path lengths.
- pathNum += 1; // changes array location to store a new individual path.
- currentRow = rowNum; // resets row and column to original cell.
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- if (map[currentRow-1][currentColumn] == 'L') { // if next step is onto land then continue walk +1 to path length.
- tempPathLength += 1;
- currentRow -= 1; // currentRow -1 makes the next cell the program looks become the one above the previous.
- goto endcase;
- }
- if ((map[currentRow-1][currentColumn] == 'D') || (map[currentRow-1][currentColumn] == 'V') || (map[currentRow-1][currentColumn] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell above is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0; // sets tempPathLength back to zero after a fail (and success).
- goto endcase;
- }
- break;
- // north-east.
- case 1:
- if((map[currentRow][currentColumn] == 'B') && ((rowNum = 0) || (colNum = 8))) { // If current cell is a B and is on top or right of map = success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- pathNum += 1;
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase; // break out of case structure.
- }
- if (map[currentRow-1][currentColumn+1] == 'L') {
- tempPathLength += 1;
- currentRow -= 1;
- currentColumn += 1;
- goto endcase;
- }
- if ((map[currentRow-1][currentColumn+1] == 'D') || (map[currentRow-1][currentColumn+1] == 'V') || (map[currentRow-1][currentColumn+1] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell above and to the right is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- break;
- // east.
- case 2:
- if((map[currentRow][currentColumn] == 'B') && (colNum = 8)) { // If current cell is B and on the right side of map then success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- pathNum += 1;
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase; // break out of case structure.
- }
- if (map[currentRow][currentColumn+1] == 'L') {
- tempPathLength += 1;
- currentColumn += 1;
- goto endcase;
- }
- if ((map[currentRow][currentColumn+1] == 'D') || (map[currentRow][currentColumn+1] == 'V') || (map[currentRow][currentColumn+1] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell to the right is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- break;
- // south-east.
- case 3:
- if((map[currentRow][currentColumn] == 'B') && ((rowNum = 8) || (colNum = 8))) { // If current cell is B and if both or either row = 8 or column = 8 then success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- pathNum += 1;
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase; // break out of case structure.
- }
- if (map[currentRow+1][currentColumn+1] == 'L') {
- tempPathLength += 1;
- currentRow += 1;
- currentColumn += 1;
- goto endcase;
- }
- if ((map[currentRow+1][currentColumn+1] == 'D') || (map[currentRow+1][currentColumn+1] == 'V') || (map[currentRow+1][currentColumn+1] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell below and to the right is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- break;
- // south.
- case 4:
- if((map[currentRow][currentColumn] == 'B') && (rowNum = 8)) { // If current cell is B and if row = 8 then success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength= 0;
- goto endcase; // break out of case structure.
- }
- if (map[currentRow+1][currentColumn] == 'L') {
- tempPathLength += 1;
- currentRow += 1;
- goto endcase;
- }
- if ((map[currentRow+1][currentColumn] == 'D') || (map[currentRow+1][currentColumn] == 'V') || (map[currentRow+1][currentColumn] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell below is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- break;
- // south-west.
- case 5:
- if((map[currentRow][currentColumn] == 'B') && ((rowNum = 8) || (colNum = 0))) { // If current cell is B and if both or either row = 8 or column = 0 then success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- pathNum += 1;
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase; // break out of case structure.
- }
- if (map[currentRow+1][currentColumn-1] == 'L') {
- tempPathLength += 1;
- currentRow += 1;
- currentColumn -= 1;
- goto endcase;
- }
- if ((map[currentRow+1][currentColumn-1] == 'D') || (map[currentRow+1][currentColumn-1] == 'V') || (map[currentRow+1][currentColumn-1] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell below and to the left and to the right is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- break;
- // west.
- case 6:
- if((map[currentRow][currentColumn] == 'B') && (colNum = 0)) { // If current cell is B and if column = 0 then success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- pathNum += 1;
- currentRow = rowNum;
- currentColumn = colNum;
- goto endcase; // break out of case structure.
- }
- if (map[currentRow][currentColumn-1] == 'L') {
- tempPathLength += 1;
- currentColumn -= 1;
- goto endcase;
- }
- if ((map[currentRow][currentColumn-1] == 'D') || (map[currentRow][currentColumn-1] == 'V') || (map[currentRow][currentColumn-1] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell to the left is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- break;
- // north-west.
- case 7:
- if((map[currentRow][currentColumn] == 'B') && ((rowNum = 0) || (colNum = 0))) { // If current cell is B and if both or either row = 0 or column = 0 then success.
- numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
- totalPathLength[rowNum][colNum] += tempPathLength;
- indivPaths[element][pathNum] = tempPathLength;
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- if (map[currentRow-1][currentColumn-1] == 'L') {
- tempPathLength += 1;
- currentRow -= 1;
- currentColumn -= 1;
- goto endcase;
- }
- if ((map[currentRow-1][currentColumn-1] == 'D') || (map[currentRow-1][currentColumn-1] == 'V') || (map[currentRow-1][currentColumn-1] == 'W')) {
- numFail[rowNum][colNum] += 1; // if the next cell up and to the left is a D V or W then walk failed, return to original cell.
- currentRow = rowNum;
- currentColumn = colNum;
- tempPathLength = 0;
- goto endcase;
- }
- endcase:
- break;
- }
- }
- element += 1;
- colNum += 1;
- pathNum = 0;
- }
- colNum = 0;
- rowNum += 1;
- pathNum = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement