Go Fish: Difference between revisions

Content added Content deleted
Line 476: Line 476:
return new-deck
return new-deck
]
]

show-cards: does [
clear-and-show 0 ""
print [newline "Player cards:" newline sort phand newline]
print ["Computer books:" cbooks]
print ["Player books:" pbooks newline]
]

shuffle: function [deck [block!]] [deck: random deck]
shuffle: function [deck [block!]] [deck: random deck]
;------------- end of helper functions -----------------
;------------- end of helper functions -----------------

check-for-books: func [
{
Checks for a book in a players hand.
Increments the players book score, and
discards the book from the players hand
}
hand "from or to hand"
kind "rank of cards"
/local
c "collected"
][
c: collect [
forall hand [keep find hand/1 kind]
]
remove-each i c [none = i]
if 4 = length? c [
either hand = phand [pbooks: pbooks + 1][cbooks: cbooks + 1]
remove-each i hand [if find/only c i [i]] ;-- remove book from hand
forall c [append pile c/1] ;-- append discarded book to the pile
]
]
transfer-cards: func [
transfer-cards: func [
Line 543: Line 573:
go-fish 1 thand
go-fish 1 thand
]
]
]
check-for-books: func [
{
Checks for a book in a players hand.
Increments the players book score, and
discards the book from the players hand
}
hand "from or to hand"
kind "rank of cards"
/local
c "collected"
][
c: collect [
forall hand [keep find hand/1 kind]
]
remove-each i c [none = i]
if 4 = length? c [
either hand = phand [pbooks: pbooks + 1][cbooks: cbooks + 1]
remove-each i hand [if find/only c i [i]] ;-- remove book from hand
forall c [append pile c/1] ;-- append discarded book to the pile
]
]
show-cards: does [
clear-and-show 0 ""
print [newline "Player cards:" newline sort phand newline]
print ["Computer books:" cbooks]
print ["Player books:" pbooks newline]
]
]
Line 605: Line 606:
]
]
demo: does [
main: does [
deck: shuffle make-deck
deck: shuffle make-deck
deal-cards 9 chand
deal-cards 9 chand
Line 618: Line 619:
]
]


main
demo
</lang>
</lang>