I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Go Fish/PicoLisp

From Rosetta Code
Go Fish/PicoLisp is part of Go Fish. You may find other members of Go Fish at Category:Go Fish.
(de *Ranks
Ace 2 3 4 5 6 7 8 9 10 Jack Queen King )
(de goFish ()
(Ocean (by '(NIL (rand)) sort (mapcan '((R) (need 4 R)) *Ranks))
Your (cut 9 'Ocean)
Mine (cut 9 'Ocean)
YouHave NIL
YouDont NIL
YourBooks NIL
MyBooks NIL
Reply NIL
Options NIL
Request NIL )
(prin "Your Books: ")
(println YourBooks)
(prin "My Books: ")
(println MyBooks)
(T (nor Your Mine Ocean)
(let (Y (length YourBooks) M (length MyBooks))
((= Y M) "Tie game")
((> Y M) "You won!")
(T "I won!") ) ) ) )
(prin "You have ")
(println (sort Your))
(prinl "I have " (length Mine) " cards")
(if Ocean
"Ask for a rank, lay down a book, or 'draw' a card: "
"Ask for a rank or lay down a book: " ) )
(T (member (setq Reply (read)) *Ranks)
(ifn (filter = Mine (circ Reply))
" I don't have any card of rank "
(push 'YouHave Reply) )
(prin " I give you ")
(println @)
Mine (diff Mine @)
Your (append @ Your)
YouHave (append @ YouHave)
YouDont (diff YouDont @) ) ) )
(T (and Ocean (== 'draw Reply))
(prinl " You draw a " (push 'Your (pop 'Ocean)))
(off YouDont) )
((atom Reply)
(prin " The rank must be one of ")
(println *Ranks) )
((and (cdddr Reply) (member (car Reply) *Ranks) (not (cdr (uniq Reply))) (= (length Your) (length (append (diff Your Reply) Reply))))
(prin " You lay down the book ")
(println (push 'YourBooks Reply))
Your (diff Your Reply)
YouHave (diff YouHave Reply) ) )
(T (prinl " A book consists of four ranks, e.g. (7 7 7 7)")) ) )
((setq Options (diff (rot Mine) YouDont))
(setq Request
'((Opt) (= 3 (cnt = Mine (circ Opt))))
Options )
YouHave )
(sect Options YouHave)
Options ) ) )
(prin "Please give me all your " Request "s (or NIL): ")
(NIL (setq Reply (read))
(push 'YouDont Request)
(ifn Ocean
(prinl " I pass")
(prinl " I draw a card")
(push 'Mine (pop 'Ocean)) ) )
(T (and (pair Reply) (member Request Reply) (not (cdr (uniq Reply))) (= (length Your) (length (append (diff Your Reply) Reply))))
Your (diff Your Reply)
YouHave (diff YouHave Reply)
Mine (append Reply Mine) ) )
(prinl " I expect a list of " Request "s") ) )
(prinl " I draw a card")
(push 'Mine (pop 'Ocean)) )
(T (prinl " I pass")) )
(while (find '((R) (= 4 (cnt = Mine (circ R)))) *Ranks)
(let B (need 4 @)
(prin " I lay down the book ")
(println (push 'MyBooks B))
(setq Mine (diff Mine B)) ) )
(prinl) ) ) )