![]() StartingPoints Sub-pages (up) Referenced by
|
The Code So Far/A Simple Life And Death Solver
Sub-page of TheCodeSoFar
I did say simple: this program kills and saves with single moves, it doesn't do look-ahead. To both kill and save a group, it looks for strings of the appropriate color with a single liberty, and then plays on that liberty. Wow, a 30K player in 30 lines of code :) This code slashes through the first 21 problems in Graded Go Problems For Beginners. Problem 22 exposes its weaknesses rather well:
White has not saved its bottom stones by extending. In fact, the solver needs to look ahead 14 moves to correctly analyse this situation. I love this: black's defect makes answering urgent, and the lone white stone's precise position is critical.
All manner of hacks to solve this can be considered: deep move searches, brutal alpha-beta pruning, local pattern matches, etc. I need to think before settling on a course here. /A Better Life And Death Solver tackles this problem.
Incidently, the solver was:
(defmethod solve-kill ((p Problem)) (let* ((sn (of-color (snake-set (game p)) (other (current-player (game p))))) (killable-snakes (mapcan (lambda (sn) (if (= 1 (length (liberties sn (pos (game p))))) (list sn))) sn))) (if killable-snakes (car (liberties (car killable-snakes) (pos (game p))))))) (defmethod solve-save ((p Problem)) (let* ((sn (of-color (snake-set (game p)) (current-player (game p)))) (savable-snakes (mapcan (lambda (sn) (if (= 1 (length (liberties sn (pos (game p))))) (list sn))) sn))) (if savable-snakes (car (liberties (car savable-snakes) (pos (game p))))))) (defmethod solve ((p Problem)) (cond ((eq (Action (Goal p)) 'Kill) (solve-kill p)) ((eq (ACtion (Goal p)) 'Save) (solve-save p)) (t nil))) (defmethod solution ((p Problem)) (let ((sol (solve p))) (if sol (printsl (move (game p) sol) (format nil "~A: Solved with ~A" (name p) (printb sol))) (printsl (game p) (format nil "Can't solve ~A" (name p)))) (if sol t ()))) This is a copy of the living page "The Code So Far/A Simple Life And Death Solver" at Sensei's Library. ![]() |