Я хочу, чтобы моя функция (с именем TRY), чтобы убедиться, что:Как заставить функцию try работать?
клетка не в клетках
координаты ячейки между 0 и лабиринтом размером 1
клеток затрагивает ровно одну ячейку в клетках.
Определение:
(define maze-size 15)
(define-struct Cell (x y))
(define (random-element a-list)
(list-ref a-list (random (length a-list))))
(define (random-adjacent cell)
(let ((neighbors (adjacents cell)))
(list-ref neighbors (random (length neighbors)))))
(define (count-in cell cells)
(cond
[(member? cell cells) 1]
[else 0]))
(define (touches cell cells)
(+
(count-in (make-Cell (Cell-x cell) (+ (Cell-y cell) 1)) cells)
(count-in (make-Cell (Cell-x cell) (+ (Cell-y cell) -1)) cells)
(count-in (make-Cell (+ (Cell-x cell) -1) (Cell-y cell)) cells)
(count-in (make-Cell (+ (Cell-x cell) 1) (Cell-y cell)) cells)))
Вот что у меня есть:
(define (try cell cells)
(cond [(=? 1(touches cell cells)) (member? cell cells) (=? 1(cell-post))]
[(zero? (random (sqr maze-size))) cells]
[else (extend cells)]))
и да, я знаю, что синтаксис является неправильным в первом состоянии, мои заявления Cond Арена Сильно.
В чем смысл синтаксиса в этом случае?
Имейте в виду, что это должно работать для этого кода:
(define (extend cells)
(try (random-adjacent cells) cells))