Cows and Bulls

[Home]   [Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

 

Available Now

Search

Google

Search WWW

Search delphiforfun.org

 

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Help support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

Google
 

Search WWW

Search delphiforfun.org

 

 

Problem Description

Cows and Bulls is an the predecessor the game of Mastermind which uses the digits 0-9 instead of colored pegs.

Background & Techniques

"Cows and Bulls" (aka Bulls and Cows) is a version of the Game of Mastermind  previously published here on DFF but played with integer digits instead of colored pegs. The objective is to guess a secret pattern given feedback after each guess about the number of correct digits in the correct position (the Bulls), and the number of correct digits in the wrong position (the Cows).

According to Wikipedia, Cows and Bulls predates Mastermind and was probably the inspiration for that game.

There are now 10 digits to choose from in selecting or guessing a secret pattern. This version allows
patterns 3, 4, or 5 digits long. Zeros are valid as leading digits.

Choose whether you want to be the "Hider" (program searches for a pattern you choose) or the
"Seeker", (you try to find a secret number selected by the program). Select a digit length, default is 4, and
click the "Start" button to begin. pattern

For information about the programming and mathematics techniques used in the program, see the mastermind link above.  Because of the number of patterns to analyze and the algorithm used, the "Smarter than you" option for 5 digit numbers may take the program a few minutes to find its 2nd & 3rd guesses.

Addendum February 1, 2008:  Version 2 was posted today with several enhancements:

  • Patterns up to 6 digits long are handled now,
  • Repeated digits within the pattern may be permitted or not under user control. The  patterns for this option are generated using  TComboSet to create  permutations.  The TComboset class is contained in UComboV2 unit found in the DFFLibrary zip file available for download here.
  •  A  "Show progress" checkbox allows display of a summary of solution steps as the game progresses plus a display of up to 1000 patterns which have not been eliminated as solutions by preceding guesses.
  • In addition to selecting a role as "Hider" or "Seeker", the user can now also select to play "Both" roles.  This was added to assist in debugging, but may be useful as a learning tool to see the effect of pattern guesses and the resulting scores on the set of patterns which are possible solutions.
  • Searches for 5 and 6 digit numbers are significantly faster than in Version 1. 

   Running/Exploring the Program 

Suggestions for Further Explorations

bullet Done Feb, 2008:  In the "official" rules, digits may not be repeated in the pattern but in this program they can be.  It would be an easy addition to allow the player to optionally restrict the pattern to unique digits.
bullet Improve the efficiency of the min-max algorithm used in the "Smarter than you" IQ level which now may make take several minutes for the early guess when there are up to a million possible solutions remaining.

 

Original Date: September 24, 2007 

Modified: February 01, 2008

 


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2008, Gary Darby    All rights reserved.