Last active
February 4, 2021 08:01
-
-
Save znxkznxk1030/f178da5844573dd0163a6113443f33b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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