Opgepast! Het lijkt erop dat je Dodona gebruikt binnen een andere webpagina waardoor mogelijk niet alles goed werkt. Laat dit weten aan de lesgever zodat die het probleem kan oplossen door een instelling in de leeromgeving aan te passen. Ondertussen kan je op deze link klikken om Dodona te openen in een nieuw venster.
Opgepast! De pagina kon niet volledig ingeladen worden, waarschijnlijk door een netwerkprobleem. Het kan zijn dat niet alle functionaliteit beschikbaar is. Probeer de pagina te verversen.
Haskell-oefening
Tetris fitsTetromino
Meld je aan om je oplossing in te dienen en feedback te krijgen.
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