Question: Need help Python only Run this code import random #random boat coordinates def placeBoat(size, lev , row , col): lev = random.randint(0,2) row = random.randint(0,r-size)
Need help
Python only
Run this code
import random
#random boat coordinates def placeBoat(size, lev , row , col): lev = random.randint(0,2) row = random.randint(0,r-size) col = random.randint(0,c-size) bDirect = random.randint(0,3) bPlace = (lev,row,col) return lev,row,col,bPlace def eraseBoat(board, size, lev, row, col, bDirect): for uCtr in range (size-1, -1, -1): oRow = row if bDirect ==0: col -= 1 elif bDirect == 1: row -= 1 elif bDirect == 2: row -= 1 col -= 1 elif bDirect == 3: row += 1 col -= 1 board [lev][row][col] = '-' print ("e", index, board [lev][row][col], lev, row, col, "*",bDirect)
bPlace = [0,0,0] #creating the board board = [[["-" for c in range (12)] for r in range (12)] for l in range (3)] c = 11 r = 11 l = 2 boatSz = [2,3,3,4,5] #placing the boats on the board for (index, place) in enumerate (boatSz): lev, row, col, bDirect = placeBoat(place, l, r, c) ctr = 0 size = 0 if board[lev][row][col]=="-": print("n", index, board[lev][row][col],lev,row,col, "*", bDirect) board[lev][row][col] = index oRow = row if bDirect == boatSz[0]: col += 1 elif bDirect == boatSz[1]: row += 1 elif bDirect == boatSz[2]: row += 1 col += 1 elif bDirect == 3: if(row - size) >= boatSz[1]: row -= 1 col += 1
for l in range (3): print ('level', l+1) for r in range (12): for c in range (12): print (board [l][r][c], end=' ') print() print()
What I need help is putting my boats on the grid
Similar to this as the output.
level o lerel
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
