Problem : Finding minimum knights needed to cover a NxN chess board.
NxN chess board has NxN squares which i numbered from 0 to NxN - 1. I've defined the following predicates.
allKnightsAttack(N, KnightsList, AttackedSquaresList)
this predicate gives Attacked Squares List.
Example:
if N = 4, KnightsList = [0, 5] gives us :
AttackedSquaresList = [3,11,12,14,5,6,9,0].
Graphical equivalent:
X--O
-XO-
-O-O
O-O-
X - knight, O - attacked square(squares held by knights are also "attacked".
next(KnightsList, Next, N)
this predicate given a KnightsList finds "next" list, which is found like that :
/* this KnightList's ALWAYS ASCENDING */
if last knight position < NxN-1 then increase its position;
if it reached NxN-1 then increase second last's knights position, and the last becomes next to second last and so on.
Examples: N = 4.
[0, 1, 2, 3] - next is [0, 1, 2, 4]
[0, 1, 2, 15] - next is [0, 1, 3, 4]
[0, 5, 14, 15] - next is [0, 6, 7, 8]
.........
/* with next you can get every position of knights placed on the board - if starting list [0,1,2,3] and N=4, "next'ing" to [12, 13, 14, 15] would give us all possible positions of four knights on a 4x4 board */
I also defined a few predicates to operate lists : removing adding, concatenating ...
I've done a solution which tells if a set of knights IS covering a board(TRUE/FALSE).
Can anyone help to define a predicate
knights(N, Knights)
which given N would output a set of Knights which cover a NxN board.
Example :
goal: knights(3, Knights)
Knights = [0,1,2,4].
XXX
-X-
---
NxN chess board has NxN squares which i numbered from 0 to NxN - 1. I've defined the following predicates.
allKnightsAttack(N, KnightsList, AttackedSquaresList)
this predicate gives Attacked Squares List.
Example:
if N = 4, KnightsList = [0, 5] gives us :
AttackedSquaresList = [3,11,12,14,5,6,9,0].
Graphical equivalent:
X--O
-XO-
-O-O
O-O-
X - knight, O - attacked square(squares held by knights are also "attacked".
next(KnightsList, Next, N)
this predicate given a KnightsList finds "next" list, which is found like that :
/* this KnightList's ALWAYS ASCENDING */
if last knight position < NxN-1 then increase its position;
if it reached NxN-1 then increase second last's knights position, and the last becomes next to second last and so on.
Examples: N = 4.
[0, 1, 2, 3] - next is [0, 1, 2, 4]
[0, 1, 2, 15] - next is [0, 1, 3, 4]
[0, 5, 14, 15] - next is [0, 6, 7, 8]
.........
/* with next you can get every position of knights placed on the board - if starting list [0,1,2,3] and N=4, "next'ing" to [12, 13, 14, 15] would give us all possible positions of four knights on a 4x4 board */
I also defined a few predicates to operate lists : removing adding, concatenating ...
I've done a solution which tells if a set of knights IS covering a board(TRUE/FALSE).
Can anyone help to define a predicate
knights(N, Knights)
which given N would output a set of Knights which cover a NxN board.
Example :
goal: knights(3, Knights)
Knights = [0,1,2,4].
XXX
-X-
---