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

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

### Contact

 Search DelphiForFun.org only

 Red loses!

### Problem Description

Hip is a game invented by the well known recreational mathematician Martin Gardner. He named it Hip "because of the hipster's reputed  distain for squares".

The game is played on a 6X6 board. Each  player has 18 tokens and they take turns  placing tokens on any unoccupied square. The objective is to avoid completing any square by marking all 4 corners with his tokens. The square may be any size and tipped at any angle There are 105 such squares (several sample squares are initially displayed). You can right click on any point to see the squares with corners there.

The first player to complete a square is the loser.  There is essentially only one way for a complete game to end in a tie. Can you find it?

Source: My Best Mathematical and Logical Puzzles, Martin Gardner, Dover Pubs., 1994

### Background & Techniques

Here's another interesting Martin Gardner puzzle/game,  originally  published  in  his "Mathematical Recreations" Scientific American magazine column in the 60's.  Which explains his use of the the terms "Hip" and "Hipster" - terms probably unfamiliar to most of today's viewers.

In his write-up in the book referenced  above, he relates that for several months after first publication he had  assumed that a tie game was impossible.   Then a reader,  computer science major of course, found the tie game configuration.     I'll confess up front that I didn't  succeed in rediscovering the tie game -  this program  plays a tie game when  when computer plays computer, but the game played is simply a random display of the moves from the solution published in Gardner's book.

Two classes are defined:  TSquare defines the four corners of any square and identifies the how many of the corners are "owned" by each player.  Squarelist is a TStringlist that has a string version of the  sorted coordinates as a unique key for each square and a Tsquare object stored as a Objects entry.    Squarelist will always contain 105 entries.   In general it has been proven, (not by me),  that n x (n2-1) / 12 squares may be formed on an n x n board.

TPlayer identifies each player, whether it is a computer, and the points currently owned.  When a player makes a move,  the MakeMove procedure  scans Squarelist  to see if this point gives  4 corner ownership to this player for any square in the list  (i.e. he just completed a square and lost).

Custom cursors are defined to indicate the current player by color, red for player A and blue for player B.   Cursors are contained in resource file  Cursors.res.  Four files used to build Cusors.res;  (Cursors.rc, Genres,bat, Red.cur, and Blue.cur), are included with the source  for completeness but not required for compiling Hip.  Check the Custom Cursors page in the Delphi-Techniques section for more information.

Addendum August 20, 2008: This is the first update sine the program was posted in 2001.  Version 3 of HIP wad prompted by an email from Sadanand Kasargod [s_vkasargod@yahoo.com]  who spent what must have been a considerable amount of time searching for additional tie games on the 6x6 board.  I had quoted Gardner's comment that there is "essentially" only one way for a a game to end in a tie.  Sadanand found 3 others, but two are the same if one is rotated and the colors reversed.  We settled on three "essentially" different tie games that cannot be transformed into another by rotation, mirroring, or color reversal.    I added a button to replay tie games.  Other changes include the ability to retract moves to aid in studying game and choice of playing on 5x5, 6x6, and 7x7 game board sizes.   Again according to Gardner's book, My Best Mathematical and Logical Puzzles, ties are not possible for 7x7 boards or higher.

Addendum August 25, 2008:  When  updating this page last week, I noticed the suggestion for a variation of the rules which requires selecting 2 points for each turn after the first.    I created Version 4 with that option along with some enhancements to the retraction process.