DIM x(8),a(8),b(15),c(15)
FOR i=1 TO 8
x(i)=0
a(i)=TRUE
NEXT
FOR i=1 TO 15
b(i)=TRUE
c(i)=TRUE
NEXT
sukses = false
CALL Try(1, sukses)
IF sukses=TRUE THEN
CALL CetakPapan()
ELSE
document.write "Tidak Ada Solusinya!!!
"
END IF
SUB Try(byVal baris, byRef sukses)
kolom = 0
DO
kolom = kolom + 1
suksesBerikut = FALSE
IF a(kolom) AND b(baris+kolom-1) AND c(kolom-baris+8) THEN
x(baris)=kolom
a(kolom)=FALSE
b(baris+kolom-1)=FALSE
c(kolom-baris+8)=FALSE
IF baris<8 THEN
CALL Try(baris+1, suksesBerikut)
IF suksesBerikut = FALSE THEN
x(baris)=0
a(kolom)=TRUE
b(baris+kolom-1)=TRUE
c(kolom-baris+8)=TRUE
END IF
ELSE
suksesBerikut = TRUE
END IF
END IF
LOOP UNTIL suksesBerikut = TRUE OR kolom = 8
sukses = suksesBerikut
END SUB
SUB CetakPapan()
document.write "Papan Catur :
"
FOR i=1 TO 8
document.write x(i) & ", "
NEXT
document.write "
"
END SUB
No comments:
Post a Comment