Probably the worst implementation of the 5-puzzle problem you can write.
Artificial Intelligence
Assignment 1
Problem 09: Write GET-NEW-STATES to implement all possible movements of the empty tile for a given
state.
CG-USER(151): (defun get-new-states (state)
(setf new-states '())
(cond ((= 0 (first state)) (setf new-states (list (list (second state) 0 (third state) (fourth state)
(fifth state) (sixth state)) (list (fourth state) (second state) (third state) 0 (fifth state) (sixth state)))))
((= 0 (second state)) (setf new-states (list (list (first state) (fifth state) (third state) (fourth
state) 0 (sixth state)) (list 0 (first state) (third state) (fourth state) (fifth state) (sixth state)) (list (first
state) (third state) 0 (fourth state) (fifth state) (sixth state)))))
((= 0 (third state)) (setf new-states (list (list (first state) 0 (second state) (fourth state) (fifth
state) (sixth state)) (list (first state) (second state) (sixth state) (fourth state) (fifth state) 0))))
((= 0 (fourth state)) (setf new-states (list (list 0 (second state) (third state) (first state) (fifth
state) (sixth state)) (list (first state) (second state) (third state) (fifth state) 0 (sixth state)))))
((= 0 (fifth state)) (setf new-states (list (list (first state) 0 (third state) (fourth state) (second
state) (sixth state)) (list (first state) (second state) (third state) 0 (fourth state) (sixth state)) (list (first
state) (second state) (third state) (fourth state) (sixth state) 0))))
((= 0 (sixth state)) (setf new-states (list (list (first state) (second state) 0 (fourth state) (fifth
state) (third state)) (list (first state) (second state) (third state) (fourth state) 0 (fifth state)))))))
GET-NEW-STATES
CG-USER(152): (get-new-states '(1 2 3 4 5 0))
((1 2 0 4 5 3) (1 2 3 4 0 5))
CG-USER(153): (get-new-states '(1 2 3 4 0 5))
((1 0 3 4 2 5) (1 2 3 0 4 5) (1 2 3 4 5 0))
CG-USER(154): (get-new-states '(1 2 3 0 4 5))
((0 2 3 1 4 5) (1 2 3 4 0 5))
CG-USER(155): (get-new-states '(1 2 0 3 4 5))
((1 0 2 3 4 5) (1 2 5 3 4 0))
CG-USER(156): (get-new-states '(1 0 2 3 4 5))
((1 4 2 3 0 5) (0 1 2 3 4 5) (1 2 0 3 4 5))
CG-USER(157): (get-new-states '(0 1 2 3 4 5))
((1 0 2 3 4 5) (3 1 2 0 4 5))