First of all, to set up the array that defines the board I thought I was suppose to use:
myArray[SIZE][SIZE];
but someone said that using calloc would be better. I am not familiar with it, and dont see how it could be applied here.
2nd, we are suppose to just get to the part where the board is set up with random computer ships (no further) but I have no idea how to set up the function to randomly assign ships. Here are the instructions:
Any help would be great, thanks!CSCE 1030
You shall write a function
to assign a ship to a location on the board, given the
data
structure for the board passed by reference and
another parameter providing some
identifying factor, such as the length or type of the ship.
This function is called by
main()
and is to only assign
(or attempt to assign) one ship that is passed to it.
You
shall randomly generate the orientation (i.e., either vertical or horizontal) of the ship.
You shall also randomly generate the row and column position for the start of the ship. If
the ship does n
ot fit on the board at this starting location, you can either return
information indicating that the ship could not be assigned (and so it will be up to
main()
to keep calling this
function until it is successfully assigned) or keep randomly
generating row
and column positions for the ship
’s starting position until one is found
that can be used to successfully assign the ship. A ship may be assigned anywhere on
the board (as long as it fits), but it may not be assigned on top of another ship that
exists at
that location.
This must be a single function designed to handle all ships.
You will also write a function to display the game board, giving the data structure for the
board passed by reference.
It
is called by
main()
and is invoked anytime th
e board has
b
een updated (for this homework, it is invoked after the aircraft carrier and battleship
have been placed on the board).
This function
will display the row and column headers
for the board as well as the board itself
(see sample output). Open space on the board
(i.e., where no ships have been assigned) shall be indicated by a blank space on the
board. The aircraft carrier shall be represented by an
‘A’ for each of its 5 unit length,
while the battleship shall be repres
ented by a ‘B’ for each of its 4 unit length.