;;ボード8*8の端の判定を楽にするのに10*10行列にしている。
(define mat
(list->matrix
'((0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 2 0 0 0 0 0)
(0 0 0 0 2 2 0 0 0 0)
(0 0 0 1 1 1 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0))))
(define init? #t)
(define (find)
(do ((i 2 (+ i 1)))
((> i 9) (if init? (display "初期配置")))
(do ((j 2 (+ j 1)))
((> j 9) #t)
(check-LU i j)
(check-UP i j)
(check-RU i j)
(check-LT i j)
(check-RT i j)
(check-LD i j)
(check-DN i j)
(check-RD i j))))
(define (LU? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat (- i 1) (- j 1))
(matrix-ref1 mat i j))
(= (matrix-ref1 mat (+ i 1) (+ i 1)) 0)))
(define (UP? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat (- i 1) j)
(matrix-ref1 mat i j))
(= (matrix-ref1 mat (+ i 1) j) 0)))
(define (RU? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat (- i 1) (+ j 1))
(matrix-ref1 mat i j))
(= (matrix-ref1 mat (+ i 1) (- j 1)) 0)))
(define (LT? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat i (- j 1))
(matrix-ref1 mat i j))
(= (matrix-ref1 mat i (+ j 1)) 0)))
(define (RT? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat i (+ j 1))
(matrix-ref1 mat i j))
(= (matrix-ref1 mat i (- j 1)) 0)))
(define (LD? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat (+ i 1) (- j 1))
(matrix-ref1 mat i j))
(= (matrix-ref1 mat (- i 1) (+ j 1)) 0)))
(define (DN? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat (+ i 1) j)
(matrix-ref1 mat i j))
(= (matrix-ref1 mat (- i 1) j) 0)))
(define (RD? i j)
(and (not (= (matrix-ref1 mat i j) 0))
(= (matrix-ref1 mat (+ i 1) (+ j 1))
(matrix-ref1 mat i j))
(= (matrix-ref1 mat (- i 1) (- j 1)) 0)))
(define (check-LU i j)
(when (LU? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((< i1 1) #f)
((< j1 1) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop (- i1 1) (- j1 1) (+ cnt 1))))))))
(define (check-UP i j)
(when (UP? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((< i1 1) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop (- i1 1) j1 (+ cnt 1))))))))
(define (check-RU i j)
(when (RU? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((< i1 1) #f)
((> j1 10) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop (- i1 1) (+ j1 1) (+ cnt 1))))))))
(define (check-LT i j)
(when (LT? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((< j1 1) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop i1 (- j1 1)(+ cnt 1))))))))
(define (check-RT i j)
(when (RT? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((> j1 10) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop i1 (+ j1 1)(+ cnt 1))))))))
(define (check-LD i j)
(when (LD? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((> i1 10) #f)
((< j1 1) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop (+ i1 1) (- j1 1) (+ cnt 1))))))))
(define (check-DN i j)
(when (DN? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((> i1 10) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop (+ i1 1) j1 (+ cnt 1))))))))
(define (check-RD i j)
(when (RD? i j)
(let ((e (matrix-ref1 mat i j)))
(let loop ((i1 i) (j1 j) (cnt 0))
(cond ((> i1 10) #f)
((> j1 10) #f)
((and (= 0 (matrix-ref1 mat i1 j1))
(> cnt 2))
(answer e i j))
((not (= e (matrix-ref1 mat i1 j1))) #f)
(else
(loop (+ i1 1) (+ j1 1) (+ cnt 1))))))))
(define (answer e i j)
(set! init? #f)
(display "color=")(display e)(display " (")
(display (- i 1))(display ",")
(display (- j 1))(display ")")(newline))
norm> (find)
color=1 (5,3)
color=1 (5,5)
#<undef>
norm>