Battleships

This took me months to finish, mainly cause I didn’t work on it for four months. It probably took like half a month or so for me to finish it. Spent this past month working on it on and off. It could use some work for sure still, but it works. I would love to get suggestions on how it could be improved.
Here it is: Battleship game

I enjoyed this game how did you get the blocks of color to print like that I looked at the source code thinking I was going to find some code for that image but it looked like just like a green block?

if you look at lines 38 - 46 that’s the base code. The next block of code that comes after is if its at the end of the board like say J instead of adding the green block to the right so an index that doesn’t exist it’ll add them to the left so it doesn’t cause an error that’s why the signs are switched to -= and it only runs after an error occurs because of the try statement and while loop. All I did for changing directions was change from changing the colloms to changing the rows for vertical placement everything else stayed the same when it came to placing. but even still the code doesn’t work all the time it can still be improved and I’m gonna be honest I wrote it but I don’t fully understand how it works I’m just glad it works as well as it does. If you have any more questions like creating the board or changing the color of blocks on the board after an attacking let me know.

here is the code with some more context and explanations.

def place_ships(self,ship,row,col,dir):
   # this to keep track of the ships sizes and changes the count depending on the determined ship and its size 
   count = {"Carrier":0,"Battleship":1,"Destroyer":2,"Submarine":2,"Patrol boat":3,}
   if dir == 'H':  
    try:
       #the main while loop that makes sure that the code runs enough times so that all the parts are placed 
        while count[ship] < 5:
         count[ship] += 1
       #a while loop that makes sure that the col is a number between 1 and 10 the other half is in the second half of this code
         while col < 1:
           col += 1
        #this while loop makes sure it doesn't place on top of other ships or itself
         while self.board[row][col] == '🟩':
          col += 1
         else:
          #changes the specific  block on the chosen index from a blue one to a green one once all the col changes have been made
          self.board[row][col] = '🟩'
          col -= 1
    except:
         #same code as the last part except signs are switched to -= and it has the second half  1 < col < 10 since this is the half of code that deal with that issue
         while count[ship] < 5:
          count[ship] += 1
        #second half of the 1 < col < 10
          while col > 10:
            col -= 1
          while self.board[row][col] == '🟩':
           col -= 1
          else:
           self.board[row][col] = '🟩'
           col += 1
   #the code for vertical placements same as horizontal except it changes the rows not the colloms as well as the last line where the sign is also -= and not +=
   elif dir == 'V': 
    try:
     while count[ship]  < 5:
        count[ship] += 1
        while row < 1:
          row += 1
        while self.board[row][col] == '🟩':
         row += 1
        else:
          self.board[row][col] = '🟩'
          row -= 1
    except:
        while count[ship] < 5:
         count[ship] += 1
         while row > 10:
          row -= 1
         while self.board[row][col] == '🟩':
          row -= 1
         else:
          self.board[row][col] = '🟩'
          row -= 1