Skip to content

Instantly share code, notes, and snippets.

@znxkznxk1030
Last active February 4, 2021 08:01
Show Gist options
  • Save znxkznxk1030/f178da5844573dd0163a6113443f33b1 to your computer and use it in GitHub Desktop.
Save znxkznxk1030/f178da5844573dd0163a6113443f33b1 to your computer and use it in GitHub Desktop.
module Board (
Cell(..),
Row,
Board,
initboard,
showBoard
) where
import Data.List
-- Occupied to Colors
data Cell = Occupied | Wall | Celling | Floor | Empty deriving(Eq)
type Row = [Cell]
type Board = [Row]
instance Show Cell where
show Occupied = "■"
show Wall = "|"
show Celling = "_"
show Floor = "─"
show Empty = " "
-- 10 * cell + 2 * wall
width :: Int
width = 15
-- 20 * cell + celling + floor
height :: Int
height = 20
initboard :: Board
initboard = [replicate (width + 2) Celling] ++ (replicate height $ ([Wall] ++ replicate width Empty ++ [Wall])) ++ [replicate (width + 2) Floor]
showRow :: Row -> String
showRow row = intercalate "" $ map show row
showBoard :: Board -> String
showBoard board = unlines $ map showRow board
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment