;ELC ;;; Compiled ;;; in Emacs version 28.0.50 ;;; with all optimizations. (byte-code "\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\307\310\311\312\313\314\315\316&\210\317\320\321\322\323DD\324\325\326%\210\317\327\321\322\330DD\331\325\326%\210\317\332\321\322\333DD\334\325\326%\210\317\335\321\322\336DD\337\325\326%\210\317\340\321\322\341DD\342\325\326%\210\317\343\321\322\344DD\345\325\346%\210\317\347\321\322\350DD\351\325\326%\210\317\352\321\322\353DD\354\325\326%\210\317\355\321\322\356DD\357\325\360%\210\317\361\321\322\362DD\363\325\360%\207" [require chess-algebraic chess-common chess-polyglot chess-ply chess-pos cl-lib custom-declare-group chess-ai nil "A simple chess engine written in Emacs Lisp.\n\nThis module does not allow to configure search time used to calculate\nreply moves. You can only specify the search depth (see `chess-ai-depth')." :group chess :link (custom-manual "(chess)AI") custom-declare-variable chess-ai-depth funcall function #[0 "\300\207" [2] 1] "The default search depth used to prune the search tree.\n\nIf `chess-ai-quiescence' is non-nil, quiescence search will be performed after\nthis ply depth limit has been reached." :type integer chess-ai-quiescence-depth #[0 "\300\207" [2] 1] "Search depth for quiescence search." chess-ai-pawn-value #[0 "\300\207" [100] 1] "Value of a Pawn." chess-ai-knight-value #[0 "\300\207" [300] 1] "Value of a Knight." chess-ai-bishop-value #[0 "\300\207" [300] 1] "Value of a Bishop." chess-ai-rook-value #[0 "\300\207" [500] 1] "Value of a Rook." intger chess-ai-queen-value #[0 "\300\207" [900] 1] "Value of a Queen." chess-ai-passed-pawn #[0 "\300\207" [50] 1] "Extra score for a passed Pawn." chess-ai-mobility #[0 "\300\207" [t] 1] "Non-nil if piece mobility should be considered during static evaluation." boolean chess-ai-quiescence #[0 "\300\207" [t] 1] "Non-nil if quiescence search should be performed."] 8) #@57 Calculate the static score for POSITION. (fn POSITION) (defalias 'chess-ai-eval-static #[257 "\306\211\307!\205 \211G\310U\262\204\311\312\313\314E\"\210\211\315H\262\211\316=\203'\317\207\211\320=\203/\306\207\321\211\211\211\211\211\211\211\211\211\322\306\211W\2035\211H\211\323U\204,\211\324U\203cB\262\\\262\266\202.\211\325U\203yB\262Z\262\266\202.\211\326U\203\220B\262 \\\262\266\202.\211\327U\203\247 B\262  Z\262\266\202.\211\330U\203\276\fB\262\f\n\\\262\266\202.\211\331U\203\325 B\262 \nZ\262\266\202.\211\332U\203\354\nB\262\n \\\262\266\202.\211\333U\203 B\262  Z\262\266\202.\211\334U\203B\262\f\\\262\266\202.\211\335U\203,B\262\fZ\262\266\211T\262\202;\266\203P\211G\336W\203P \337\340#G _\\\262\f\211\203iG\336W\203i \337\321#G _Z\262\f&\203\340' \341 \203\206\342\343\326\344%G\202\207\306\n\203\231\342\343\330\344%G\202\232\306 \203\254\342\343\332\344%G\202\255\306\203\277\342\343\334\344 %G\202\300\306$\341 \203\324\342\343\327\344%G\202\325\306\n\203\347\342\343\331\344%G\202\350\306 \203\372\342\343\333\344%G\202\373\306\203 \342\343\335\344 %G\202\306$Z\\\262\f)\f\211\307!\205!\211G\310U\262\204.\311\312\313\314E\"\210\211\345H\262\2039 \207 [\207" [chess-ai-pawn-value chess-ai-queen-value chess-ai-rook-value chess-ai-bishop-value chess-ai-knight-value chess-ai-passed-pawn 0 vectorp 75 signal wrong-type-argument chess-pos position 69 :checkmate -32767 :stalemate nil 64 32 80 112 81 113 82 114 66 98 78 110 7 chess-pos-passed-pawns t + chess-legal-plies :piece :candidates 70 chess-ai-mobility chess-ply-checking-mate] 25 (#$ . 1953)]) #@219 Return an ordered list of all legal plies for POSITION. Move ordering is rather naive at the moment. Capturing moves come first, the rest is sorted according to the square index. (fn POSITION &optional CAPTURE-ONLY) (defalias 'chess-ai-plies #[513 "\211\300!\205\f\211G\301U\262\204\302\303\304\305E\"\210\211\306H\262\307\310#\2042\311\312\313#\"\207\314\312\315\"\"\207" [vectorp 75 signal wrong-type-argument chess-pos position 70 chess-legal-plies :color sort make-closure #[514 "\302\211\211:\205\211@\303!\205\211G\304U\262\262\204#\305\306\307\310E\"\210\211A\262A@\211\211:\205>\211@\303!\205<\211G\304U\262\262\204K\305\306\307\310E\"\210\211A\262A@\300\303!\205^\211G\304U\262\204k\305\306\311\312E\"\210\211\250\203|\211\313Y\203|\211\314X\204\204\305\306\315\316E\"\210H\266\202>G\300\303!\205\231\211G\304U\262\204\246\305\306\311\312E\"\210\211\250\203\267\211\313Y\203\267\211\314X\204\277\305\306\315\316E\"\210H\266\202>GW\206\327\301\203\323\317\202\324\320\"\207" [V0 V1 (81 82 66 78 80 32) vectorp 75 signal wrong-type-argument chess-ply ply chess-pos position 0 63 #1=(integer 0 63) index < >] 13 "\n\n(fn A B)"] cl-delete-if #[257 "\300\211\211:\205\211@\301!\205\211G\302U\262\262\204#\303\304\305\306E\"\210\211A\262A@\301!\2054\211G\302U\262\204A\303\304\307\310E\"\210\211\250\203R\211\311Y\203R\211\312X\204Z\303\304\313\314E\"\210H\266\202\315U\207" [V0 vectorp 75 signal wrong-type-argument chess-ply ply chess-pos position 0 63 #1# index 32] 8 "\n\n(fn PLY)"]] 10 (#$ . 3731)]) #@119 Try to find a quiet position by evaluating only capturing moves. (fn POSITION DEPTH LOWER-BOUND UPPER-BOUND EVAL-FN) (defalias 'chess-ai-quiescence #[1285 "\211!\211Y\203 \207\211V\203\211\262\300U\203\207\301\302\"\303\211\211:\203H@\262\304\211\211:\205C\211@\305!\205A\211G\306U\262\262\204P\307\310\311\312E\"\210\313\314\"\206\315\316\211\211:\205n\211@\305!\205l\211G\306U\262\262\204{\307\310\311\312E\"\210\211@\262\211\305!\205\212\211G\306U\262\204\227\307\310\317\320E\"\210\321!\211\322\211\305!\205\250\211G\306U\262\204\265\307\310\317\320E\"\210\211\323H\262!\305!\205\306\211G\306U\262\204\323\307\310\317\320E\"\210\211<\204\340\307\310\324\325E\"\210\323I\266\262\211\211:\205\375\211@\305!\205\373\211G\306U\262\262\204\n\307\310\311\312E\"\210\211A\262#\326\"\210\327\314#\262\262\nS [ [\n%[\262V\2036\262Y\204HA\262\303\262\202$\266\207" [0 chess-ai-plies t nil chess-ai-quiescence vectorp 75 signal wrong-type-argument chess-ply ply chess-ply-keyword :next-pos apply chess-pos-move chess-pos position vconcat copy-alist 71 list annotations chess-pos-set-preceding-ply chess-ply-set-keyword] 24 (#$ . 5344)]) #@55 (fn POSITION DEPTH LOWER-BOUND UPPER-BOUND EVAL-FN) (defalias 'chess-ai-search #[1285 "\302U\203\203\300 %\207\211!\207\303!\211\204\"!\207\211\304\211\211:\203J@\262\305\211\211:\205E\211@\306!\205C\211G\307U\262\262\204R\310\311\312\313E\"\210\314\315\"\206\316\317\211\211:\205p\211@\306!\205n\211G\307U\262\262\204}\310\311\312\313E\"\210\211@\262\211\306!\205\214\211G\307U\262\204\231\310\311\320\321E\"\210\322!\211\323\211\306!\205\252\211G\307U\262\204\267\310\311\320\321E\"\210\211\324H\262!\306!\205\310\211G\307U\262\204\325\310\311\320\321E\"\210\211<\204\342\310\311\325\326E\"\210\324I\266\262\211\211:\205\377\211@\306!\205\375\211G\307U\262\262\204\f\310\311\312\313E\"\210\211A\262#\327\"\210\330\315#\262\262\nS [ [\n%[\262V\2038\262Y\204JA\262\304\262\202&\266\207" [chess-ai-quiescence chess-ai-quiescence-depth 0 chess-ai-plies nil chess-ai-search vectorp 75 signal wrong-type-argument chess-ply ply chess-ply-keyword :next-pos apply chess-pos-move chess-pos position vconcat copy-alist 71 list annotations chess-pos-set-preceding-ply chess-ply-set-keyword] 24 (#$ . 6581)]) #@518 Evaluate POSITION using a simple alpha-beta search algorithm using at least DEPTH plies. If `chess-ai-quiescence' is non-nil additionally only capturing moves are examined until a quiet position is reached. EVAL-FN is called for all leave nodes of the resulting tree. A `cons' cell is returned where `cdr' is the supposedly best move from POSITION and `car' is the score of that move. If there is no legal move from POSITION (or DEPTH is 0), `cdr' will be nil. (fn POSITION DEPTH LOWER-BOUND UPPER-BOUND EVAL-FN) (defalias 'chess-ai-eval #[1285 "\302U\203 \211!C\207\303\211\304\305\306\307\310\n\211\311!\205#\211G\312U\262\2040\313\314\315\316E\"\210\211\317H\262#\"\320\"*\211\204D!C\207\211@\321\322\323\324!\"\302G#\325\303:\203\244@\262\326\211\211:\205s\211@\311!\205q\211G\312U\262\262\204\200\313\314\327\330E\"\210\331\332\"\206K\333\334\211\211:\205\236\211@\311!\205\234\211G\312U\262\262\204\253\313\314\327\330E\"\210\211@\262\211\311!\205\272\211G\312U\262\204\307\313\314\315\316E\"\210\335!\211\336\211\311!\205\330\211G\312U\262\204\345\313\314\315\316E\"\210\211\337H\262!\311!\205\366\211G\312U\262\204\313\314\315\316E\"\210\211<\204\313\314\340\341E\"\210\337I\266\262\211\211:\205-\211@\311!\205+\211G\312U\262\262\204:\313\314\327\330E\"\210\211A\262#\342\"\210\343\332#\262\262 S\n[\f[ %[\303\247\203i@Y\205n\344#\266\345\303\346\"\210\211\nV\203\220\211\262\n\262\347\322\350\324 !##\210\210Y\204\244T\262A\262\202T\266\351!\210B\207" [chess-ai-quiescence chess-ai-mobility 0 nil sort mapcar #[257 "\302\303\304\211\211:\205\211@\305!\205\211G\306U\262\262\204&\307\310\311\312E\"\210\313\314\"\206\361\315\316\211\211:\205D\211@\305!\205B\211G\306U\262\262\204Q\307\310\311\312E\"\210\211@\262\211\305!\205`\211G\306U\262\204m\307\310\317\320E\"\210\321!\211\322\211\305!\205~\211G\306U\262\204\213\307\310\317\320E\"\210\211\323H\262!\305!\205\234\211G\306U\262\204\251\307\310\317\320E\"\210\211<\204\266\307\310\324\325E\"\210\323I\266\262\211\211:\205\323\211@\305!\205\321\211G\306U\262\262\204\340\307\310\311\312E\"\210\211A\262#\326\"\210\302\314#\262\262\327T \330%[#\210\207" [most-negative-fixnum most-positive-fixnum chess-ply-set-keyword :score chess-ai-search vectorp 75 signal wrong-type-argument chess-ply ply chess-ply-keyword :next-pos apply chess-pos-move chess-pos position vconcat copy-alist 71 list annotations chess-pos-set-preceding-ply 1 chess-ai-eval-static] 18 "\n\n(fn PLY)"] chess-legal-plies :color vectorp 75 signal wrong-type-argument chess-pos position 70 #[514 "\300\301\"\300\301\"V\207" [chess-ply-keyword :score] 6 "\n\n(fn LHS RHS)"] make-progress-reporter format "Thinking... (%s) " chess-ply-to-algebraic 1 chess-ai-search chess-ply ply chess-ply-keyword :next-pos apply chess-pos-move vconcat copy-alist 71 list annotations chess-pos-set-preceding-ply chess-ply-set-keyword progress-reporter-do-update accept-process-output 0.05 progress-reporter-force-update "Thinking... (%s {cp=%d}) " progress-reporter-done] 25 (#$ . 7790)]) #@122 Find the best move for POSITION. DEPTH defaults to the value of `chess-ai-depth'. (fn POSITION &optional DEPTH EVAL-FN) (defalias 'chess-ai-best-move #[769 "\303\206 T\n\206\304%A\207" [chess-ai-depth most-negative-fixnum most-positive-fixnum chess-ai-eval chess-ai-eval-static] 9 (#$ . 10987)]) #@30 (fn GAME EVENT &rest ARGS) (defalias 'chess-ai-handler #[642 "?\205[\306\267\202U\307\310\207\311\312!\207\211\204\313\314!\210\211\211\204%\313\314!\210\3158\262GS\262\316U\203?\317\320\n#\210\317\321 #\210\211\204H\313\314!\210\322\3158\323\"@\211\205\261\211\324\325\326\327\330\331\332&\206\257\211\211\211:\205v\211@\333!\205t\211G\334U\262\262\204\203\335\336\337\340E\"\210\211@\262\211\333!\205\222\211G\334U\262\204\237\335\336\341\342E\"\210\211\343H\262\211\205\255\324\344\345#\262\262\266\202\205[\346\347\312#\207\211\204\305\313\314!\210\322\3158\323\"@\211\205.\211\324\325\326\327\330\331\332&\206,\211\211\211:\205\363\211@\333!\205\361\211G\334U\262\262\204\335\336\337\340E\"\210\211@\262\211\333!\205\211G\334U\262\204\335\336\341\342E\"\210\211\343H\262\211\205*\324\344\345#\262\262\266\202?\205[\312\350\312!\f\351\352 !\203O\353 !\203O\354 \"\206R\355!\")\207\356\357$\207" [chess-engine-handling-event chess-engine-opponent-name chess-full-name chess-display-handling-event chess-engine-response-handler chess-polyglot-book #s(hash-table size 5 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (initialize 11 new 15 move 19 post-move 188 pass 188)) "Emacs AI" t chess-engine-set-position nil cl--assertion-failed game 3 1 chess-game-set-tag "White" "Black" last 2 chess-ply-any-keyword :drawn :perpetual :repetition :flag-fell :resign :aborted vectorp 75 signal wrong-type-argument chess-ply ply chess-pos position 74 :stalemate :checkmate chess-game-set-data active chess-engine-position move bufferp buffer-live-p chess-polyglot-book-ply chess-ai-best-move apply chess-common-handler] 14 (#$ . 11298)]) (provide 'chess-ai)