Skip to content

Instantly share code, notes, and snippets.

@mheinzel
Forked from lksnmnn/FENBoard_Moves.hs
Last active January 29, 2016 12:31
Show Gist options
  • Save mheinzel/848cb8c8d0e0cdb17232 to your computer and use it in GitHub Desktop.
Save mheinzel/848cb8c8d0e0cdb17232 to your computer and use it in GitHub Desktop.
Chess: FEN-Boards and possible moves
----------------------------------------------------------------------------
-- Test für die Funktion botListAllMoves :: String -> String -> [String]
--
-- Lizenz: MIT
-- Berlin, 25.01.2016
----------------------------------------------------------------------------
import Data.List (sort)
import ChessBot (botListAllMoves)
data TestCase = Case String String [String]
testCases :: [TestCase]
testCases = [
-- Paul
Case
"rnbkqbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBKQBNR"
"w"
["h2 h4","h2 h3","g2 g4","g2 g3","f2 f4","f2 f3","e2 e4","e2 e3",
"d2 d4","d2 d3","c2 c4","c2 c3","b2 b4","b2 b3","a2 a4","a2 a3",
"g1 h3","g1 f3","b1 c3","b1 a3"],
-- ravensinth:
Case
"3q2k1/1b5b/6p1/5P2/8/1R1b2Q1/1NP5/4K3"
"w"
["f5 f6","f5 g6","g3 h4","g3 f4","g3 e5","g3 d6","g3 c7","g3 b8",
"g3 h2","g3 f2","g3 h3","g3 f3","g3 e3","g3 d3","g3 g2","g3 g1",
"g3 g4","g3 g5","g3 g6","b3 c3","b3 d3","b3 a3","b3 b4","b3 b5",
"b3 b6","b3 b7","c2 c4","c2 c3","c2 d3","b2 c4","b2 a4","b2 d3",
"b2 d1","e1 d1","e1 d2","e1 f2"],
Case
"3q2k1/5r1b/6p1/5P2/8/1R4Q1/1NP5/4K3"
"b"
["g8 g7","g8 f8","g8 h8","d8 e7","d8 f6","d8 g5","d8 h4","d8 c7",
"d8 b6","d8 a5","d8 e8","d8 f8","d8 c8","d8 b8","d8 a8","d8 d7",
"d8 d6","d8 d5","d8 d4","d8 d3","d8 d2","d8 d1","f7 g7","f7 e7",
"f7 d7","f7 c7","f7 b7","f7 a7","f7 f6","f7 f5","f7 f8","g6 g5"],
Case
"3q2k1/P4r1b/6pR/8/8/4B3/2PN4/4K3"
"w"
["a7 a8","h6 g6","h6 h5","h6 h4","h6 h3","h6 h2","h6 h1","h6 h7",
"e3 f4","e3 g5","e3 d4","e3 c5","e3 b6","e3 f2","e3 g1","d2 e4",
"d2 c4","d2 f3","d2 b3","d2 f1","d2 b1","c2 c4","c2 c3","e1 d1",
"e1 e2"]
]
test :: TestCase -> Bool
test (Case board color solution) = let result = botListAllMoves board color
in sort result == sort solution
runTests :: [TestCase] -> String
runTests tests = let failedTests = filter (not . test) tests
showFailedTest (n, Case b c s) =
show n ++ ") " ++ b ++ " " ++ c ++ " failed!\n"
++ "should be:\n"
++ show (sort s) ++ "\n"
++ "is:\n"
++ show (sort (botListAllMoves b c)) ++ "\n"
in if null failedTests
then "All tests passed!"
else unlines . map showFailedTest . zip [1..] $ failedTests
main :: IO ()
main = putStrLn (runTests testCases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment