> 1 <

Автор Сообщение

Upierczi

Members


Статус

1 сообщений

Где: Kazakhstan
Род занятий:
Возраст:

#7149   2013-10-29 15:34 GMT+3 часа(ов)      
Нашел на этом форуме код игры пятнашки. Помогите пожалуйста разобраться, как произвести ввод данных?
P.S. писал хозяину кода ответа пока нет.

(defstruct board
r c cells)
(defun board-size (board)
(array-dimension (board-cells board) 0))

(defun move (board dr dc)
(let* ((size (board-size board))
(r (board-r board))
(c (board-c board))
(r1 (+ r dr))
(c1 (+ c dc)))
(if (and (< -1 r1 size) (< -1 c1 size))
(let* ((cells (board-cells board))
(cells1 (make-array (list size size)))
(board1 (make-board :r r1 :c c1 :cells cells1)))
(dotimes (row size)
(dotimes (col size)
(setf (aref cells1 row col) (aref cells row col))))
(rotatef (aref cells1 r c) (aref cells1 r1 c1))
board1)
nil)))

(defun generate-next (board exclude)
(loop for d in '((1 0) (0 1) (-1 0) (0 -1))
for (dr dc) = d
for b = (move board dr dc)
when (and b (not (eq d exclude))) collect (cons b d)))

(defun good-p (board)
(let ((cells (board-cells board))
(size (board-size board)))
(dotimes (i (- (* size size) 1)
t)
(let ((c (row-major-aref cells i)))
(unless (eql c (1+ i))
(return nil))))))

(defun find-good-from* (board rest last-move)
(cond ((good-p board)
(list board))
((zerop rest)
nil)
(t
(loop for (next . move) in (generate-next board last-move) do
(let ((solution (find-good-from* next (1- rest) move)))
(when solution
(return (cons board solution))))))))

(defun find-good-from (board)
(loop for rest from 0
thereis (find-good-from* board rest nil)))
> 1 <


Онлайн :

0 пользователь(ей), 38 гость(ей) :