Drag Colors Puzzle

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 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.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

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

Search DelphiForFun.org only

 

 

 

Problem Description

Drag colors to form a target pattern trying to match a "secret" pattern generated by the program.  After each guess the program will tell you the number of colors that are in the correct position.   The objective is to guess the pattern in the fewest number of trys. 

Background & Techniques

I received this email the other day:

I want to develop an application which generates a random, three part code using three colours. These colours can be repeated during the sequence. The main point im struggling with is that i want the user to drag and drop the colours into a guess sequence.

This is basically the main features of the program and i wondered if you can give me some feedback on how to code it.

I previously posted a Simple drag/drop demo program in the Delphi Techniques section which shows how to drag colors to targets.  I decided to finish the program and post it here.

Non-programmers are welcome to read on, but may want to skip to the bottom of this page to download executable version of the program.

I counted 46 lines of user written code in the source for this program, so we'll put it in the "Beginners" category.   Here are a few tricks that a beginner might want to pick up:

bulletWe use a "OnFormActivate" exit procedure to initialize the random number generator with the "randomize" statement so that secret codes  do not repeat each time we start program.   FormActivate also calls the ResetBtnClick procedure to set things up for a new game.
bulletBefore giving a message to the user, a couple of lines of code will maintain proper grammar by using singular verbs and nouns in the text when when we are referencing a single guess or a single item in the correct position.   
bulletThe ResetbtnClick procedure flashes several sets of random patterns before selecting one, just to add a little interest to the program.   Inside the the loop that generates the patterns, we will "sleep" for .05 seconds (50 milliseconds) for each set displayed.    I put the Sleep statement at the beginning of the loop so that no sharp-eyed player will be able to pick out the final pattern before we clear the display.    Note that there a common variable "Shape" is used to hold the particular shape being set (Shape1, Shape2, Shape3).  Note that for objects, statements like Shape:=Shape1  does not assign or move Shape1 to Shape.  It merely sets the pointer to Shape1 into the variable shape.   Before object oriented programming we needed a special pointer reference symbol (^)  to do this.    In fact this is one of the stumbling blocks to overcome when learning object oriented programming.  

I'm sure that there is more  to be done with this program.  It is similar to Mastermind, but less feedback information is provided to the user.  I have not yet succeeded to analyzing this version nor have I found an analysis of the game on the web.   That will be a first step to developing an automated guesser strategy that will find the pattern in the fewest number of guesses.  We could then rank players skill levels at guessing,  track how fast users develop a guessing strategy based on experience, etc.  

 

Running/Exploring the Program 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

User control over number of colors to choose from and number of colors in the guess pattern.
Implement an "auto-solve" procedure that uses an optimal guess strategy.  I  would probably use this to report the "best score" to player as a target goal. 
Previous suggestion will require an analysis of the puzzle to determine the best guess strategy.  

   

 

Original Date: March 27, 2004 

Modified: May 15, 2018

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