picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

xchess (1420B)


      1 #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
      2 # 15jul11abu
      3 # (c) Software Lab. Alexander Burger
      4 
      5 (load "/usr/share/picolisp/games/chess.l")
      6 
      7 (de reply @
      8    (prinl (glue " " (rest)))
      9    (flush) )
     10 
     11 (de xmove ()
     12    (when (myMove)
     13       (let L (car *Undo)
     14          (reply "move"
     15             (pack
     16                (cdr (asoq (caar L) (cdr L)))
     17                (pick cdr (cdar L)) ) ) ) ) )
     18 
     19 (in NIL
     20    (loop
     21       (case (read)
     22          (protover
     23             (read)
     24             (reply "feature" "myname=\"PicoLisp Chess\"")
     25             (reply "feature" "time=0" "sigint=0" "usermove=1")
     26             (reply "feature" "done=1") )
     27          (accepted (read))
     28          (new
     29             (seed (in "/dev/urandom" (rd 3)))
     30             (setup (format (sys "XCHESS_DEPTH"))) )
     31          (level (line T))
     32          (sd (setup (read)))
     33          (black (off *Me) (on *You))
     34          (white (on *Me) (off *You))
     35          (usermove
     36             (let (L (line)  From (pack (head 2 L))  To (pack (head 2 (cddr L)))  F (get L 5))
     37                (if (and (yourMove (intern From) (intern To)) (or (not F) (= "q" F)))
     38                   (xmove)
     39                   (reply "Illegal move:" (pack L)) ) ) )
     40          (go (xchg '*Me '*You) (xmove))
     41          (undo (undo))
     42          (remove (undo) (undo))
     43          (result (line T))
     44          (random)
     45          (hard)
     46          (quit (bye))
     47          (T (reply "Error (unknown command):" @)) ) ) )
     48 
     49 # vi:et:ts=3:sw=3