Queens Dominant

Publication: ZX-Appeal
Pub Details: ZX-Appeal Summer 87
Date: Summer 1987
Pages: 39

This program lets you distribute chess queens on a board, and shows which squares they are attacking. The aim is to attack all of the board with as few queens as possible, by judicious choice. It can be done with five of them.

  10 DIM B(8,8)
20 FOR I=1 TO 8
30 FOR J=1 TO 8
40 PRINT AT 2*I,2*J+8;"gH"
50 NEXT J
60 NEXT I
70 LET P=2
80 LET Q=9
90 GOSUB 2000
92 LET P0=P
94 LET Q0=Q
100 IF INKEY$<>"" THEN GOTO 100
110 IF INKEY$="" THEN GOTO 110
120 LET I$=INKEY$
130 IF I$="Q" THEN GOTO 200
140 IF I$="5" THEN LET Q=Q-2
150 IF I$="6" THEN LET P=P+2
160 IF I$="7" THEN LET P=P-2
170 IF I$="8" THEN LET Q=Q+2
180 GOSUB 1000
185 GOSUB 1020
190 GOTO 92
200 PRINT AT P,Q+1;" Q "
207 LET J=(Q-7)/2
210 LET B(I,J)=1
220 FOR T=1 TO 8
230 IF B(I,T)=0 THEN LET B(I,T)=-1
240 IF B(T,J)=0 THEN LET B(T,J)=-1
250 NEXT T
260 FOR F=-1 TO 1 STEP 2
270 FOR T=-8 TO 8
280 LET U=I+F*T
290 LET V=J+T
300 IF U<1 OR U>8 OR V<1 OR V>8 THEN GOTO 320
310 IF B(U,V)=0 THEN LET B(U,V)=-1
320 NEXT T
330 NEXT F
340 GOSUB 2000
350 GOTO 92
1000 PRINT AT P,Q;" > "
1010 RETURN
1020 PRINT AT P0,Q0;"□"
1030 RETURN
2000 FOR I=1 TO 8
2010 FOR J=1 TO 8
2020 IF B(I,J)=-1 THEN PRINT AT 2*I,2*J+8;"+"
2030 NEXT J
2040 NEXT I
2050 RETURN

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.