RosettaCodeData/Task/Generate-Chess960-starting-position/Prolog/generate-chess960-starting-position-1.pro
2024-03-06 22:25:12 -08:00

12 lines
335 B
Prolog

check(Row) :-
nth1(King, Row, ),
nth1(Rook1, Row, ),
nth1(Rook2, Row, ),
nth1(Bishop1, Row, ),
nth1(Bishop2, Row, ),
Rook1 < King, King < Rook2,
(Bishop1 + Bishop2) mod 2 =:= 1.
generate(Row) :-
random_permutation([,,,,,,,], Row),
check(Row) ; generate(Row).