Guest User

Untitled

a guest
Feb 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public boolean HasTreasure(int row, int col) {
  2. if(row < 0 || col < 0 || row > theMap.numRows() || col > theMap.numCols()){
  3. return false;
  4. } else {
  5. if(theMap[row][col]) {
  6. return true;
  7. } else {
  8. return false;
  9. }
  10. }
  11. }
  12.  
  13.  
  14.  
  15. public int NumAdjacent(int row, int col) {
  16. int count = 0;
  17. if(theMap.HasTreasure((row - 1), col)
  18. count++;
  19. if(theMap.HasTreasure((row + 1), col)
  20. count++;
  21. if(theMap.HasTreasure(row, (col + 1))
  22. count++;
  23. if(theMap.HasTreasure(row, (col - 1))
  24. count++;
  25. if(theMap.HasTreasure((row + 1), (col + 1))
  26. count++;
  27. if(theMap.HasTreasure((row - 1), (col + 1))
  28. count++;
  29. if(theMap.HasTreasure((row + 1), (col - 1))
  30. count++;
  31. if(theMap.HasTreasure((row - 1), (col - 1))
  32. count++;
  33. return count;
  34. }
  35.  
  36. puclic static int[][] ComputeCounts(TreasureMap theMap) {
  37. int[][] returnThis = new int[theMap.numRows(), theMap.numCols()];
  38. for(int i = 0 ; i < theMap.numRows(); i++) {
  39. for(int j = 0; j < theMap.numCols(); j++) {
  40. if(theMap.HasTreasure(i,j)) {
  41. returnThis[i][j] = 9;
  42. } else {
  43. returnThis[i][j] = theMap.NumAdjacent(i,j);
  44. }
  45. }
  46. }
  47. return returnThis;
  48. }
Add Comment
Please, Sign In to add comment