This is homework, and I'm really struggling with the last bit. We are writing Armadillo in Haskell, and apart from a few general lectures on functional languages, we don’t have many. No tutorial, etc. I was referred to LYAH several times, and there were good things there, but it does not seem to have suggestions for this particular problem.
In context, I have put all my Battleship code so you can see which definitions I will mention later.
--A data Row = A | B | C | D | E | F | G | H | I | J deriving (Enum, Ord, Show, Bounded, Eq, Read) data Column = One | Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten deriving (Enum, Ord, Show, Bounded, Eq, Read) --B data Address = Address Row Column deriving (Show, Read, Eq) --C data Cell = Cell Address Bool deriving (Show, Read, Eq) --D data Ship = Ship [Cell] deriving (Show, Eq) --E data Ships = Ships [Ship] deriving (Show, Eq) --F toAddress rc = Address (toEnum r) (toEnum c) --G toRowColumn (Address aRow aColumn) = (fromEnum aRow, fromEnum aColumn) --H allAddressesA = [ Address row column | row <- [A .. J], column <- [One .. Ten]] --I allAddressesB = [toAddress row column | row <- [0 .. 9], column <- [0 .. 9]] --J targetShip (Ship ship) (Address row column) | Address == map (\list -> (head Address Bool)) s --K targetShips [(Ships)] toAddress //TODO --L isSunk Ship ship |ship [] = true |otherwise foldl --M areSunk [(Ships)] //TODO
And now I will also publish descriptions of specific appointments so that there are no communication errors with what I need help with:
(j) Write a function targetShip that takes the ship and target address as two of its parameters. If the ship has a cell with a destination address, this cell is marked sunk. An updated version of the ship is back. If the ship is empty, an empty ship is returned. (1 map, 116 characters)
(k) Write a function targetShips that takes a list of ships and the target address as two parameters. He tries to submerge each ship in the list of ships. It returns a list of updated ships. If there are no ships, an empty list is returned. (1 map, 86 characters)
(l) Write an isSunk function that takes the ship as its parameter. If the ship is an empty ship, return it. Otherwise, return true if all cells are marked sunk. (1 time, 78 characters)
(m) Write an isSunk function that takes a list of ships as its parameter. If there are no ships, return the truth. Otherwise, return true if all ships are marked sunk. (1 time, 78 characters)
So, what is my specific struggle here, these are the last 4. The solutions (A - I) that I tested and they work fine.
We need to know how to refer to cell values ... Address and Bool separately for starters.
We cannot write more functions.
I suggest that you need more explanation on specific issues, so I will follow closely. Any tips on where to start the last four problems will be greatly appreciated. Thanks in advance ... and now I will return to the text editor and try to do it.