Skip to content

Instantly share code, notes, and snippets.

@ignaciomosca
Created November 25, 2019 22:25
Show Gist options
  • Save ignaciomosca/1743a4c3e340ceb41df1278d2b619f60 to your computer and use it in GitHub Desktop.
Save ignaciomosca/1743a4c3e340ceb41df1278d2b619f60 to your computer and use it in GitHub Desktop.
findCandidate :: ChessPiece -> Board -> Set Board
findCandidate p b
= Data.Set.fromList $
[ newBoard
| rr <- [1 .. (m b)]
, cc <- [1 .. (n b)]
, let pp = createPiece (piece p) rr cc
, let newBoard = place b pp
, isSafe b pp]
solution :: Board -> [ChessPiece] -> Set Board -> Set Board
solution board (p : ps) solutions = solution board ps (Data.Set.Extra.flatten (Data.Set.map (findCandidate p) solutions))
solution board [] solutions = Data.Set.filter done solutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment