I'm playing the game Battle Ship, the game board consists of 10 x 10 squares in the form of arrays:
const board = [
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0.0.0.0,0,0,0,0,0,0]
]
I want to fill the board with boats, in the form of numbers 2, which means the ship is alive and have already changed the game for example by -1 to understand that the ship is hit. I was able to fill the game board using random positions during initialization, but the problem is that the ships touch each other, that you can think of that the positions of the ships at the start are not in contact with each other. What would be between them was the distance of at least one empty cage.