Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
Haskell exercise
Tetris fitsTetromino
Sign in to hand in your solution and get feedback.
import Data.List
type Direction = (Int,Int)
-- The colour of a tetromino.
data Color = Red | Green | Blue | Yellow | Cyan | Magenta | Orange
deriving (Eq,Show)
data Tetromino = Tetromino Int (Int,Int) Color [Block]
deriving (Eq,Show)
data Block = Block (Int,Int)
deriving (Eq,Show)
data Board = Board [Block]
deriving (Eq,Show)
width :: Float
width = 10
height :: Float
height = 20
move :: Direction -> Block -> Block
move (x,y) (Block (p,q)) = (Block (x+p,y+q))
freeBlock :: Board -> Block -> Bool
freeBlock (Board l) b = not (b `elem` l)
onBoard :: Block -> Bool
onBoard (Block (x,y)) = and [(x>=0), (x < round width), (y>=0), (y< round height)]
-- Check if a Tetromino fits in the board
-- This means that if you move all the blocks of the tetromino to their position
-- then:
-- 1) The position of all the moved blocks in the Tetromino are free
-- 2) All the positions of the moved blocks are within the boundaries
-- Lookup "all" and "and"
-- (* Difficulty 2 *)
fitsTetromino :: Tetromino -> Board -> Bool
fitsTetromino (Tetromino s p c blocks) board = undefined
-- hint :: where aBlocks = (move p) <$> blocks