Y el de tableros... me faltó el 4 que no lo pude sacar todavía, pero como dice opcional no me dio verguenza subirlo incompleto =)
Al final del ejercicio cargué los tableros que aparecen en la guía para probar. Saludos!
Ejercicio
import Tablero
cantidadBloquesNegros :: Tablero -> Integer
cantidadBloquesNegros t
| (cantFilas t)<2 || (cantColumnas t)<2 = 0
| otherwise = auxCantBloq t 1
cantidadCrucesNegras :: Tablero -> Integer
cantidadCrucesNegras t
| (cantFilas t)<3 || (cantColumnas t)<3 = 0
| otherwise = auxCantCruc t 2
esDamero :: Tablero -> Bool
esDamero t
| (cantFilas t)<2 || (cantColumnas t)<2 = False
| otherwise = auxDamero t 1
--AUXILIARES--
chequeaBloque :: Tablero -> Int -> Int -> Bool
chequeaBloque t f c = c1==Negro && c2==Negro && c3==Negro && c4==Negro
where c1 = colorCasilla t f c
c2 = colorCasilla t (f+1) c
c3 = colorCasilla t f (c+1)
c4 = colorCasilla t (f+1) (c+1)
bloquesEnFila :: Tablero -> Int -> Int -> Integer
bloquesEnFila t f c
| c==(cantColumnas t)-1 = if (chequeaBloque t f c) then 1 else 0
| otherwise = if (chequeaBloque t f c) then 1+(bloquesEnFila t f (c+1)) else (bloquesEnFila t f (c+1))
auxCantBloq :: Tablero -> Int -> Integer
auxCantBloq t i
| i==(cantFilas t)-1 = bloquesEnFila t i 1
| otherwise = (bloquesEnFila t i 1) + (auxCantBloq t (i+1))
----
chequeaCruz :: Tablero -> Int -> Int -> Bool
chequeaCruz t f c = c0==Negro && c1==Negro && c2==Negro && c3==Negro && c4==Negro
where c0 = colorCasilla t f c
c1 = colorCasilla t (f-1) c
c2 = colorCasilla t f (c+1)
c3 = colorCasilla t (f+1) c
c4 = colorCasilla t f (c-1)
crucesEnFila :: Tablero -> Int -> Int -> Integer
crucesEnFila t f c
| c==(cantColumnas t)-1 = if (chequeaCruz t f c) then 1 else 0
| otherwise = if (chequeaCruz t f c) then 1 + (crucesEnFila t f (c+1)) else (crucesEnFila t f (c+1))
auxCantCruc :: Tablero -> Int -> Integer
auxCantCruc t i
| i ==(cantFilas t)-1 = crucesEnFila t i 1
| otherwise = (crucesEnFila t i 1) + (auxCantCruc t (i+1))
----
chequeaDamero :: Tablero -> Int -> Int -> Bool
chequeaDamero t f c
| colorCasilla t f c == Negro = c1==Blanco && c2==Negro && c3==Blanco
| colorCasilla t f c == Blanco = c1==Negro && c2==Blanco && c3==Negro
where c1 = colorCasilla t f (c+1)
c2 = colorCasilla t (f+1) (c+1)
c3 = colorCasilla t (f+1) c
chequeaFilaDamera :: Tablero -> Int -> Int -> Bool
chequeaFilaDamera t f c
| c == (cantColumnas t)-1 = (chequeaDamero t f c)
| otherwise = (chequeaDamero t f c) && (chequeaFilaDamera t f (c+1))
auxDamero :: Tablero -> Int -> Bool
auxDamero t i
| i==(cantFilas t) -1 = chequeaFilaDamera t i 1
| otherwise = (chequeaFilaDamera t i 1) && (auxDamero t (i+1))
---Tableros de prueba (los de la guía)
tab1 = crearT 4 4 [0,1,1,0,0,1,1,0,0,0,0,0,1,0,1,0]
tab2 = crearT 4 4 [0,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0]
tab3 = crearT 4 4 [1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0]
tab4 = crearT 4 4 [0,1,0,0,1,1,1,0,0,1,0,0,1,0,0,1]
tab5 = crearT 4 4 [0,0,1,0,0,1,1,1,1,1,1,0,0,1,1,1]
tab6 = crearT 4 4 [0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0]
tab7 = crearT 4 4 [0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0]
tab8 = crearT 5 6 [1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,0,1,1,0,0,0,1,0,0,1,0,1,0,0]
Módulo
module Tablero (Color(..), Tablero, cantFilas, cantColumnas, colorCasilla, crearT)
where
data Color = Negro | Blanco
deriving (Eq, Show)
data Tablero = T Int Int [Int]
deriving Show
cantFilas :: Tablero -> Int
cantFilas (T f c cod) = f
cantColumnas :: Tablero -> Int
cantColumnas (T f c cod) = c
codCasilla :: Tablero -> Int -> Int -> Int
codCasilla (T f c cod) i j = cod!!(((i-1)*c)+(j-1))
colorCasilla :: Tablero -> Int -> Int -> Color
colorCasilla t f c
| codCasilla t f c == 1 = Negro
| codCasilla t f c == 0 = Blanco
crearT :: Int -> Int -> [Int] -> Tablero
crearT f c cod = T f c cod