Something wrong with my program

closed account (LN3RX9L8)
there should be four boats in this program and each boat takes up two consecutive spaces on the board (up, down, right or left, don’t worry about diagonal placement). So in total really 8 boats
Problem is my program is only playing with two boats and also I have to check before I pace a boat on the board, double-check to make sure it will not overlap with an existing boat and make sure that the boat does not go over the edge of the board.
Is my last do while loop(logic statement) correct??
This is what I have so far...

I finished this code.
Last edited on
- It doesnt check if a place is already occupied by a boat which is possible.
boat [row2][column2]='B';

- The boats would not occupy the whole board and the placement would be very near to each other. for example, if indexrow and indexrowcolumn are 5,2 before the loop. you are going to place boats mostly around these locations and rest of the locations would be empty. This will have less chances that you will generate duplicates many times.

- Lets say, the generation is 9, 1 which is possible. and the generator generates a value of 2. You are going to place the boats at 10, 1 and which is not a valid position (valid positions are from 0-9). Same can be a case when the generation is 9,0 and generator is 0; You have checks for this in the while but the assignment would be before that and a crash is possible.

- I think
boat [indexrow][indexcolumn]='B';
should be inside the for loop ? Otherwise you would generate maximum 5 positions.
Last edited on
Topic archived. No new replies allowed.