; 8-QUEENS SOLUTION¢; BY DAVE OBLAD¢; (c) 1985, ANTIC PUBLISHING¢¢BYTE ARRAY T(96),P(8),I(8),O(8),M(8)¢BYTE A,B,C,D,X,Y,L1,L2,L3,OPT=53279¢¢PROC SEARCH()¢ FOR X=0 TO D¢ DO¢ Y=X*8 B=1¢ FOR A=0 TO 7¢ DO¢ IF T(Y+A)#O(A) THEN B=0 FI¢ OD¢ IF B=1 THEN RETURN FI¢ OD¢RETURN¢¢PROC ROTATE()¢ FOR A=0 TO 7¢ DO¢ B=7-O(A) M(B)=A¢ OD¢ FOR A=0 TO 7¢ DO¢ O(A)=M(A)¢ OD¢RETURN¢¢PROC TEST()¢ FOR A=0 TO 7¢ DO O(A)=P(A) OD¢ FOR L1=0 TO 1¢ DO ¢ FOR L2=0 TO 1¢ DO¢ FOR L3=0 TO 3¢ DO¢ SEARCH()¢ IF B=1 THEN RETURN FI¢ ROTATE()¢ OD¢ FOR A=0 TO 7¢ DO M(A)=O(A) OD¢ FOR A=0 TO 7¢ DO O(7-A)=M(A) OD¢ OD¢ FOR A=0 TO 7¢ DO O(A)=7-O(A) OD¢ OD¢ B=0¢RETURN¢¢PROC KEEP()¢ X=D*8¢ FOR A=0 TO 7¢ DO T(X+A)=P(A) OD¢RETURN¢¢PROC DISPLAY()¢;REMOVE 5 SEMI-COLONS BELOW¢;FOR UNIQUE SOLUTIONS ONLY!¢¢;IF D#0 THEN TEST()¢; IF B=1 THEN RETURN¢; ELSE KEEP()¢; FI¢;FI¢¢ FOR Y=0 TO 7¢ DO¢ FOR X=0 TO 7¢ DO¢ POSITION(X+15,Y+8) ¢ IF P(Y)=X THEN PRINT("Q")¢ ELSE PRINT("+") FI¢ OD¢ OD¢ POSITION(18,18)¢ D==+1 PRINTB(D)¢RETURN¢¢PROC TRY()¢ FOR Y=0 TO 6¢ DO¢ FOR X=Y+1 TO 7¢ DO¢ A=P(X)-P(Y) B=X-Y¢ IF A>7 THEN A=255-A+1 FI¢ IF A=B THEN RETURN FI¢ OD¢ OD¢ DISPLAY()¢RETURN¢¢PROC SWAP()¢ C=0 I(C)==+1¢ WHILE I(C)=C+2¢ DO¢ I(C)=0 C==+1 I(C)==+1¢ IF C<7 THEN¢ FOR B=0 TO C¢ DO¢ A=P(B) P(B)=P(B+1) P(B+1)=A¢ OD¢ FI¢ OD¢ A=P(0) P(0)=P(1) P(1)=A¢RETURN¢¢¢PROC MAIN()¢BYTE CONSOLE=53279¢¢DO¢ GRAPHICS(0) POKE(752,1)¢ POSITION(8,0)¢ PRINTE(" 8-QUEENS SOLUTIONS")¢ PRINTE(" BY DAVE OBLAD")¢ FOR A=0 TO 7 DO P(A)=A I(A)=0 OD¢ FOR A=0 TO 96 DO T(A)=0 OD¢ D=0¢ DO ¢ TRY() SWAP()¢ FOR A=0 TO 7¢ DO¢ IF A#P(A) THEN EXIT FI¢ OD¢ IF A=8 OR OPT#7 THEN EXIT FI¢ OD¢ IF A=8 THEN POSITION(15,20)¢ PRINTE("COMPLETE")¢ PUTE()¢ PRINTE("PRESS áצקIJפקá TO RE-RUN")¢ FI¢ DO¢ UNTIL CONSOLE < 7¢ OD¢OD¢RETURN¢¢