Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help using only python Using the algorithm for the Arrays assignment. Create a 3D Battle ship program making use of a 3 dimensional array.

Need help

using only python

Using the algorithm for the Arrays assignment. Create a 3D Battle ship program making use of a 3 dimensional array.

There will me 5 ships that will be hidden anywhere on each level.

The board will be 3 X 12 X 12

Randomly generate each hiding space for each ship.

A ship can only be on one level

A ship size will denote the number of elements it takes up.

Ship 1 = 2

Ship 2 = 3

Ship 3 = 3

Ship 4 = 4

Ship 5 = 5

After hiding the ships, allow the user to guess where the boats are one element at a a time

Mark the found elements on the two dimensional table to show progress.

Give the user a limit to the amount of guesses made.

using this code able to modify it

import random level = [[[' ' for c in range(3)] for r in range(3)] for l in range(3)]

for l in range (3): print ("level", l+1) for r in range (3) : for c in range (3) : level [l] [r] [c] = 'A' + str (l)+","+ 'B' + str (r)+","+ 'C' + str (c) print (level[l][r][c], end = ' ') print ()

def boatCoord(size, l,r,c) :

lev = random.randint(0,l-1) 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,boatDirect bPlace = [0,0,0] board = [[[ ' 'for c in range (12) ] for r in range (12)] for l in range (3)] c = 11 r = 11 l = 2 boatsize=[2,3,3,4,5] for (index,place) in enumerate(boatsSz): lev,row,col, bDirect = boatCoord(place, l, r, c) ##place boats on board for size in range (place) : if board[lev] [row] [col] != "-": board[lev] [row] [col] = index print (board[lev] [row] [col] , index) for l in range (3) : print ( "level",l) for r in range (12) : for c in range (12) : print ( "level",r,c) :

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

ISBN: 1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

What initiatives did I take?

Answered: 1 week ago

Question

a. How are members selected to join the team?

Answered: 1 week ago

Question

b. Will new members be welcomed?

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago