Created
December 15, 2012 13:07
-
-
Save thomwiggers/4294806 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
--Nieuwe posities als we iemand kunnen slaan | |
slaanDownFrom :: Player -> Board -> (Int,Int) -> Bool -> [(Int,Int)] | |
slaanDownFrom player board (a,b) isdam = | |
[ (x,y) | (x,y) <- ([ (a+n,b-n) | n <- [2 .. 10], n > 2 == isdam] ++ | |
[ (a+n,b-n) | n <- [2 .. 10], n > 2 == isdam]), | |
x > 0 && x < 10 && y > 0 && y < 10 && vrij (x,y) | |
&& enemybetween (a,b) (x,y) | |
] | |
where | |
enem = (\x -> isEnemy (getPiece board x) player) | |
vrij = isVrij board | |
enemybetween :: (Int,Int) -> (Int,Int) -> Int -> Bool | |
enemybetween (a,b) (x,y) acc | |
| a > x && b > y = enemybetween (a,b) (x-1,y-1) (acc + (nemem (x-1,y-1))) | |
| a > x && b < y = enemybetween (a,b) (x-1,y+1) (acc + (nemem (x-1,y+1))) | |
| a == x && b == y = if acc == 1 | |
then True | |
else False | |
| otherwise = False | |
where | |
nemem :: (Int,Int) -> Int | |
nemem pos = if enem pos | |
then 1 | |
else 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment