[QUIZ] Cows and Bulls (#32)

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

···

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Pat Eyler

My kids like to play a variant of "Cows and Bulls" when we're driving. One of
them (the server, to use a computing term -- you'll see why in a minute) will
think of a word (we usually play with either three or four letters), and the
other (the client) will try to guess it. With each guess, the server will
respond with the number of 'cows' (letters in the word, but not in the right
place) and bulls (letters in the correct place in the word).

Here's a short example:

  Server: (thinks of the word cow) I'm thinking of a three letter word.
  Client: cab
  Server: 0 cows and 1 bull
  Client: cat
  Server: 0 cows and 1 bull
  Client: cot
  Server: 0 cows and 2 bulls
  Client: cow
  Server: That's right!

This weeks quiz has a couple of flavors:

1) You can write a server that will play our version of "Cows and Bulls". It
should follow a simplified version of the above, and look like:

  Server: 3 # the number of letters in the word
  Client: "cab"
  Server: "0 1"
  Client: "cat"
  Server: "0 1"
  Client: "cot"
  Server: "0 2"
  Client: "cow"
  Server: 1 # indicating success

2) You should write also write a client that a player can interact with to play
the game.

3) You can also write a player that will interact with the server and play a
game.

Ruby Quiz wrote:

My kids like to play a variant of "Cows and Bulls" when we're driving.

See also: Mastermind game, break the hidden code!

···

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoil.com/&gt;

Thank you for the quiz,

My design this week focuses on orthogonality. I made a basic game
class, a network interface to the game class communicating via the
given protocoll, a readline interface and a simple AI. You can plug
together the local or network game class with the Human or AI Player.

Find the source code and documentation at

http://ruby.brian-schroeder.de/quiz/cows-and-bulls/

best regards,

Brian

···

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Glenn Parker wrote:

Ruby Quiz wrote:
>
> My kids like to play a variant of "Cows and Bulls" when we're

driving.

See also: Mastermind game, break the hidden code!

Or: http://bigweb.misty.com/weyer/js/pfb.htm

Thank you for the quiz for my part aswell,

Here's my kinda ad-hoc solution.
No AI player, but networking and a human-readable client.
Didn't use readline though, so it's not the most usable
thing around :confused:

Oh and it uses IO#readpartial which doesn't seem to be in 1.8.2 (2004-12-25).
My debian computator says it has 1.8.2 (2005-01-10), and that has it.

cows_and_bulls.rb (4.24 KB)

···

On 16.5.2005, at 12:18, Brian Schröder wrote:

Thank you for the quiz,

My design this week focuses on orthogonality. I made a basic game
class, a network interface to the game class communicating via the
given protocoll, a readline interface and a simple AI. You can plug
together the local or network game class with the Human or AI Player.

Find the source code and documentation at

http://ruby.brian-schroeder.de/quiz/cows-and-bulls/

You can grab my solution at:

http://rubyquiz.com/cowsnbulls.zip

I didn't build a player, but did provide three different interfaces.

The files in the zip are:

     cowsnbulls.rb -- The library that handles the game. Executing this gives a
                         command-line interface.
     tc_library.rb -- Unit tests for the library.
     telnet_server.rb -- Quiz solution. The protocol mentioned in the quiz didn't
                         appeal to me, so I just targeted Telnet instead. This isn't
                         exactly a true Telnet server, since it reads line-by-line
                         (You won't see an answer to an "Are You There" command, until
                         you press return, for example.), but it's close enough
                         for this exercise.
     web_server.rb -- Web interface through WEBrick servlets. (Just for fun.)
     english-words.10 -- The dictionary I've been using for testing. Part of
                         Spell Checking Oriented Word Lists (SCOWL) by Kevin Atkinson.

Enjoy.

James Edward Gray II