Go Fish/Unicon: Difference between revisions
< Go Fish
Content added Content deleted
m (Fixed syntax highlighting.) |
|||
(3 intermediate revisions by one other user not shown) | |||
Line 17: | Line 17: | ||
* (iii) Guess. This should also be in inverse proportion to what you hold in your hand. |
* (iii) Guess. This should also be in inverse proportion to what you hold in your hand. |
||
<syntaxhighlight lang="icon"> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
|||
<lang Icon> |
|||
link printf,strings |
link printf,strings |
||
Line 57: | Line 56: | ||
if *opponent.hand = 0 then DrawCard(opponent)# hand empty ? |
if *opponent.hand = 0 then DrawCard(opponent)# hand empty ? |
||
ifbook(player) # made a book ? |
ifbook(player) # made a book ? |
||
if *player.hand > 0 then return # signal success if cards left |
|||
} |
} |
||
else { |
else { |
||
printf("No, %s has no %s's - |
printf("No, %s has no %s's - %s draws a card\n",opponent.name,r,player.name) |
||
DrawCard(player) # draw from deck |
DrawCard(player) # draw from deck |
||
ifbook(player) # made a book ? |
ifbook(player) # made a book ? |
||
Line 130: | Line 129: | ||
printf("You: Does the computer have any %s's?\n",r) |
printf("You: Does the computer have any %s's?\n",r) |
||
return r |
return r |
||
end</ |
end</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
Line 138: | Line 137: | ||
Sample Game:<pre>Go fish. |
Sample Game:<pre>Go fish. |
||
You vs. the computer - your turn first: |
You vs. the computer - your turn first: |
||
Your hand : |
Your hand : 34688AAJK |
||
Your turn : |
Your turn : k |
||
You: Does the computer have any |
You: Does the computer have any K's? |
||
Yes, there was |
Yes, there was 2 K('s) |
||
Your hand : |
Your hand : 34688AAJKKK |
||
Your turn : |
Your turn : j |
||
You: Does the computer have any |
You: Does the computer have any J's? |
||
Yes, there was |
Yes, there was 1 J('s) |
||
Your hand : |
Your hand : 34688AAJJKKK |
||
Your turn : a |
|||
You: Does the computer have any A's? |
|||
No, Computer has no A's - Human draws a card |
|||
Computer: Do you have any 3's? |
|||
Yes, there was 1 3('s) |
|||
Computer: Do you have any 5's? |
|||
No, Human has no 5's - Computer draws a card |
|||
Your hand : 4688AAJJKKKQ |
|||
Your turn : 4 |
Your turn : 4 |
||
You: Does the computer have any 4's? |
You: Does the computer have any 4's? |
||
No, Computer has no 4's - drawing a card |
|||
Computer: Do you have any 6's? |
|||
No, Human has no 6's - drawing a card |
|||
Your hand : 2233344577AQQ |
|||
Your turn : 5 |
|||
You: Does the computer have any 5's? |
|||
Yes, there was 1 5('s) |
|||
Your hand : 22333445577AQQ |
|||
Your turn : 7 |
|||
You: Does the computer have any 7's? |
|||
No, Computer has no 7's - drawing a card |
|||
Computer: Do you have any 8's? |
|||
No, Human has no 8's - drawing a card |
|||
Your hand : 223334455779AQQ |
|||
Your turn : a |
|||
You: Does the computer have any A's? |
|||
No, Computer has no A's - drawing a card |
|||
Computer: Do you have any 4's? |
|||
Yes, there was 2 4('s) |
Yes, there was 2 4('s) |
||
Your hand : 444688AAJJKKKQ |
|||
Computer: Do you have any J's? |
|||
No, Human has no J's - drawing a card |
|||
Your hand : 22333556779AQQ |
|||
Your turn : q |
|||
You: Does the computer have any Q's? |
|||
No, Computer has no Q's - drawing a card |
|||
Computer: Do you have any 7's? |
|||
Yes, there was 2 7('s) |
|||
Computer: Do you have any 8's? |
|||
No, Human has no 8's - drawing a card |
|||
Your hand : 223335569AQQT |
|||
Your turn : t |
|||
You: Does the computer have any T's? |
|||
No, Computer has no T's - drawing a card |
|||
Computer: Do you have any K's? |
|||
No, Human has no K's - drawing a card |
|||
Your hand : 223335569AJQQT |
|||
Your turn : 6 |
Your turn : 6 |
||
You: Does the computer have any 6's? |
You: Does the computer have any 6's? |
||
Yes, there was 2 6('s) |
Yes, there was 2 6('s) |
||
Your hand : |
Your hand : 44466688AAJJKKKQ |
||
Your turn : 8 |
|||
You: Does the computer have any 8's? |
|||
No, Computer has no 8's - Human draws a card |
|||
Computer: Do you have any 3's? |
|||
No, Human has no 3's - Computer draws a card |
|||
Your hand : 44466688AAJJKKKQQ |
|||
Your turn : q |
Your turn : q |
||
You: Does the computer have any Q's? |
You: Does the computer have any Q's? |
||
No, Computer has no Q's - |
No, Computer has no Q's - Human draws a card |
||
Computer: Do you have any |
Computer: Do you have any 3's? |
||
No, Human has no 3's - Computer draws a card |
|||
Yes, there was 1 A('s) |
|||
Your hand : 444666888AAJJKKKQQ |
|||
Your turn : k |
|||
You: Does the computer have any K's? |
|||
No, Computer has no K's - Human draws a card |
|||
Computer: Do you have any 3's? |
|||
No, Human has no 3's - Computer draws a card |
|||
Your hand : 444666888AAJJKKKQQT |
|||
Your turn : t |
|||
You: Does the computer have any T's? |
|||
Yes, there was 1 T('s) |
|||
Your hand : 444666888AAJJKKKQQTT |
|||
Your turn : j |
|||
You: Does the computer have any J's? |
|||
No, Computer has no J's - Human draws a card |
|||
Computer: Do you have any 2's? |
|||
No, Human has no 2's - Computer draws a card |
|||
Your hand : 444666888AAAJJKKKQQTT |
|||
Your turn : a |
|||
You: Does the computer have any A's? |
|||
No, Computer has no A's - Human draws a card |
|||
Computer: Do you have any J's? |
Computer: Do you have any J's? |
||
Yes, there was |
Yes, there was 2 J('s) |
||
Computer: Do you have any 7's? |
Computer: Do you have any 7's? |
||
No, Human has no 7's - |
No, Human has no 7's - Computer draws a card |
||
Your hand : |
Your hand : 3444666888AAAKKKQQTT |
||
Your turn : 4 |
Your turn : 4 |
||
You: Does the computer have any 4's? |
You: Does the computer have any 4's? |
||
Yes, there was |
Yes, there was 1 4('s) |
||
Human made a book of 4's |
Human made a book of 4's |
||
Your hand : |
Your hand : 3666888AAAKKKQQTT |
||
Your turn : 7 |
|||
Try again, you must have at least one "7" in your hand |
|||
Your hand : 22333556669QQT |
|||
Your turn : 2 |
|||
You: Does the computer have any 2's? |
|||
No, Computer has no 2's - drawing a card |
|||
Computer: Do you have any 8's? |
|||
No, Human has no 8's - drawing a card |
|||
Your hand : 22333556669QQQT |
|||
Your turn : t |
|||
You: Does the computer have any T's? |
|||
No, Computer has no T's - drawing a card |
|||
Computer: Do you have any 9's? |
|||
Yes, there was 1 9('s) |
|||
Computer: Do you have any A's? |
|||
No, Human has no A's - drawing a card |
|||
Your hand : 22333555666QQQT |
|||
Your turn : 3 |
|||
You: Does the computer have any 3's? |
|||
No, Computer has no 3's - drawing a card |
|||
Computer: Do you have any 8's? |
|||
No, Human has no 8's - drawing a card |
|||
Your hand : 22333555666JQQQT |
|||
Your turn : 5 |
|||
You: Does the computer have any 5's? |
|||
No, Computer has no 5's - drawing a card |
|||
Computer: Do you have any 2's? |
|||
Yes, there was 2 2('s) |
|||
Computer: Do you have any 7's? |
|||
No, Human has no 7's - drawing a card |
|||
Your hand : 333555666AJQQQT |
|||
Your turn : 6 |
Your turn : 6 |
||
You: Does the computer have any 6's? |
You: Does the computer have any 6's? |
||
No, Computer has no 6's - |
No, Computer has no 6's - Human draws a card |
||
Computer: Do you have any 5's? |
Computer: Do you have any 5's? |
||
No, Human has no 5's - Computer draws a card |
|||
Yes, there was 3 5('s) |
|||
Your hand : 23666888AAAKKKQQTT |
|||
Computer made a book of 5's |
|||
Your turn : 8 |
|||
Computer: Do you have any K's? |
|||
You: Does the computer have any 8's? |
|||
No, Human has no K's - drawing a card |
|||
No, Computer has no 8's - Human draws a card |
|||
Your hand : 333666AJQQQTT |
|||
Computer: Do you have any 2's? |
|||
Your turn : a |
|||
Yes, there was 1 2('s) |
|||
You: Does the computer have any A's? |
|||
Computer: Do you have any 3's? |
|||
Yes, there was 2 A('s) |
|||
Your hand : 333666AAAJQQQTT |
|||
Your turn : j |
|||
You: Does the computer have any J's? |
|||
Yes, there was 2 J('s) |
|||
Your hand : 333666AAAJJJQQQTT |
|||
Your turn : 3 |
|||
You: Does the computer have any 3's? |
|||
Yes, there was 1 3('s) |
Yes, there was 1 3('s) |
||
Computer: Do you have any 7's? |
|||
No, Human has no 7's - Computer draws a card |
|||
Your hand : 666AAAJJJQQQTT |
|||
Your |
Your hand : 666888AAAJKKKQQTT |
||
Your turn : t |
|||
You: Does the computer have any 6's? |
|||
You: Does the computer have any T's? |
|||
No, Computer has no 6's - drawing a card |
|||
No, Computer has no T's - Human draws a card |
|||
Human made a book of 6's |
|||
Computer: Do you have any 7's? |
|||
No, Human has no 7's - Computer draws a card |
|||
Your hand : 888AAAJKKKQQTT |
|||
Your turn : q |
|||
You: Does the computer have any Q's? |
|||
No, Computer has no Q's - Human draws a card |
|||
Computer: Do you have any 8's? |
Computer: Do you have any 8's? |
||
Yes, there was 3 8('s) |
|||
Computer made a book of 8's |
|||
Your hand : 6667AAAJJJQQQTT |
|||
Computer: Do you have any J's? |
|||
Yes, there was 1 J('s) |
|||
Computer made a book of J's |
|||
Computer: Do you have any 9's? |
|||
No, Human has no 9's - Computer draws a card |
|||
Your hand : 5AAAKKKQQTT |
|||
Your turn : a |
Your turn : a |
||
You: Does the computer have any A's? |
You: Does the computer have any A's? |
||
No, Computer has no A's - |
No, Computer has no A's - Human draws a card |
||
Computer: Do you have any 7's? |
|||
Yes, there was 1 7('s) |
|||
Computer: Do you have any 9's? |
|||
No, Human has no 9's - Computer draws a card |
|||
Your hand : 5AAAKKKQQTT |
|||
Your turn : k |
|||
You: Does the computer have any K's? |
|||
No, Computer has no K's - Human draws a card |
|||
Computer: Do you have any T's? |
Computer: Do you have any T's? |
||
Yes, there was 2 T('s) |
Yes, there was 2 T('s) |
||
Computer: Do you have any |
Computer: Do you have any 9's? |
||
Yes, there was 1 9('s) |
|||
No, Human has no 8's - drawing a card |
|||
Computer: Do you have any 2's? |
|||
Your hand : 6667AAAJJJ |
|||
No, Human has no 2's - Computer draws a card |
|||
Your turn : j |
|||
Your hand : 5AAAKKKQQ |
|||
You: Does the computer have any J's? |
|||
Your turn : 5 |
|||
No, Computer has no J's - drawing a card |
|||
You: Does the computer have any 5's? |
|||
Yes, there was |
Yes, there was 2 5('s) |
||
Your hand : 555AAAKKKQQ |
|||
Computer made a book of A's |
|||
Your turn : q |
|||
Computer: Do you have any 8's? |
|||
You: Does the computer have any Q's? |
|||
No, Human has no 8's - drawing a card |
|||
Yes, there was 1 Q('s) |
|||
Your hand : 26667JJJ |
|||
Your |
Your hand : 555AAAKKKQQQ |
||
Your turn : k |
|||
You: Does the computer have any 7's? |
|||
You: Does the computer have any K's? |
|||
Yes, there was 3 7('s) |
|||
No, Computer has no K's - Human draws a card |
|||
Human made a book of 7's |
|||
Computer: Do you have any 2's? |
|||
Your hand : 2666JJJ |
|||
No, Human has no 2's - Computer draws a card |
|||
Your hand : 555AAAKKKQQQT |
|||
Your turn : t |
|||
You: Does the computer have any T's? |
|||
Yes, there was 3 T('s) |
|||
Human made a book of T's |
|||
Your hand : 555AAAKKKQQQ |
|||
Your turn : 5 |
|||
You: Does the computer have any 5's? |
|||
No, Computer has no 5's - Human draws a card |
|||
Computer: Do you have any Q's? |
|||
Yes, there was 3 Q('s) |
|||
Computer made a book of Q's |
|||
Computer: Do you have any 7's? |
|||
No, Human has no 7's - Computer draws a card |
|||
Your hand : 2555AAAKKK |
|||
Your turn : 2 |
Your turn : 2 |
||
You: Does the computer have any 2's? |
You: Does the computer have any 2's? |
||
Yes, there was 3 2('s) |
Yes, there was 3 2('s) |
||
Human made a book of 2's |
Human made a book of 2's |
||
Your hand : |
Your hand : 555AAAKKK |
||
Your turn : |
Your turn : 5 |
||
You: Does the computer have any |
You: Does the computer have any 5's? |
||
No, Computer has no 5's - Human draws a card |
|||
Yes, there was 1 6('s) |
|||
Computer: Do you have any A's? |
|||
Yes, there was 3 A('s) |
|||
Your hand : JJJ |
|||
Computer made a book of A's |
|||
Your turn : j |
|||
Computer: Do you have any 7's? |
|||
No, |
No, Human has no 7's - Computer draws a card |
||
Your hand : 3555KKK |
|||
Computer: Do you have any T's? |
|||
Your turn : 3 |
|||
No, Human has no T's - drawing a card |
|||
You: Does the computer have any 3's? |
|||
Your hand : 9JJJ |
|||
Yes, there was 3 3('s) |
|||
Your turn : 9 |
|||
Human made a book of 3's |
|||
You: Does the computer have any 9's? |
|||
Your hand : 555KKK |
|||
Yes, there was 3 9('s) |
|||
Human made a book of 9's |
|||
Your hand : JJJ |
|||
Your turn : j |
|||
You: Does the computer have any J's? |
|||
No, Computer has no J's - drawing a card |
|||
Computer: Do you have any T's? |
|||
No, Human has no T's - drawing a card |
|||
Computer made a book of 8's |
|||
Your hand : JJJK |
|||
Your turn : k |
Your turn : k |
||
You: Does the computer have any K's? |
You: Does the computer have any K's? |
||
No, Computer has no K's - Human draws a card |
|||
Yes, there was 3 K('s) |
|||
Human made a book of 5's |
|||
Computer: Do you have any 7's? |
|||
No, Human has no 7's - Computer draws a card |
|||
Computer made a book of 9's |
|||
Your hand : KKK |
|||
Your turn : k |
|||
You: Does the computer have any K's? |
|||
No, Computer has no K's - Human draws a card |
|||
Human made a book of K's |
Human made a book of K's |
||
Computer: Do you have any 7's? |
|||
Your hand : JJJ |
|||
Yes, there was 1 7('s) |
|||
Your turn : j |
|||
Computer made a book of 7's |
|||
You: Does the computer have any J's? |
|||
Final score: Computer=6, Human=7 - Human wins.</pre> |
|||
No, Computer has no J's - drawing a card |
|||
Computer: Do you have any T's? |
|||
Yes, there was 1 T('s) |
|||
Computer made a book of T's |
|||
Computer: Do you have any J's? |
|||
Yes, there was 3 J('s) |
|||
Computer made a book of J's |
|||
Computer is out of cards |
|||
Final score: Computer=5, Human=8 - Human wins.</pre> |
Latest revision as of 08:16, 31 August 2022
This is a two player version of Go Fish with a 9 card deal out where the human player always goes first. It is assumed that everyone will know what cards are booked out and what cards are fished. The computer acts as arbitrator so there is no way to lie, cheat, or steal.
Also, this program uses a simplified deck (no suits but four of each card) similar to some children's specialty decks.
The computer strategy relies on the following facts and public knowledge which are kept for each player in the player's public field. Public is a table by rank. A value of -1 indicates unknown state, any other value is the known number of cards.
- a. Public counts can be adjusted when a player makes a book.
- b. If the opponent asks for a card an unknown can be changed to a 1 as they have at least one card of this rank.
- c. When one or more cards are surrendered during fishing , the public counts of both players can be adjusted accordingly.
- d. A card drawn requires that counts of 0 be set to unknown unless the cards were booked out.
Strategy:
- (i) Request any known cases of 3 of a kind first.
- (ii) Request from other known cards second. The request should be in proportion to what you do not hold in your hand. That is if you have 1 J, you should have 3 chances of requesting it.
- (iii) Guess. This should also be in inverse proportion to what you hold in your hand.
printf.icn provides formatting strings.icn provides csort,deletec,strcnt,scramble
Sample Game:
Go fish. You vs. the computer - your turn first: Your hand : 34688AAJK Your turn : k You: Does the computer have any K's? Yes, there was 2 K('s) Your hand : 34688AAJKKK Your turn : j You: Does the computer have any J's? Yes, there was 1 J('s) Your hand : 34688AAJJKKK Your turn : a You: Does the computer have any A's? No, Computer has no A's - Human draws a card Computer: Do you have any 3's? Yes, there was 1 3('s) Computer: Do you have any 5's? No, Human has no 5's - Computer draws a card Your hand : 4688AAJJKKKQ Your turn : 4 You: Does the computer have any 4's? Yes, there was 2 4('s) Your hand : 444688AAJJKKKQ Your turn : 6 You: Does the computer have any 6's? Yes, there was 2 6('s) Your hand : 44466688AAJJKKKQ Your turn : 8 You: Does the computer have any 8's? No, Computer has no 8's - Human draws a card Computer: Do you have any 3's? No, Human has no 3's - Computer draws a card Your hand : 44466688AAJJKKKQQ Your turn : q You: Does the computer have any Q's? No, Computer has no Q's - Human draws a card Computer: Do you have any 3's? No, Human has no 3's - Computer draws a card Your hand : 444666888AAJJKKKQQ Your turn : k You: Does the computer have any K's? No, Computer has no K's - Human draws a card Computer: Do you have any 3's? No, Human has no 3's - Computer draws a card Your hand : 444666888AAJJKKKQQT Your turn : t You: Does the computer have any T's? Yes, there was 1 T('s) Your hand : 444666888AAJJKKKQQTT Your turn : j You: Does the computer have any J's? No, Computer has no J's - Human draws a card Computer: Do you have any 2's? No, Human has no 2's - Computer draws a card Your hand : 444666888AAAJJKKKQQTT Your turn : a You: Does the computer have any A's? No, Computer has no A's - Human draws a card Computer: Do you have any J's? Yes, there was 2 J('s) Computer: Do you have any 7's? No, Human has no 7's - Computer draws a card Your hand : 3444666888AAAKKKQQTT Your turn : 4 You: Does the computer have any 4's? Yes, there was 1 4('s) Human made a book of 4's Your hand : 3666888AAAKKKQQTT Your turn : 6 You: Does the computer have any 6's? No, Computer has no 6's - Human draws a card Computer: Do you have any 5's? No, Human has no 5's - Computer draws a card Your hand : 23666888AAAKKKQQTT Your turn : 8 You: Does the computer have any 8's? No, Computer has no 8's - Human draws a card Computer: Do you have any 2's? Yes, there was 1 2('s) Computer: Do you have any 3's? Yes, there was 1 3('s) Computer: Do you have any 7's? No, Human has no 7's - Computer draws a card Your hand : 666888AAAJKKKQQTT Your turn : t You: Does the computer have any T's? No, Computer has no T's - Human draws a card Human made a book of 6's Computer: Do you have any 7's? No, Human has no 7's - Computer draws a card Your hand : 888AAAJKKKQQTT Your turn : q You: Does the computer have any Q's? No, Computer has no Q's - Human draws a card Computer: Do you have any 8's? Yes, there was 3 8('s) Computer made a book of 8's Computer: Do you have any J's? Yes, there was 1 J('s) Computer made a book of J's Computer: Do you have any 9's? No, Human has no 9's - Computer draws a card Your hand : 5AAAKKKQQTT Your turn : a You: Does the computer have any A's? No, Computer has no A's - Human draws a card Computer: Do you have any 7's? Yes, there was 1 7('s) Computer: Do you have any 9's? No, Human has no 9's - Computer draws a card Your hand : 5AAAKKKQQTT Your turn : k You: Does the computer have any K's? No, Computer has no K's - Human draws a card Computer: Do you have any T's? Yes, there was 2 T('s) Computer: Do you have any 9's? Yes, there was 1 9('s) Computer: Do you have any 2's? No, Human has no 2's - Computer draws a card Your hand : 5AAAKKKQQ Your turn : 5 You: Does the computer have any 5's? Yes, there was 2 5('s) Your hand : 555AAAKKKQQ Your turn : q You: Does the computer have any Q's? Yes, there was 1 Q('s) Your hand : 555AAAKKKQQQ Your turn : k You: Does the computer have any K's? No, Computer has no K's - Human draws a card Computer: Do you have any 2's? No, Human has no 2's - Computer draws a card Your hand : 555AAAKKKQQQT Your turn : t You: Does the computer have any T's? Yes, there was 3 T('s) Human made a book of T's Your hand : 555AAAKKKQQQ Your turn : 5 You: Does the computer have any 5's? No, Computer has no 5's - Human draws a card Computer: Do you have any Q's? Yes, there was 3 Q('s) Computer made a book of Q's Computer: Do you have any 7's? No, Human has no 7's - Computer draws a card Your hand : 2555AAAKKK Your turn : 2 You: Does the computer have any 2's? Yes, there was 3 2('s) Human made a book of 2's Your hand : 555AAAKKK Your turn : 5 You: Does the computer have any 5's? No, Computer has no 5's - Human draws a card Computer: Do you have any A's? Yes, there was 3 A('s) Computer made a book of A's Computer: Do you have any 7's? No, Human has no 7's - Computer draws a card Your hand : 3555KKK Your turn : 3 You: Does the computer have any 3's? Yes, there was 3 3('s) Human made a book of 3's Your hand : 555KKK Your turn : k You: Does the computer have any K's? No, Computer has no K's - Human draws a card Human made a book of 5's Computer: Do you have any 7's? No, Human has no 7's - Computer draws a card Computer made a book of 9's Your hand : KKK Your turn : k You: Does the computer have any K's? No, Computer has no K's - Human draws a card Human made a book of K's Computer: Do you have any 7's? Yes, there was 1 7('s) Computer made a book of 7's Final score: Computer=6, Human=7 - Human wins.