Go Fish: Difference between revisions

Line 401:
]
chand: [] ;-- c and p = computer and player
chand: []
cguesses: []
phand: []
Line 412 ⟶ 411:
***************
}
pip: ["a" "2" "3" "4" "5" "6" "7" "8" "9" "10" "j" "q" "k"] ;-- suits are not relevant
pile: [] ;-- where discarded cards go
pile: []
;---------------------
Line 425 ⟶ 424:
clear-and-show: func [duration str][
{
Poor persons animation.
Blips message to screen after a pause of duration length.
 
}
clear-screen
print str
Line 438 ⟶ 442:
find-in: func [blk str][
"Finds a string value in a block. Series in series."
foreach i blk [if find i str [return i]]
]
Line 445 ⟶ 450:
deal-cards num hand
][
append hand rejoin [trim/all form take pile] ;-- take from pile if deck is empty
append hand rejoin [trim/all form take pile]
]
]
Line 453 ⟶ 457:
{
Randomly picks from hand minus guessed.
 
Simulates a person asking for different cards on
their next turn if their previous guess resulted
Line 472 ⟶ 476:
return new-deck
]
shuffle: function [deck [block!]] [deck: random deck]
Line 478 ⟶ 481:
transfer-cards: func [
"Transfers cards from one handplayer to anotherplayer"
fhand "from hand"
thand "to hand"
Line 520 ⟶ 523:
][
if empty? fhand [go-fish 3 fhand]
 
if none? find-in thand kind [ ;-- player has to hold rank asked for
clear-and-show 1.0
"You have to have that rank in your hand to ask for it.^/Computers turn..."
exit
]
 
either find-in fhand kind [
check-for-books thand kind
transfer-cards fhand thand kind
show-cards
if find-in thand kind [ ;-- player has to have rank asked for
p: ask "Your guess: "
either p = "x" [halt][player-turn fhand thand p]
Line 536 ⟶ 546:
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"
Line 566 ⟶ 581:
}
if empty? chand [ ; computer has no more cards? fish 3 cards.
go-fish 3 chand
show-cards
Line 580 ⟶ 595:
}
 
if empty? phand [ ;-- player has no more cards? fish 3 cards.
go-fish 3 phand
show-cards
Line 604 ⟶ 619:
 
demo
 
</lang>
 
Anonymous user