Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. for(int k = 0; k < 1000; k++) { // loop to perform walks.
  2.  
  3. direction = (rand() % 8);
  4.  
  5. switch(direction) {
  6.  
  7. // north.
  8. case 0:
  9. if((map[currentRow][currentColumn] == 'B') && (rowNum = 0)) { // if at row 0 (top) and on bridge and going north = success, end walk.
  10. numSuccess[rowNum][colNum] += 1;
  11. totalPathLength[rowNum][colNum] += tempPathLength; // sets total path length for the specified cell's walks (successful) to previous value + tempPathLength.
  12. indivPaths[element][pathNum] = tempPathLength; // stores individual path lengths.
  13. pathNum += 1; // changes array location to store a new individual path.
  14. currentRow = rowNum; // resets row and column to original cell.
  15. currentColumn = colNum;
  16. tempPathLength = 0;
  17. goto endcase;
  18. }
  19. if (map[currentRow-1][currentColumn] == 'L') { // if next step is onto land then continue walk +1 to path length.
  20. tempPathLength += 1;
  21. currentRow -= 1; // currentRow -1 makes the next cell the program looks become the one above the previous.
  22. goto endcase;
  23. }
  24. if ((map[currentRow-1][currentColumn] == 'D') || (map[currentRow-1][currentColumn] == 'V') || (map[currentRow-1][currentColumn] == 'W')) {
  25. numFail[rowNum][colNum] += 1; // if the next cell above is a D V or W then walk failed, return to original cell.
  26. currentRow = rowNum;
  27. currentColumn = colNum;
  28. tempPathLength = 0; // sets tempPathLength back to zero after a fail (and success).
  29. goto endcase;
  30. }
  31.  
  32. break;
  33.  
  34. // north-east.
  35. case 1:
  36. if((map[currentRow][currentColumn] == 'B') && ((rowNum = 0) || (colNum = 8))) { // If current cell is a B and is on top or right of map = success.
  37. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  38. totalPathLength[rowNum][colNum] += tempPathLength;
  39. indivPaths[element][pathNum] = tempPathLength;
  40. pathNum += 1;
  41. currentRow = rowNum;
  42. currentColumn = colNum;
  43. tempPathLength = 0;
  44. goto endcase; // break out of case structure.
  45. }
  46. if (map[currentRow-1][currentColumn+1] == 'L') {
  47. tempPathLength += 1;
  48. currentRow -= 1;
  49. currentColumn += 1;
  50. goto endcase;
  51. }
  52. if ((map[currentRow-1][currentColumn+1] == 'D') || (map[currentRow-1][currentColumn+1] == 'V') || (map[currentRow-1][currentColumn+1] == 'W')) {
  53. 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.
  54. currentRow = rowNum;
  55. currentColumn = colNum;
  56. tempPathLength = 0;
  57. goto endcase;
  58. }
  59.  
  60. break;
  61.  
  62. // east.
  63. case 2:
  64. if((map[currentRow][currentColumn] == 'B') && (colNum = 8)) { // If current cell is B and on the right side of map then success.
  65. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  66. totalPathLength[rowNum][colNum] += tempPathLength;
  67. indivPaths[element][pathNum] = tempPathLength;
  68. pathNum += 1;
  69. currentRow = rowNum;
  70. currentColumn = colNum;
  71. tempPathLength = 0;
  72. goto endcase; // break out of case structure.
  73. }
  74. if (map[currentRow][currentColumn+1] == 'L') {
  75. tempPathLength += 1;
  76. currentColumn += 1;
  77. goto endcase;
  78. }
  79. if ((map[currentRow][currentColumn+1] == 'D') || (map[currentRow][currentColumn+1] == 'V') || (map[currentRow][currentColumn+1] == 'W')) {
  80. numFail[rowNum][colNum] += 1; // if the next cell to the right is a D V or W then walk failed, return to original cell.
  81. currentRow = rowNum;
  82. currentColumn = colNum;
  83. tempPathLength = 0;
  84. goto endcase;
  85. }
  86.  
  87. break;
  88.  
  89. // south-east.
  90. case 3:
  91. 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.
  92. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  93. totalPathLength[rowNum][colNum] += tempPathLength;
  94. indivPaths[element][pathNum] = tempPathLength;
  95. pathNum += 1;
  96. currentRow = rowNum;
  97. currentColumn = colNum;
  98. tempPathLength = 0;
  99. goto endcase; // break out of case structure.
  100. }
  101. if (map[currentRow+1][currentColumn+1] == 'L') {
  102. tempPathLength += 1;
  103. currentRow += 1;
  104. currentColumn += 1;
  105. goto endcase;
  106. }
  107. if ((map[currentRow+1][currentColumn+1] == 'D') || (map[currentRow+1][currentColumn+1] == 'V') || (map[currentRow+1][currentColumn+1] == 'W')) {
  108. 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.
  109. currentRow = rowNum;
  110. currentColumn = colNum;
  111. tempPathLength = 0;
  112. goto endcase;
  113. }
  114.  
  115. break;
  116.  
  117. // south.
  118. case 4:
  119. if((map[currentRow][currentColumn] == 'B') && (rowNum = 8)) { // If current cell is B and if row = 8 then success.
  120. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  121. totalPathLength[rowNum][colNum] += tempPathLength;
  122. indivPaths[element][pathNum] = tempPathLength;
  123. currentRow = rowNum;
  124. currentColumn = colNum;
  125. tempPathLength= 0;
  126. goto endcase; // break out of case structure.
  127. }
  128. if (map[currentRow+1][currentColumn] == 'L') {
  129. tempPathLength += 1;
  130. currentRow += 1;
  131. goto endcase;
  132. }
  133. if ((map[currentRow+1][currentColumn] == 'D') || (map[currentRow+1][currentColumn] == 'V') || (map[currentRow+1][currentColumn] == 'W')) {
  134. numFail[rowNum][colNum] += 1; // if the next cell below is a D V or W then walk failed, return to original cell.
  135. currentRow = rowNum;
  136. currentColumn = colNum;
  137. tempPathLength = 0;
  138. goto endcase;
  139. }
  140.  
  141. break;
  142.  
  143. // south-west.
  144. case 5:
  145. 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.
  146. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  147. totalPathLength[rowNum][colNum] += tempPathLength;
  148. indivPaths[element][pathNum] = tempPathLength;
  149. pathNum += 1;
  150. currentRow = rowNum;
  151. currentColumn = colNum;
  152. tempPathLength = 0;
  153. goto endcase; // break out of case structure.
  154. }
  155. if (map[currentRow+1][currentColumn-1] == 'L') {
  156. tempPathLength += 1;
  157. currentRow += 1;
  158. currentColumn -= 1;
  159. goto endcase;
  160. }
  161. if ((map[currentRow+1][currentColumn-1] == 'D') || (map[currentRow+1][currentColumn-1] == 'V') || (map[currentRow+1][currentColumn-1] == 'W')) {
  162. 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.
  163. currentRow = rowNum;
  164. currentColumn = colNum;
  165. tempPathLength = 0;
  166. goto endcase;
  167. }
  168.  
  169. break;
  170.  
  171. // west.
  172. case 6:
  173. if((map[currentRow][currentColumn] == 'B') && (colNum = 0)) { // If current cell is B and if column = 0 then success.
  174. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  175. totalPathLength[rowNum][colNum] += tempPathLength;
  176. indivPaths[element][pathNum] = tempPathLength;
  177. pathNum += 1;
  178. currentRow = rowNum;
  179. currentColumn = colNum;
  180. goto endcase; // break out of case structure.
  181. }
  182. if (map[currentRow][currentColumn-1] == 'L') {
  183. tempPathLength += 1;
  184. currentColumn -= 1;
  185. goto endcase;
  186. }
  187. if ((map[currentRow][currentColumn-1] == 'D') || (map[currentRow][currentColumn-1] == 'V') || (map[currentRow][currentColumn-1] == 'W')) {
  188. numFail[rowNum][colNum] += 1; // if the next cell to the left is a D V or W then walk failed, return to original cell.
  189. currentRow = rowNum;
  190. currentColumn = colNum;
  191. tempPathLength = 0;
  192. goto endcase;
  193. }
  194.  
  195. break;
  196.  
  197. // north-west.
  198. case 7:
  199. 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.
  200. numSuccess[rowNum][colNum] += 1; // Number of successes for the specified cell +1.
  201. totalPathLength[rowNum][colNum] += tempPathLength;
  202. indivPaths[element][pathNum] = tempPathLength;
  203. currentRow = rowNum;
  204. currentColumn = colNum;
  205. tempPathLength = 0;
  206. goto endcase;
  207. }
  208. if (map[currentRow-1][currentColumn-1] == 'L') {
  209. tempPathLength += 1;
  210. currentRow -= 1;
  211. currentColumn -= 1;
  212. goto endcase;
  213. }
  214. if ((map[currentRow-1][currentColumn-1] == 'D') || (map[currentRow-1][currentColumn-1] == 'V') || (map[currentRow-1][currentColumn-1] == 'W')) {
  215. 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.
  216. currentRow = rowNum;
  217. currentColumn = colNum;
  218. tempPathLength = 0;
  219. goto endcase;
  220. }
  221. endcase:
  222.  
  223. break;
  224.  
  225. }
  226. }
  227. element += 1;
  228. colNum += 1;
  229. pathNum = 0;
  230. }
  231. colNum = 0;
  232. rowNum += 1;
  233. pathNum = 0;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement