Go Fish: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎{{header|Perl 6}}: Added PureBasic)
m (Corrected grammatical errors.)
Line 3: Line 3:


* Each player is dealt nine cards to start with.
* Each player is dealt nine cards to start with.
* On their turn, a player asks their opponent for a given rank (like threes or kings). A player must already have at least one card of a given rank to ask for more.
* On their turn, a player asks their opponent for a given rank (such as threes or kings). A player must already have at least one card of a given rank to ask for more.
** If the opponent has any cards of the named rank, they must hand over all such cards, and the requester can ask again.
** If the opponent has any cards of the named rank, they must hand over all such cards, and the requester can ask again.
** If the opponent has no cards of the named rank, the requester draws a card and ends their turn.
** If the opponent has no cards of the named rank, the requester draws a card and ends their turn.
* A ''book'' is a collection of every card of a given rank. Whenever a player completes a book, they may remove it from their hand.
* A ''book'' is a collection of every card of a given rank. Whenever a player completes a book, they may remove it from their hand.
* If at any time a player's hand is empty, they may immediately draw a new card, so long as any new cards remain in the deck.
* If at any time a player's hand is empty, they may immediately draw a new card, so long as any new cards remain in the deck.
* The game ends when every book is complete. The player with more books wins.
* The game ends when every book is complete. The player with the most books wins.


The game's AI need not be terribly smart, but it should use at least some strategy. That is, it shouldn't choose legal moves entirely at random.
The game's AI need not be terribly smart, but it should use at least some strategy. That is, it shouldn't choose legal moves entirely at random.

Revision as of 21:51, 31 May 2010

Task
Go Fish
You are encouraged to solve this task according to the task description, using any language you may know.

Write a program to let the user play Go Fish against a computer opponent. Use the following rules:

  • Each player is dealt nine cards to start with.
  • On their turn, a player asks their opponent for a given rank (such as threes or kings). A player must already have at least one card of a given rank to ask for more.
    • If the opponent has any cards of the named rank, they must hand over all such cards, and the requester can ask again.
    • If the opponent has no cards of the named rank, the requester draws a card and ends their turn.
  • A book is a collection of every card of a given rank. Whenever a player completes a book, they may remove it from their hand.
  • If at any time a player's hand is empty, they may immediately draw a new card, so long as any new cards remain in the deck.
  • The game ends when every book is complete. The player with the most books wins.

The game's AI need not be terribly smart, but it should use at least some strategy. That is, it shouldn't choose legal moves entirely at random.

You may want to use code from Playing Cards.

Haskell

See Go Fish/Haskell

OCaml

See Go Fish/OCaml

Perl 6

See Go Fish/Perl 6

PureBasic

See Go Fish/PureBasic

Python

See Go Fish/Python

Ruby

See Go Fish/Ruby

Tcl

See Go Fish/Tcl