Go Fish/PicoLisp: Difference between revisions

Content added Content deleted
mNo edit summary
(Feature: Sort user cards when shown; Flush output for Picolisps that do not fush their "prin"s in Windows console (Ersatz))
Line 3: Line 3:
<lang PicoLisp>(de *Ranks
<lang PicoLisp>(de *Ranks
Ace 2 3 4 5 6 7 8 9 10 Jack Queen King )
Ace 2 3 4 5 6 7 8 9 10 Jack Queen King )

(de goFish ()
(de goFish ()
(let
(let
Line 18: Line 18:
(loop
(loop
(prin "Your Books: ")
(prin "Your Books: ")
(flush)
(println YourBooks)
(println YourBooks)
(prin "My Books: ")
(prin "My Books: ")
(flush)
(println MyBooks)
(println MyBooks)
(T (nor Your Mine Ocean)
(T (nor Your Mine Ocean)
Line 29: Line 31:
(T "I won!") ) ) ) )
(T "I won!") ) ) ) )
(prin "You have ")
(prin "You have ")
(println Your)
(flush)
(println (sort Your))
(prinl "I have " (length Mine) " cards")
(prinl "I have " (length Mine) " cards")
(loop
(loop
Line 36: Line 39:
"Ask for a rank, lay down a book, or 'draw' a card: "
"Ask for a rank, lay down a book, or 'draw' a card: "
"Ask for a rank or lay down a book: " ) )
"Ask for a rank or lay down a book: " ) )
(flush)
(T (member (setq Reply (read)) *Ranks)
(T (member (setq Reply (read)) *Ranks)
(ifn (filter = Mine (circ Reply))
(ifn (filter = Mine (circ Reply))
Line 42: Line 46:
(push 'YouHave Reply) )
(push 'YouHave Reply) )
(prin " I give you ")
(prin " I give you ")
(flush)
(println @)
(println @)
(setq
(setq
Line 54: Line 59:
((atom Reply)
((atom Reply)
(prin " The rank must be one of ")
(prin " The rank must be one of ")
(flush)
(println *Ranks) )
(println *Ranks) )
((and (cdddr Reply) (member (car Reply) *Ranks) (not (cdr (uniq Reply))) (= (length Your) (length (append (diff Your Reply) Reply))))
((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 ")
(prin " You lay down the book ")
(flush)
(println (push 'YourBooks Reply))
(println (push 'YourBooks Reply))
(setq
(setq
Line 76: Line 83:
(loop
(loop
(prin "Please give me all your " Request "s (or NIL): ")
(prin "Please give me all your " Request "s (or NIL): ")
(flush)
(NIL (setq Reply (read))
(NIL (setq Reply (read))
(push 'YouDont Request)
(push 'YouDont Request)
Line 95: Line 103:
(let B (need 4 @)
(let B (need 4 @)
(prin " I lay down the book ")
(prin " I lay down the book ")
(flush)
(println (push 'MyBooks B))
(println (push 'MyBooks B))
(setq Mine (diff Mine B)) ) )
(setq Mine (diff Mine B)) ) )