So, we need to reconsider our probability distribution calculation so it should be aware of surroundings:
If a neighbor cell was already hit (so we know there is a ship there), we should stop doing any calculations since we know it’s impossible to have adjusted ship cells. Since we still operate in one dimensional, we should check both left and right adjusted cells:
After checking surroundings, we need to check the sliding window itself:
The algorithm hasn’t been changed this the previous part of this tutorial:
We just need to slightly change chance expression:
Finally, let’s check if it works correctly.
We need to designate our shooting results somehow:
If we hit some ship, there is still a chance to sink it by hitting surroundings:
But if there is a sunk ship it means there could be no ships arround: