dimanche 7 août 2022

How can I create a random 2d array in Haskell?

I am fairly new to Haskell and I'm always confused when it comes to dealing with random values. This time I'm trying to create a 5x5 2d-array in which every cell contains a random value between 4 options.

data Content = Bomb | One | Two | Three deriving (Eq, Show)
data Board = Array (Int, Int) Cell
data Cell = Cell {
   content :: Content,
   state :: CellState,
   notes :: Notes
}
type Notes = [String]
type CellState = Bool

then in the main function I typed

main :: IO()
main = do
let cellMatrix = createMatrix
print cellMatrix

How can I create a function that creates a Board, and where do I need to do all the g<-newStdGen stuff?

Any advice would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire