Search Results

Search found 1 results on 1 pages for 'rgorrosini'.

Page 1/1 | 1 

  • Recursion - Ship Battle

    - by rgorrosini
    I'm trying to write a little ship battle game in java. It is 100% academic, I made it to practice recursion, so... I want to use it instead of iteration, even if it's simpler and more efficient in most some cases. Let's get down to business. These are the rules: Ships are 1, 2 or 3 cells wide and are placed horizontally only. Water is represented with 0, non-hit ship cells are 1, hit ship cells are 2 and sunken ships have all it's cells in 3. With those rules set, I'm using the following array for testing: int[][] board = new int[][] { {0, 1, 2, 0, 1, 0}, {0, 0, 1, 1, 1, 0}, {0, 3, 0, 0, 0, 0}, {0, 0, 2, 1, 2, 0}, {0, 0, 0, 1, 1, 1}, }; It works pretty good so far, and to make it more user-friendly I would like to add a couple of reports. these are the methods I need for them: Given the matrix, return the amount of ships in it. Same as a), but separating them by state (amount of non-hit ships, hit and sunken ones). I will need a hand with those reports, and I would like to get some ideas. Remember it must be done using recursion, I want to understand this, and the only way to go is practice! Thanks a lot for your time and patience :).

    Read the article

1