battleships game – Haskell [closed]

You need to transform the input grid into the output grid by mapping a function over each cell of the grid. The mapping function is going to need the coordinates of the cell and the content of the cell. The coordinates are needed to see if the other player fired at that location, and the contents are needed in order to know whether anything was hit.

Mapping can be done with map. Since the grid is 2d, you will need to map over the rows, and for each row, map over the columns of that row.

The coordinates of the row or column can be attached prior to mapping by zipping with an infinite .. range so that you get a pair of a coordinate in that dimension and a value in that dimension.


zip [0..] xs

Labels each element of xs with a zero-based index.

You can test if a coordinate is a member of the shot list with elem.

Browse More Popular Posts

Leave a Comment