[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] Cows and Bulls (#32

James Gray

5/13/2005 11:30:00 AM

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.rub...

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.


5 Answers

Glenn Parker

5/13/2005 12:20:00 PM

0

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

See also: http://www.archimedes-lab.org/maste...

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoi...


Karl von Laudermann

5/13/2005 1:01:00 PM

0

Glenn Parker wrote:
> Ruby Quiz wrote:
> >
> > My kids like to play a variant of "Cows and Bulls" when we're
driving.
>
> See also: http://www.archimedes-lab.org/maste...

Or: http://bigweb.misty.com/weyer/...

Brian Schröder

5/16/2005 9:18:00 AM

0

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-sch...quiz/cows-...

best regards,

Brian

--
http://ruby.brian-sch...

Stringed instrument chords: http://chordlist.brian-sch...


Ilmari Heikkinen

5/16/2005 10:28:00 AM

0


James Gray

5/17/2005 2:58:00 PM

0

You can grab my solution at:

http://rubyquiz.com/cows...

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