so I’m new to Prolog and we have this problem
Consider a chessboard of side n. You need to place 2(n-1) bishops on the chessboard so that no two bishops threaten each other. Bishops move only diagonally.
Express the problem using constraints-based terminology. Name the variables, their domains and the constraints.
Apply depth-first-search and forward checking for a problem with n=3 placing the first bishop at square (1,1). Write down the squares for the other bishops in the order you generate solutions.
I was able to use DFS, but I’m lost with CLPFD
We associate each bishop with an ordered pair
X/Y—aXandYposition on the board.Every bishop lies on one diagonal (
X - Y) and on one skew diagonal (X + Y).All bishops must be on different diagonals and on different skew diagonals.
Putting it all together:
Using Scryer Prolog: