RosettaCodeData/Task/Generate-Chess960-starting-position/Phix/generate-chess960-starting-position.phix
2017-09-25 22:28:19 +02:00

25 lines
724 B
Text

sequence solutions = {}
--integer d = new_dict()
for i=1 to factorial(8) do
sequence s = permute(i,"RNBQKBNR")
-- sequence s = permute(rand(factorial(8),"RNBQKBNR")
integer b1 = find('B',s),
b2 = find('B',s,b1+1)
if and_bits(b2-b1,1)=1 then
integer k = find('K',s)
integer r1 = find('R',s)
integer r2 = find('R',s,r1+1)
if r1<k and k<r2 then
if find(s,solutions)=0 then
-- if getd_index(s,d)=0 then
-- setd(s,0,d)
solutions = append(solutions,s)
end if
end if
end if
end for
printf(1,"Found %d solutions\n",{length(solutions)})
for i=1 to 5 do
?solutions[rand(length(solutions))]
end for