Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean HasTreasure(int row, int col) {
- if(row < 0 || col < 0 || row > theMap.numRows() || col > theMap.numCols()){
- return false;
- } else {
- if(theMap[row][col]) {
- return true;
- } else {
- return false;
- }
- }
- }
- public int NumAdjacent(int row, int col) {
- int count = 0;
- if(theMap.HasTreasure((row - 1), col)
- count++;
- if(theMap.HasTreasure((row + 1), col)
- count++;
- if(theMap.HasTreasure(row, (col + 1))
- count++;
- if(theMap.HasTreasure(row, (col - 1))
- count++;
- if(theMap.HasTreasure((row + 1), (col + 1))
- count++;
- if(theMap.HasTreasure((row - 1), (col + 1))
- count++;
- if(theMap.HasTreasure((row + 1), (col - 1))
- count++;
- if(theMap.HasTreasure((row - 1), (col - 1))
- count++;
- return count;
- }
- puclic static int[][] ComputeCounts(TreasureMap theMap) {
- int[][] returnThis = new int[theMap.numRows(), theMap.numCols()];
- for(int i = 0 ; i < theMap.numRows(); i++) {
- for(int j = 0; j < theMap.numCols(); j++) {
- if(theMap.HasTreasure(i,j)) {
- returnThis[i][j] = 9;
- } else {
- returnThis[i][j] = theMap.NumAdjacent(i,j);
- }
- }
- }
- return returnThis;
- }
Add Comment
Please, Sign In to add comment