home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / puzzles / archive / competition / part1 next >
Encoding:
Internet Message Format  |  1996-04-26  |  42.8 KB

  1. Received: from MIT.EDU (PACIFIC-CARRIER-ANNEX.MIT.EDU [18.69.0.28]) by bloom-picayune.MIT.EDU (8.6.13/2.3JIK) with SMTP id PAA04446; Sat, 20 Apr 1996 15:02:40 -0400
  2. Received: from [199.164.164.1] by MIT.EDU with SMTP
  3.     id AA15645; Sat, 20 Apr 96 14:10:58 EDT
  4. Received: by questrel.questrel.com (940816.SGI.8.6.9/940406.SGI)
  5.     for news-answers-request@mit.edu id LAA25192; Sat, 20 Apr 1996 11:11:56 -0700
  6. Newsgroups: rec.puzzles,news.answers,rec.answers
  7. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!questrel!chris
  8. From: chris@questrel.questrel.com (Chris Cole)
  9. Subject: rec.puzzles Archive (competition), part 06 of 35
  10. Message-Id: <puzzles/archive/competition/part1_745653851@questrel.com>
  11. Followup-To: rec.puzzles
  12. Summary: This is part of an archive of questions
  13.  and answers that may be of interest to
  14.  puzzle enthusiasts.
  15.  Part 1 contains the index to the archive.
  16.  Read the rec.puzzles FAQ for more information.
  17. Sender: chris@questrel.questrel.com (Chris Cole)
  18. Reply-To: archive-comment@questrel.questrel.com
  19. Organization: Questrel, Inc.
  20. References: <puzzles/archive/Instructions_745653851@questrel.com>
  21. Date: Wed, 18 Aug 1993 06:04:40 GMT
  22. Approved: news-answers-request@MIT.Edu
  23. Expires: Thu, 1 Sep 1994 06:04:11 GMT
  24. Lines: 1267
  25. Xref: senator-bedfellow.mit.edu rec.puzzles:24992 news.answers:11512 rec.answers:1912
  26. Apparently-To: news-answers-request@mit.edu
  27.  
  28. Archive-name: puzzles/archive/competition/part1
  29. Last-modified: 17 Aug 1993
  30. Version: 4
  31.  
  32.  
  33. ==> competition/contests/games.magazine.p <==
  34. What are the best answers to various contests run by _Games_ magazine?
  35.  
  36. ==> competition/contests/games.magazine.s <==
  37. Contest            Date        Archive Entry
  38. ----------------------    --------------    -----------------------------
  39. Equations        ? 1981        equations
  40. National Puzzle 1993    1993        npc.1993
  41. Nots and Crosses    ? 1992        nots.and.crosses
  42. Perfect Ladder        July 1993    perfect.ladder
  43. Telegrams        ?        telegrams
  44.  
  45. ==> competition/contests/national.puzzle/npc.1993.p <==
  46. What are the solutions to the Games magazine 1993 National Puzzle Contest?
  47.  
  48. ==> competition/contests/national.puzzle/npc.1993.s <==
  49. 1. 6, 10, 11, and 12 are in one group, and everything else is in the other.
  50. 2. 20
  51. 3. The upper-right segment of the first 8.
  52. 4. 6
  53. 5. d (ball point pen, analog watch, mattress, pogo stick): springs
  54. 6. a (Fire Engine, strawberry, lobster, lips): red
  55. 7. h (Icicle, paint, nose, faucet): drip
  56. 8. f (piggy bank, basketball, jack o' lantern, drum): hollow
  57. 9. g (horseshoe, goal post, stethoscope, fish hook): shaped like letters
  58. 10. e (flying bat, Xmas tree ornament, framed picture, trapeze artist): hang
  59. 11. b (candle, owl, vampire, pajamas): all associated with night
  60. 12. 4, 7, 2, 10, 5, 8, 1, 9, 6, 3
  61. 13. 152954
  62. 14. LIMA PERU
  63. 15. 44
  64. 16. 160
  65. 17. A
  66. 18. Flo Lisa Amy Joyce Kim. 
  67. 19. Top: AJKQ, 2nd Row: JKAQ, 3rd Row: KQAJ, 4th Row: JQAK
  68. 20. Joan Miro, Paavo Nurmi, Blaise Pascal
  69. 21. Top: 1, 8, 4  Middle: 6, 9, 3  Bottom: 2, 7, 5
  70. 22. d and g
  71. 23. Brenda: 87, Carrie: 85, Dick: 86, Harry: 84, Laura: 88, Tom: 83
  72. 24. If you number the columns 1-6 and letter the rows a-f, the first group
  73.     consists of 1a, 2a, 3a, 4a, 1b, 2b, 2c, 3c, 2d.  Other groups are
  74.     similarly shaped, rotated around the center point of the grid.
  75. 25. 2, 6, 5
  76. 26. Top: R O M  Middle: Q T A   Bottom: U E D S
  77. 27. 3 X 58 = 174 = 6 X 29
  78. 28. 5 (the number of enclosed areas in the letters of each month name)
  79. 29. too hard to describe -- easier than it looked
  80. 30. 80
  81. 31. 16
  82. 32. 4 (ADBECF ADBFCE ADFCBE BFDCAE)
  83. 33. 8 (delete 3,5,7,9,12,14,17,18)
  84. 34.  CONKP VALEY GSRCW TUIBI LANZS
  85.  
  86.  
  87. ==> competition/games/bridge.p <==
  88. Are there any programs for solving double-dummy Bridge?
  89.  
  90.  
  91. ==> competition/games/bridge.s <==
  92. I'll enclose my Double-Dummy solver for bridge.  I like this program
  93. because it contains a wildly unstructured "goto" -- which I claim is the
  94. most readable way to write the program.
  95.     Included are two test problems for the bridge-solver: a 6-card
  96. ending and a complete 13-card position.  The former should be very fast;
  97. the latter about 20 minutes on Sparcstation-2.  Each is *very*
  98. challenging for humans.
  99.  
  100. Regards, James
  101.  
  102. =============== clip; chmod +x; execute =============
  103. #!/bin/sh
  104. cat > bridge.c << 'EOF'
  105. /*
  106.  * DOUBLE_DUMMY
  107.  * Copyright (c) 1990 by
  108.  *    James D. Allen
  109.  *    19785 Stanton Ave
  110.  *    Castro Valley, CA
  111.  * Permission granted to use for any non-commercial purpose
  112.  *    as long as this notice is not removed.
  113.  *
  114.  * This program will solve double-dummy bridge problems.
  115.  * The algorithm is trivial: brute-force alpha-beta search (also known
  116.  *    as "backtracking").  The alpha-beta is trivial since we do not
  117.  *    consider overtricks or extra undertricks.
  118.  * The control flow is neat; this is a rare exception where software is
  119.  *    more readable with a "goto".  (Although I've tersified this to
  120.  *    the point where it is perhaps unreadable anyway :-)
  121.  */
  122.  
  123. #define    NUMP    4    /* The Players:  N, E, S, W */
  124. #define        NORTH    0
  125. #define        IS_CONT(x)    (!((x) & 1))    /* Is x on N/S team? */
  126. #define        LHO(x)        (((x) + 1) % NUMP)
  127. #define        RHO(x)        (((x) + NUMP - 1) % NUMP)
  128. char    *Playername[] = { "North", "East", "South", "West" };
  129.  
  130. #define    NUMS    4    /* The Suits:   S, H, D, C */
  131. char    Suitname[] = "SHDC";
  132. char    *Fullname[] = { "Spades\t", "Hearts\t", "Diamonds", "Clubs\t" };
  133.  
  134. /*
  135.  * Rank indices are 2 (Ace), 3 (King), ... 14 (Deuce)
  136.  * There is also a CARD Index which can be converted to from Rank and Suit.
  137.  */
  138. #define    CARD(Suit, Rank)    (((Suit) << 4) | (Rank))
  139. #define    SUIT(Card)        ((Card) >> 4)
  140. #define    RANK(Card)        ((Card) & 0xf)
  141. char    Rankname[] = "??AKQJT98765432";
  142. #define    INDEX(s, c)    ((char *)index(s, c) - (s))
  143.  
  144. /* A "SuitSet" is used to cope with more than one card at once: */
  145. typedef    unsigned short SuitSet;
  146. #define    MASK(Card)        (1 << RANK(Card))
  147. #define    REMOVE(Set, Card)    ((Set) &= ~(MASK(Card)))
  148.  
  149. /* And a CardSet copes with one SuitSet for each suit: */
  150. typedef struct cards {
  151.     SuitSet cc[NUMS];
  152. } CardSet;
  153.  
  154. /* Everything we wish to remember about a trick: */
  155. struct status {
  156.     CardSet st_hold[NUMP];    /* The players' holdings */
  157.     CardSet st_lgl[NUMP];    /* The players' remaining legal plays */
  158.     short    st_play[NUMP];    /* What the players played */
  159.     SuitSet st_trick;    /* Led-suit Cards eligible to win trick */
  160.     SuitSet st_trump;    /* Trump Cards eligible to win trick */
  161.     short    st_leader;    /* Who led to the trick */
  162.     short    st_suitled;    /* Which suit was led */
  163. }
  164. Status[14]; /* Status of 13 tricks and a red zone" */
  165. #define    Hold    Statp->st_hold
  166. #define    Resid    (Statp+1)->st_hold
  167. #define    Lgl    Statp->st_lgl
  168. #define    Play    Statp->st_play
  169. #define    Trick    Statp->st_trick
  170. #define    Trtrick    Statp->st_trump
  171. #define    Leader    Statp->st_leader
  172. #define    Suitled    Statp->st_suitled
  173.  
  174. /* Pick a card from the set and return its index */
  175. pick(set)
  176.     SuitSet set;
  177. {
  178.     return set & 0xff ? set &  1 ? 0 : set &  2 ? 1 : set &  4 ? 2
  179.               : set &  8 ? 3 : set & 16 ? 4 : set & 32 ? 5
  180.               : set & 64 ? 6 : 7 : pick(set >> 8) + 8;
  181. }
  182.  
  183. #define    highcard(set)    pick(set) /* Pick happens to return the best card */
  184.  
  185. main()
  186. {
  187.     register struct status *Statp = Status;    /* Point to current status */
  188.     int    tnum;    /* trick number */
  189.     int    won;    /* Total tricks won by North/South */
  190.     int    nc;    /* cards on trick */
  191.     int    ohsize;    /* original size of hands */
  192.     int    mask;
  193.     int    trump;
  194.     int    player;    /* player */
  195.     int    pwin;    /* player who won trick */
  196.     int    suit;    /* suit to play */
  197.     int    wincard; /* card which won the trick */
  198.     int    need;    /* Total tricks needed by North/South */
  199.     int    cardx;    /* Index of a card under consideration */
  200.     int    success; /* Was the trick or contract won by North/South ? */
  201.     int    last_t;    /* Decisive trick number */
  202.     char    asciicard[60];
  203.     SuitSet inplay;    /* cards still in play for suit */
  204.     SuitSet pr_set;    /* Temp for printing */
  205.  
  206.     /* Read in the problem */
  207.     printf("Enter trump suit (0-S,1-H,2-D,3-C,4-NT): ");
  208.     scanf("%d", &trump);
  209.     printf("Enter how many tricks remain to be played: ");
  210.     scanf("%d", &ohsize);
  211.     printf("Enter how many tricks North/South need to win: ");
  212.     scanf("%d", &need);
  213.     printf("Enter who is on lead now (0=North,etc.): ");
  214.     scanf("%d", &pwin);
  215.     printf("Enter the %d cards beginning with North:\n", NUMP * ohsize);
  216.     for (player = NORTH; player < NUMP; player++) {
  217.         for (tnum = 0; tnum < ohsize; tnum++) {
  218.             scanf("%s", asciicard);
  219.             cardx = CARD(INDEX(Suitname, asciicard[1]),
  220.                     INDEX(Rankname, asciicard[0]));
  221.             Hold[player].cc[SUIT(cardx)] |= MASK(cardx);
  222.         }
  223.     }
  224.  
  225.     /* Handle the opening lead */
  226.     printf("Enter the directed opening lead or XX if none:\n");
  227.     Lgl[pwin] = Hold[pwin];
  228.     scanf("%s", asciicard);
  229.     if (asciicard[0] == 'X') {
  230.         strcpy(asciicard, "anything");
  231.     } else {
  232.         cardx = CARD(INDEX(Suitname, asciicard[1]),
  233.                 INDEX(Rankname, asciicard[0]));
  234.         for (suit = 0; suit < NUMS; suit++)
  235.             if (suit != SUIT(cardx))
  236.                 Lgl[pwin].cc[suit] = 0;
  237.             else if (!(Lgl[pwin].cc[suit] &= MASK(cardx))) {
  238.                 printf("He can't lead card he doesn't have\n");
  239.                 exit(1);
  240.             }
  241.     }
  242.  
  243.     /* Print the problem */
  244.     for (player = NORTH; player < NUMP; player++) {
  245.         printf("\n---- %s Hand ----:\n", Playername[player]);
  246.         for (suit = 0; suit < NUMS; suit++) {
  247.             printf("\t%s\t", Fullname[suit]);
  248.             for (pr_set = Hold[player].cc[suit]; pr_set;
  249.                     REMOVE(pr_set, pick(pr_set)))
  250.                 printf("%c ", Rankname[RANK(pick(pr_set))]);
  251.             printf("\n");
  252.         }
  253.     }
  254.     printf("\n%s%s Trumps; %s leads %s; N-S want %d tricks; E-W want %d\n",
  255.         trump < NUMS ? Fullname[trump] : "",
  256.         trump < NUMS ? " are" : "No",
  257.         Playername[pwin], asciicard, need, ohsize + 1 - need);
  258.  
  259.       /* Loop to play tricks forward until the outcome is conclusive */
  260.     for (tnum = won = success = 0;
  261.             success ? ++won < need : won + ohsize >= need + tnum;
  262.             tnum++, Statp++, success = IS_CONT(pwin)) {
  263.         for (nc = 0, player = Leader = pwin; nc < NUMP;
  264.                     nc++, player = LHO(player)) {
  265.               /* Generate legal plays except opening lead */
  266.             if (nc || tnum)
  267.                 Lgl[player] = Hold[player];
  268.               /* Must follow suit unless void */
  269.             if (nc && Lgl[player].cc[Suitled])
  270.                 for (suit = 0; suit < NUMS; suit++)
  271.                     if (suit != Suitled)
  272.                         Lgl[player].cc[suit] = 0;
  273.             goto choose_suit; /* this goto is easily eliminated */
  274.               /* Comes back right away after choosing "suit"  */
  275.             make_play:
  276.             Play[player] = cardx =
  277.                 CARD(suit, pick(Lgl[player].cc[suit]));
  278.             if (nc == 0) {
  279.                 Suitled = suit;
  280.                 Trick = Trtrick = 0;
  281.             }
  282.               /* Set the play into "Trick" if it is win-eligible */
  283.             if (suit == Suitled)
  284.                 Trick |= MASK(cardx);
  285.             if (suit == trump)
  286.                 Trtrick |= MASK(cardx);
  287.  
  288.               /* Remove card played from player's holding */
  289.             Resid[player] = Hold[player];
  290.             REMOVE(Resid[player].cc[suit], cardx);
  291.         }
  292.  
  293.           /* Finish processing the trick ... who won? */
  294.         if (Trtrick)
  295.             wincard = CARD(trump, highcard(Trtrick));
  296.         else
  297.             wincard = CARD(Suitled, highcard(Trick));
  298.         for (pwin = 0; Play[pwin] != wincard; pwin++)
  299.             ;
  300.     }
  301.  
  302.       /* Loop to back up and let the players try alternatives */
  303.     for (last_t = tnum--, Statp--; tnum >= 0; tnum--, Statp--) {
  304.         won -= IS_CONT(pwin);
  305.         pwin = Leader;
  306.         for (player = RHO(Leader), nc = NUMP-1; nc >= 0;
  307.                     player = RHO(player), nc--) {
  308.               /* What was the play? */
  309.             cardx = Play[player];
  310.             suit = SUIT(cardx);
  311.               /* Retract the played card */
  312.             if (suit == Suitled)
  313.                 REMOVE(Trick, cardx);
  314.             if (suit == trump)
  315.                 REMOVE(Trtrick, cardx);
  316.               /* We also want to remove any redundant adjacent plays */
  317.             inplay =  Hold[0].cc[suit] | Hold[1].cc[suit]
  318.                 | Hold[2].cc[suit] | Hold[3].cc[suit];
  319.             for (mask = MASK(cardx); mask <= 0x8000; mask <<= 1)
  320.                 if (Lgl[player].cc[suit] & mask)
  321.                     Lgl[player].cc[suit] &= ~mask;
  322.                 else if (inplay & mask)
  323.                     break;
  324.               /* If the card was played by a loser, try again */
  325.             if (success ? !(IS_CONT(player)) : IS_CONT(player)) {
  326.                 choose_suit:
  327.                   /* Pick a suit if any untried plays remain */
  328.                 for (suit = 0; suit < NUMS; suit++)
  329.                     if (Lgl[player].cc[suit])
  330.                         /* This goto is really nice!! */
  331.                         goto make_play;
  332.             }
  333.         }
  334.     }
  335.  
  336.     /*
  337.      * We're done.  We know the answer.
  338.      * We can't remember all the variations; fortunately the
  339.      *  succeeders played correctly in the last variation examined,
  340.      * so we'll just print it.
  341.      */
  342.     printf("Contract %s, for example:\n",
  343.             success ? "made" : "defeated");
  344.     for (tnum = 0, Statp = Status; tnum < last_t; tnum++, Statp++) {
  345.         printf("Trick %d:", tnum + 1);
  346.         for (player = 0; player < Leader; player++)
  347.             printf("\t");
  348.         for (nc = 0; nc < NUMP; nc++, player = LHO(player))
  349.             printf("\t%c of %c",
  350.                 Rankname[RANK(Play[player])],
  351.                 Suitname[SUIT(Play[player])]);
  352.         printf("\n");
  353.     }
  354.     return 0;
  355. }
  356. EOF
  357. cc -O -o bridge bridge.c
  358. bridge << EOF
  359. 4 6 5 2
  360. AS JS 4S QD 8D 2C
  361. KS QS 9H 8H AD 2D
  362. AH 2H KD 9D 7D AC
  363. TS 3S 2S TH TD TC
  364. XX
  365. EOF
  366. bridge << EOF
  367. 1 13 13 3
  368. 3C          3H 2H              AD KD 2D    AS KS 7S 6S 5S 4S 3S
  369. 8C 7C 6C 5C 4C    QH TH 8H 7H          8D 7D 6D    2S
  370. AC QC JC 9C      AH KH JH 9H 6H 5H      5D 4D 3D
  371. KC TC 2C      4H              QD JD TD 9D    QS JS TS 9S 8S
  372. QS
  373. EOF
  374.  
  375.  
  376.  
  377. ==> competition/games/chess/knight.control.p <==
  378. How many knights does it take to attack or control the board?
  379.  
  380. ==> competition/games/chess/knight.control.s <==
  381. Fourteen knights are required to attack every square:
  382.  
  383.     1   2   3   4   5   6   7   8
  384.    ___ ___ ___ ___ ___ ___ ___ ___
  385. h |   |   |   |   |   |   |   |   |  
  386.    --- --- --- --- --- --- --- ---
  387. g |   |   | N | N | N | N |   |   |
  388.    --- --- --- --- --- --- --- ---
  389. f |   |   |   |   |   |   |   |   |
  390.    --- --- --- --- --- --- --- ---
  391. e |   | N | N |   |   | N | N |   |
  392.    --- --- --- --- --- --- --- ---
  393. d |   |   |   |   |   |   |   |   |
  394.    --- --- --- --- --- --- --- ---
  395. c |   | N | N | N | N | N | N |   |
  396.    --- --- --- --- --- --- --- ---
  397. b |   |   |   |   |   |   |   |   |
  398.    --- --- --- --- --- --- --- ---
  399. a |   |   |   |   |   |   |   |   |
  400.    --- --- --- --- --- --- --- ---
  401.  
  402. Three knights are needed to attack h1, g2, and a8; two more for b1, a2,
  403. and b3, and another two for h7, g8, and f7.
  404.  
  405. The only alternative pattern is:
  406.  
  407.     1   2   3   4   5   6   7   8
  408.    ___ ___ ___ ___ ___ ___ ___ ___
  409. h |   |   |   |   |   |   |   |   |  
  410.    --- --- --- --- --- --- --- ---
  411. g |   |   | N |   |   | N |   |   |
  412.    --- --- --- --- --- --- --- ---
  413. f |   |   | N | N | N | N |   |   |
  414.    --- --- --- --- --- --- --- ---
  415. e |   |   |   |   |   |   |   |   |
  416.    --- --- --- --- --- --- --- ---
  417. d |   |   | N | N | N | N |   |   |
  418.    --- --- --- --- --- --- --- ---
  419. c |   | N | N |   |   | N | N |   |
  420.    --- --- --- --- --- --- --- ---
  421. b |   |   |   |   |   |   |   |   |
  422.    --- --- --- --- --- --- --- ---
  423. a |   |   |   |   |   |   |   |   |
  424.    --- --- --- --- --- --- --- ---
  425.  
  426. Twelve knights are needed to control (attack or occupy) the board:
  427.  
  428.     1   2   3   4   5   6   7   8
  429.    ___ ___ ___ ___ ___ ___ ___ ___
  430. a |   |   |   |   |   |   |   |   |  
  431.    --- --- --- --- --- --- --- ---
  432. b |   |   | N |   |   |   |   |   |
  433.    --- --- --- --- --- --- --- ---
  434. c |   |   | N | N |   | N | N |   |
  435.    --- --- --- --- --- --- --- ---
  436. d |   |   |   |   |   | N |   |   |
  437.    --- --- --- --- --- --- --- ---
  438. e |   |   | N |   |   |   |   |   |
  439.    --- --- --- --- --- --- --- ---
  440. f |   | N | N |   | N | N |   |   |
  441.    --- --- --- --- --- --- --- ---
  442. g |   |   |   |   |   | N |   |   |
  443.    --- --- --- --- --- --- --- ---
  444. h |   |   |   |   |   |   |   |   |
  445.    --- --- --- --- --- --- --- ---
  446.  
  447. Each knight can control at most one of the twelve squares a1, b1, b2,
  448. h1, g1, g2, a8, b8, b7, h8, g8, g7.  This position is unique up to
  449. reflection.
  450.  
  451. References
  452.     Martin Gardner, _Mathematical Magic Show_.
  453.  
  454. ==> competition/games/chess/knight.most.p <==
  455. What is the maximum number of knights that can be put on n x n chessboard
  456. without threatening each other?
  457.  
  458. ==> competition/games/chess/knight.most.s <==
  459. n^2/2 for n even >= 4.
  460.  
  461. Divide the board in parts of 2x4 squares. The squares within
  462. each part are paired as follows:
  463.  
  464. -----
  465. |A|B|
  466. -----
  467. |C|D|
  468. -----
  469. |B|A|
  470. -----
  471. |D|C|
  472. -----
  473.  
  474. Clearly, not more than one square per pair can be occupied by a knight.
  475.  
  476. ==> competition/games/chess/knight.tour.p <==
  477. For what size boards are knight tours possible?
  478.  
  479. ==> competition/games/chess/knight.tour.s <==
  480. A tour exists for boards of size 1x1, 3x4, 3xN with N >= 7, 4xN with N >= 5,
  481. and MxN with N >= M >= 5.  In other words, for all rectangles except 1xN
  482. (excluding the trivial 1x1), 2xN, 3x3, 3x5, 3x6, 4x4.
  483.  
  484. With the exception of 3x8 and 4xN, any even-sized board which allows a tour
  485. will also allow a closed (reentrant) tour.
  486.  
  487. On an odd-sided board, there is one more square of one color than
  488. of the other.  Every time a knight moves, it moves to a square of
  489. the other color than the one it is on.  Therefore, on an odd-sided
  490. board, it must end the last move but one of the complete, reentrant
  491. tour on a square of the same color as that on which it started.
  492. It is then impossible to make the last move, for that move would end
  493. on a square of the same color as it begins on.
  494.  
  495. Here is a solution for the 7x7 board (which is not reentrant).
  496.      ------------------------------------
  497.      | 17 |  6 | 33 | 42 | 15 |  4 | 25 |
  498.      ------------------------------------
  499.      | 32 | 47 | 16 |  5 | 26 | 35 | 14 |
  500.      ------------------------------------
  501.      |  7 | 18 | 43 | 34 | 41 | 24 |  3 |
  502.      ------------------------------------
  503.      | 46 | 31 | 48 | 27 | 44 | 13 | 36 |
  504.      ------------------------------------
  505.      | 19 |  8 | 45 | 40 | 49 |  2 | 23 |
  506.      ------------------------------------
  507.      | 30 | 39 | 10 | 21 | 28 | 37 | 12 |
  508.      ------------------------------------
  509.      |  9 | 20 | 29 | 38 | 11 | 22 |  1 |
  510.      ------------------------------------
  511.  
  512. Here is a solution for the 5x5 board (which is not reentrant).
  513.      --------------------------
  514.      |  5 | 10 | 15 | 20 |  3 |
  515.      --------------------------
  516.      | 16 | 21 |  4 |  9 | 14 |
  517.      --------------------------
  518.      | 11 |  6 | 25 |  2 | 19 |
  519.      --------------------------
  520.      | 22 | 17 |  8 | 13 | 24 |
  521.      --------------------------
  522.      |  7 | 12 | 23 | 18 |  1 |
  523.      --------------------------
  524.  
  525. Here is a reentrant 2x4x4 tour:
  526.      0 11 16  3    15  4  1 22
  527.     19 26  9 24     8 23 14 27
  528.     10  5 30 17    31 12 21  2
  529.     29 18 25  6    20  7 28 13
  530. A reentrant 4x4x4 tour can be constructed by splicing two copies.
  531.  
  532. It shouldn't be much more work now to completely solve the problem of which 3D
  533. rectangular boards allow tours.
  534.  
  535. Warnsdorff's rule: at each stage of the knight's tour, choose the
  536. square with the fewest remaining exits:
  537.  
  538.  1 12 23 44  3 14 25
  539. 22 43  2 13 24 35  4
  540. 11 28 45 40 47 26 15
  541. 42 21 48 27 34  5 36
  542. 29 10 41 46 39 16 33
  543. 20 49  8 31 18 37  6
  544.  9 30 19 38  7 32 17
  545.  
  546. Mr. Beverley published in the Philosophical Magazine in 1848 this
  547. knight's tour that is also a magic square:
  548.  
  549.  1 30 47 52  5 28 43 54
  550. 48 51  2 29 44 53  6 27
  551. 31 46 49  4 25  8 55 42
  552. 50  3 32 45 56 41 26  7
  553. 33 62 15 20  9 24 39 58
  554. 16 19 34 61 40 57 10 23
  555. 63 14 17 36 21 12 59 38
  556. 18 35 64 13 60 37 22 11 
  557.  
  558. References:
  559. ``The Construction of Magic Knight Tours,'' by T. H. Willcocks,
  560. J. Rec. Math. 1:225-233 (1968).
  561.  
  562. "Games Ancient and Oriental and How to Play Them"
  563. by Edward Falkener published by Dover in 1961 (first published 1892)
  564.  
  565. "Mathematical Magic Show", Martin Gardner, ch. 14
  566.  
  567. ==> competition/games/chess/mutual.stalemate.p <==
  568. What's the minimal number of pieces in a legal mutual stalemate?
  569.  
  570. ==> competition/games/chess/mutual.stalemate.s <==
  571. 6.  Here are three mutual stalemate positions.  Black is lower case
  572. in the diagrams.
  573.  
  574. W Kh8 e6 f7 h7  B Kf8 e7
  575.  
  576.     --+--+--+--+--+
  577.       |  | k|  | K|
  578.     --+--+--+--+--+
  579.       | p| P|  | P|
  580.     --+--+--+--+--+
  581.       | P|  |  |  |
  582.     --+--+--+--+--+
  583.       |  |  |  |  |
  584.  
  585. W Kb1  B Ka3 b2 b3 b4 a4
  586.  
  587.     |  |  |  
  588.     +--+--+--
  589.     | p| p|  
  590.     +--+--+--
  591.     | k| p|  
  592.     +--+--+--
  593.     |  | p|  
  594.     +--+--+--
  595.     |  | K|
  596.     +--+--+--
  597.   
  598. W Kf1  B Kh1 Bg1 f2 f3 h2
  599.  
  600.       |  |  |  |
  601.     --+--+--+--+
  602.       | p|  |  |
  603.     --+--+--+--+
  604.       | p|  | p|
  605.     --+--+--+--+
  606.       | K| b| k|
  607.     --+--+--+--+
  608.   
  609.  
  610. ==> competition/games/chess/queen.control.p <==
  611. How many queens does it take to attack or control the board?
  612.  
  613.  
  614. ==> competition/games/chess/queen.control.s <==
  615. Five queens are required to attack every square:
  616.  
  617.     1   2   3   4   5   6   7   8
  618.    ___ ___ ___ ___ ___ ___ ___ ___
  619. h |   |   |   |   |   |   |   |   |  
  620.    --- --- --- --- --- --- --- ---
  621. g |   |   |   | Q |   |   |   |   |
  622.    --- --- --- --- --- --- --- ---
  623. f |   |   |   | Q |   |   |   |   |
  624.    --- --- --- --- --- --- --- ---
  625. e |   |   |   | Q |   |   |   |   |
  626.    --- --- --- --- --- --- --- ---
  627. d |   |   |   | Q |   |   |   |   |
  628.    --- --- --- --- --- --- --- ---
  629. c |   |   |   |   |   |   |   |   |
  630.    --- --- --- --- --- --- --- ---
  631. b |   |   |   |   |   |   |   |   |
  632.    --- --- --- --- --- --- --- ---
  633. a |   |   |   | Q |   |   |   |   |
  634.    --- --- --- --- --- --- --- ---
  635.  
  636. There are other positions with five queens.
  637.  
  638. ==> competition/games/chess/queen.most.p <==
  639. How many non-mutually-attacking queens can be placed on various sized boards?
  640.  
  641. ==> competition/games/chess/queen.most.s <==
  642. On an regular chess board, at most eight queens of one color can be
  643. placed so that there are no mutual attacks.
  644.  
  645. Here is one configuration:
  646. -----------------
  647. |Q| | | | | | | |
  648. -----------------
  649. | | |Q| | | | | |
  650. -----------------
  651. | | | | |Q| | | |
  652. -----------------
  653. | | | | | | |Q| |
  654. -----------------
  655. | |Q| | | | | | |
  656. -----------------
  657. | | | | | | | |Q|
  658. -----------------
  659. | | | | | |Q| | |
  660. -----------------
  661. | | | |Q| | | | |
  662. -----------------
  663.  
  664. On an nxn board, if n is not divisible by 2 or 3, n^2 queens can be placed
  665. such that no two queens of the same color attack each other.
  666.  
  667. The proof is via a straightforward construction.  For n=1, the result
  668. is obviously true, so assume n>1 and n is not divisible by 2 or 3 (thus n>=5).
  669. Assume we are given n queens in each of these n "colors" (numbers):
  670.     0 1 2 ... n-1
  671.  
  672. The proof is by construction.  The construction is easier to see then to
  673. describe, we do both.  Here is what it looks like:
  674.  
  675.     0    1    2    3    4    ...    n-2    n-1
  676.     n-2    n-1    0    1    2    ...    n-4    n-3
  677.     n-4    n-3    n-2    n-1    0    ...    n-6    n-5
  678.     ...(move one row down => sub 2 (mod n); one col right => add 1 (mod n))
  679.     2    3    4    5    6    ...    0    1
  680.  
  681. People who know how a knight moves in chess will note the repetitive knight
  682. move theme connecting queens of the same color (especially after joining
  683. opposite edges of the board).
  684.  
  685. Now to describe this: place in each cell a queen whose "color" (number) is:
  686.     j - 2*i + 1 (mod n),
  687.     where i is the # of the row, and j is the # of the column.
  688.  
  689. Then no 2 queens of the same color are in the same:
  690.     row, column, or diagonal.
  691.  
  692. Actually, we will prove something stronger, namely that no 2 queens of the
  693. same color are on the same row, column, or "hyperdiagonal".  (The concept, if
  694. not the term, hyperdiagonal, goes back to 19th century.)  There are n
  695. hyperdiagonals of negative slope (one of them being a main diagonal) and n
  696. hyperdiagonals of positive slope (one of them being the other main diagonal).
  697. Definition:  for k in 0..n-1:
  698.     the k-th negative hyperdiagonal consists of cells (i,j),
  699.         where i-j=k (mod n)
  700.     the k-th positive hyperdiagonal consists of cells (i,j),
  701.         where i+j=k (mod n)
  702.     Then 0-th negative hyperdiagonal is simply the NW-SE main diagonal.
  703.     Then "1-th" positive hyperdiagonal is simply the SW-NE main diagonal.
  704.  
  705.     The other 2*(n-1) hyperdiagonals appear as 2 disconnected diagonal
  706.         fragments of cells, but if you join opposite edges of an nxn
  707.         board to each other, forming a sphere, these 2 fragments
  708.         become linearly connected forming a great circle.
  709.  
  710. Now to the proof:
  711.   1) First note that the above color assignment does indeed uniquely define the
  712.     color of a queen in each of the n^2 cells.
  713.  
  714.   2) no row contains 2 queens of the same color:
  715.     cells (i, a) and (i, b) contain queens of the same color =>
  716.         a-2i-1 = b-2i-1 (mod n) =>
  717.         a      = b (mod n) =>
  718.         a = b (since a,b are within 1..n)
  719.  
  720.   3) no column contains 2 queens of the same color:
  721.     cells (a, j) and (b, j) contain queens of the same color =>
  722.         j-2a-1 = j-2b-1 (mod n) =>
  723.         2a     = 2b (mod n) =>
  724.         a      = b  (mod n)  (since n and 2 have no common factor) =>
  725.         a = b (since a,b are within 1..n)
  726.  
  727.   4) no negative hyperdiagonal contains 2 queens of the same color:
  728.     cells (a, j) and (b, k) on the same negative hyperdiagonal contain
  729.         queens of the same color =>
  730.         a-j    = b-k   (mod n) AND j-2a-1 = k-2b-1 (mod n) =>
  731.         2a-2j  = 2b-2k (mod n) AND j-2a = k-2b (mod n) =>
  732.         (adding corresponding sides:)
  733.         -j     = -k (mod n) =>
  734.         j = k.
  735.         And thus a = b, as well (see first equality, 5th line up)
  736.         
  737.   5) no positive hyperdiagonal contains 2 queens of the same color:
  738.     cells (a, j) and (b, k) on the same positive hyperdiagonal contain
  739.         queens of the same color =>
  740.         a+j    = b+k   (mod n) AND j-2a-1 = k-2b-1 (mod n) =>
  741.         2a+2j  = 2b+2k (mod n) AND j-2a = k-2b (mod n) =>
  742.         (adding corresponding sides:)
  743.         3j     = 3k (mod n) =>
  744.         j      = k (mod n)  (since n and 3 have no common factor) =>
  745.         j = k.  Likewise a = b.
  746.         
  747. As special cases with the 0th negative hyperdiagonal and 1st positive
  748. hyperdiagonal, no 2 queens on the same main diagonal are colored the same.
  749.  
  750. Now is this condition, than n be not divisible by 2 and 3 also *necessary*?
  751.  
  752. Mike Konrad
  753. mdk@sei.cmu.edu
  754.  
  755. ******
  756.  
  757.  . . . o .  This is a solution for the 5-queen problem
  758.  o . . . .  at the torus. It has the 90 degree rotation symmetry.
  759.  . . o . .
  760.  . . . . o
  761.  . o . . .
  762.  
  763.  According to T. Klove, The modular n-queen problem II,
  764.               Discrete Math. 36 (1981) 33
  765.  it is unknown how to construct symmetric (90 rot) solutions for 
  766.  n = 1 or 5 (mod 12) and n has prime factors = 3 (mod 4).
  767.  He solved the smallest cases 49 and 77.
  768.  Try the next cases 121 and 133 or find a general solution.
  769.  
  770. A further reference for modular or reflected queen problems is:
  771. Martin Gardner, Fractal Music, Hypercards and More ..., Freeman (1991)
  772.  
  773. ********
  774.  
  775. For the 3-D N-queens problem the answer is four, at (1,1,2), (1,3,3),
  776. (2,3,1), and (3,2,3).
  777.  
  778. You can't have more because with four, you must have at least two in
  779. at least one of the three horizontal slices of the cube.  For the
  780. two-or-more-queen slice you must solve the n-queens problem for a 3x3
  781. planar board, which allows you to place at most 2 queens, and one must
  782. be in a corner.  The two queens cover all but one spot in the adjacent
  783. slice, so if the two-queen slice is the middle one we're already 
  784. limited to no more than 4 queens.  But if we put the 2-queen slice at
  785. the bottom or top, then the corner queen has line of sight to all 
  786. corners of the opposite slice, so it can contain at most one queen,
  787. and so can the middle slice.
  788.  
  789. If they sit in a 4x4x4 cube, the maximum is 7.  Here is a sample.
  790.  
  791. 1. 4 4 3
  792. 2. 2 3 4
  793. 3. 1 2 2
  794. 4. 2 4 2
  795. 5. 3 2 1
  796. 6. 1 1 4
  797. 7. 3 1 3
  798.  
  799. If they sit in a 5x5x5 cube, the maximum is 13.  Here is a sample.
  800.  
  801. 1. 4 5 4
  802. 2. 3 5 1
  803. 3. 5 4 2
  804. 4. 3 1 2
  805. 5. 2 1 4
  806. 6. 2 5 5
  807. 7. 4 1 5
  808. 8. 1 5 2
  809. 9. 5 2 1
  810. 10. 2 3 1
  811. 11. 1 3 5
  812. 12. 1 1 1
  813. 13. 5 1 3
  814.  
  815. ==> competition/games/chess/queens.p <==
  816. How many ways can eight queens be placed so that they control the board?
  817.  
  818. ==> competition/games/chess/queens.s <==
  819. 92.  The following program uses a backtracking algorithm to count positions:
  820.  
  821. #include <stdio.h>
  822.  
  823. static int count = 0;
  824.  
  825. void try(int row, int left, int right) {
  826.    int poss, place;
  827.    if (row == 0xFF) ++count;
  828.    else {
  829.       poss = ~(row|left|right) & 0xFF;
  830.       while (poss != 0) {
  831.          place = poss & -poss;
  832.          try(row|place, (left|place)<<1, (right|place)>>1);
  833.          poss &= ~place;
  834.          }
  835.       }
  836.    }
  837.  
  838. void main() {   
  839.    try(0,0,0);
  840.    printf("There are %d solutions.\n", count);
  841.    }
  842. --
  843. Tony Lezard IS tony@mantis.co.uk OR tony%mantis.co.uk@uknet.ac.uk
  844. OR EVEN arl10@phx.cam.ac.uk if all else fails.
  845.  
  846. ==> competition/games/chess/rook.paths.p <==
  847. How many non-overlapping paths can a rook take from one corner to the opposite
  848. on an MxN chess board?
  849.  
  850. ==> competition/games/chess/rook.paths.s <==
  851. For a 1 x 1 chessboard, there are 1 unique paths.
  852. For a 1 x 2 chessboard, there are 1 unique paths.
  853. For a 1 x 3 chessboard, there are 1 unique paths.
  854. For a 1 x 4 chessboard, there are 1 unique paths.
  855. For a 1 x 5 chessboard, there are 1 unique paths.
  856. For a 1 x 6 chessboard, there are 1 unique paths.
  857. For a 1 x 7 chessboard, there are 1 unique paths.
  858. For a 1 x 8 chessboard, there are 1 unique paths.
  859. For a 2 x 2 chessboard, there are 2 unique paths.
  860. For a 2 x 3 chessboard, there are 4 unique paths.
  861. For a 2 x 4 chessboard, there are 8 unique paths.
  862. For a 2 x 5 chessboard, there are 16 unique paths.
  863. For a 2 x 6 chessboard, there are 32 unique paths.
  864. For a 2 x 7 chessboard, there are 64 unique paths.
  865. For a 2 x 8 chessboard, there are 128 unique paths.
  866. For a 3 x 3 chessboard, there are 12 unique paths.
  867. For a 3 x 4 chessboard, there are 38 unique paths.
  868. For a 3 x 5 chessboard, there are 125 unique paths.
  869. For a 3 x 6 chessboard, there are 414 unique paths.
  870. For a 3 x 7 chessboard, there are 1369 unique paths.
  871. For a 3 x 8 chessboard, there are 4522 unique paths.
  872. For a 4 x 4 chessboard, there are 184 unique paths.
  873. For a 4 x 5 chessboard, there are 976 unique paths.
  874. For a 4 x 6 chessboard, there are 5382 unique paths.
  875. For a 4 x 7 chessboard, there are 29739 unique paths.
  876. For a 4 x 8 chessboard, there are 163496 unique paths.
  877. For a 5 x 5 chessboard, there are 8512 unique paths.
  878. For a 5 x 6 chessboard, there are 79384 unique paths.
  879. For a 5 x 7 chessboard, there are 752061 unique paths.
  880.  
  881. /***********************
  882.  * RookPaths.c
  883.  * By: David Blume
  884.  * dcb@wdl1.wdl.loral.com (Predecrement David)
  885.  *
  886.  * How many unique ways can a rook move from the bottom left corner
  887.  * of a m * n chess board to the top right right?
  888.  *
  889.  * Contraints: The rook may not passover a square it has already visited.
  890.  *             What if we don't allow Down & Left moves? (much easier)
  891.  *
  892.  * This software is provided *as is.*  It is not guaranteed to work on
  893.  * any platform at any time anywhere. :-)  Enjoy.
  894.  ***********************/
  895.  
  896. #include <stdio.h>
  897.  
  898. #define kColumns 8            /* The maximum number of columns */
  899. #define kRows     8            /* The maximum number of rows */
  900.  
  901. /* The following rule is for you to play with. */
  902. #define kAllowDownLeft        /* Whether or not to allow the rook to move D or L */
  903.  
  904. /* Visual feedback defines... */
  905. #undef kShowTraversals        /* Whether or nor to show each successful graph */
  906. #define kListResults        /* Whether or not to list each n * m result */
  907. #define kShowMatrix            /* Display the final results in a matrix? */
  908.  
  909. char gmatrix[kColumns][kRows];                /* the working matrix */
  910. long result[kColumns][kRows];                /* the result array */
  911.  
  912. /*********************
  913.  * traverse
  914.  *
  915.  * This is the recursive function
  916.  *********************/
  917. traverse (short c, short r, short i, short j )
  918. {
  919.     
  920.     /* made it to the top left! increase result, retract move, and return */
  921.     if (i == c && j == r) {
  922.  
  923. #ifdef kShowTraversals    
  924.         short ti, tj;
  925.         gmatrix[i][j] = 5;
  926.         for (ti = c; ti >= 0; ti--) {
  927.             for (tj = 0; tj <= r; tj++) {
  928.                 if (gmatrix[ti][tj] == 0)
  929.                     printf(". ");
  930.                 else if (gmatrix[ti][tj] == 1)
  931.                     printf("D ");
  932.                 else if (gmatrix[ti][tj] == 2)
  933.                     printf("R ");
  934.                 else if (gmatrix[ti][tj] == 3)
  935.                     printf("L ");
  936.                 else if (gmatrix[ti][tj] == 4)
  937.                     printf("U ");
  938.                 else if (gmatrix[ti][tj] == 5)
  939.                     printf("* ");
  940.                 }
  941.             printf("\n");
  942.             }
  943.         printf("\n");
  944. #endif
  945.  
  946.         result[i][j] = result[i][j] + 1;
  947.         gmatrix[i][j] = 0;
  948.         return;
  949.         }
  950.     
  951.     /* try to move, left up down right */
  952. #ifdef kAllowDownLeft
  953.     if (i != 0 && gmatrix[i-1][j] == 0) {        /* left turn */
  954.         gmatrix[i][j] = 1;
  955.         traverse(c, r, i-1, j);
  956.         }
  957. #endif
  958.     if (j != r && gmatrix[i][j+1] == 0) {        /* turn up */
  959.         gmatrix[i][j] = 2;
  960.         traverse(c, r, i, j+1);
  961.         }
  962. #ifdef kAllowDownLeft
  963.     if (j != 0 && gmatrix[i][j-1] == 0) {        /* turn down */
  964.         gmatrix[i][j] = 3;
  965.         traverse(c, r, i, j-1);
  966.         }
  967. #endif
  968.     if (i != c && gmatrix[i+1][j] == 0) {        /* turn right */
  969.         gmatrix[i][j] = 4;
  970.         traverse(c, r, i+1, j);
  971.         }
  972.     
  973.     /* remove the marking on this square */
  974.     gmatrix[i][j] = 0;
  975.  
  976. }
  977.  
  978. main()
  979. {
  980.     short i, j;
  981.     
  982.     /* initialize the matrix to 0 */
  983.     for (i = 0; i < kColumns; i++) {
  984.         for (j = 0; j < kRows; j++) {
  985.             gmatrix[i][j] = 0;
  986.             }
  987.         }
  988.     
  989.     /* call the recursive function */
  990.     for (i = 0; i < kColumns; i++) {
  991.         for (j = 0; j < kRows; j++) {
  992.             if (j >= i) {
  993.                 result[i][j] = 0;
  994.                 traverse (i, j, 0, 0);
  995. #ifdef kListResults
  996.                 printf("For a %d x %d chessboard, there are %d unique paths.\n",
  997.                         i+1, j+1, result[i][j]); fflush(stdout);
  998. #endif
  999.                 }
  1000.             }
  1001.         }
  1002.     /* print out the results */
  1003. #ifdef kShowMatrix
  1004.     printf("\n");
  1005.     for (i = 0; i < kColumns; i++) {
  1006.         for (j = 0; j < kRows; j++) {
  1007.             short min = (i < j) ? i : j ;
  1008.             short max = (i < j) ? j : i ;
  1009.             printf("%6d", result[min][max]);
  1010.             }
  1011.         printf("\n");
  1012.         }
  1013. #endif
  1014. }
  1015.  
  1016. ==> competition/games/chess/size.of.game.tree.p <==
  1017. How many different positions are there in the game tree of chess?
  1018.  
  1019. ==> competition/games/chess/size.of.game.tree.s <==
  1020. Consider the following assignment of bit strings to square states:
  1021.  
  1022.     Square State        Bit String
  1023.     ------ -----        --- ------
  1024.  
  1025.     Empty            0
  1026.     White Pawn        100
  1027.     Black Pawn        101
  1028.     White Rook        11111
  1029.     Black Rook        11110
  1030.     White Knight        11101
  1031.     Black Knight        11100
  1032.     White Bishop        11011
  1033.     Black Bishop        11010
  1034.     White Queen        110011
  1035.     Black Queen        110010
  1036.     White King        110001
  1037.     Black King        110000
  1038.  
  1039. Record a position by listing the bit string for each of the 64 squares.
  1040. For a position with all the pieces still on the board, this will take
  1041. 164 bits.  As pieces are captured, the number of bits needed goes down.
  1042. As pawns promote, the number of bits go up.  For positions where a King
  1043. and Rook are in position to castle if castling is legal, we will need
  1044. a bit to indicate if in fact castling is legal.  Same for positions
  1045. where an en-passant capture may be possible.  I'm going to ignore these
  1046. on the grounds that a more clever encoding of a position than the one
  1047. that I am proposing could probably save as many bits as I need for these
  1048. considerations, and thus conjecture that 164 bits is enough to encode a
  1049. chess position.
  1050.  
  1051. This gives an upper bound of 2^164 positions, or 2.3x10^49 positions.
  1052.  
  1053. Jurg Nievergelt, of ETH Zurich, quoted the number 2^70 (or about 10^21) in
  1054. e-mail, and referred to his paper "Information content of chess positions",
  1055. ACM SIGART Newsletter 62, 13-14, April 1977, to be reprinted in "Machine
  1056. Intelligence" (ed Michie), to appear 1990.
  1057.  
  1058. Note that this latest estimate, 10^21, is not too intractable:
  1059. 10^7 computers running at 10^7 positions per second could scan those
  1060. in 10^7 seconds, which is less than 6 months.
  1061.  
  1062. In fact, suppose there is a winning strategy in chess for white.
  1063. Suppose further that the strategy starts from a strong book opening,
  1064. proceeds through middle game with only moves that Deep Thought (DT)
  1065. would pick using the singular extension technique, and finally ends in
  1066. an endgame that DT can analyze completely.  The book opening might take
  1067. you ten moves into the game and DT has demonstrated its ability to
  1068. analyze mates-in-20, so how many nodes would DT really have to visit?
  1069. I suggest that by using external storage such a optical WORM memory,
  1070. you could easily build up a transposition table for such a midgame.  If
  1071. DT did not find a mate, you could progressively expand the width of the
  1072. search window and add to the table until it did.  Of course there would
  1073. be no guarantee of success, but the table built would be useful
  1074. regardless.  Also, you could change the book opening and add to the
  1075. table.  This project could continue indefinitely until finally it must
  1076. solve the game (possibly using denser and denser storage media as
  1077. technology advances).
  1078.  
  1079. What do you think?
  1080.  
  1081. -------
  1082.  
  1083. I think you are a little bit too optimistic about the feasibility.  Solving
  1084. mate-in-19 when the moves are forcing is one thing, but solving mate-in-19
  1085. when the moves are not forcing is another.  Of course, human beings are no
  1086. better at the latter task.  But to solve the game in the way you described
  1087. would seem to require the ability to handle the latter task.  Anyway, we
  1088. cannot really think about doing the sort of thing you described; DT is just a
  1089. poor man's chess machine project (relatively speaking).
  1090.                         --Hsu
  1091.  
  1092. i dont think that you understand the numbers involved.
  1093. the size of the tree is still VERY large compared to all
  1094. the advances that you cite. (speed of DT, size of worms,
  1095. endgame projects, etc) even starting a project will probably
  1096. be a waste of time since the next advance will overtake it
  1097. rather than augment it. (if you start on a journey to the
  1098. stars today, you will be met there by humans)
  1099. ken
  1100.  
  1101. ==> competition/games/cigarettes.p <==
  1102. The game of cigarettes is played as follows:
  1103. Two players take turns placing a cigarette on a circular table.  The cigarettes
  1104. can be placed upright (on end) or lying flat, but not so that it touches any
  1105. other cigarette on the table.  This continues until one person loses by not
  1106. having a valid position on the table to place a cigarette.
  1107.  
  1108. Is there a way for either of the players to guarantee a win?
  1109.  
  1110. ==> competition/games/cigarettes.s <==
  1111. The first person wins by placing a cigarette at the center of the table,
  1112. and then placing each of his cigarettes in a position symmetric (with
  1113. respect to the center) to the place the second player just moved.  If the
  1114. second player could move, then symmetrically, so can the first player.
  1115.  
  1116. ==> competition/games/connect.four.p <==
  1117. Is there a winning strategy for Connect Four?
  1118.  
  1119. ==> competition/games/connect.four.s <==
  1120. An AI program has solved Connect Four for the standard 7 x 6 board.
  1121. The conclusion: White wins, was confirmed by the brute force check made by
  1122. James D. Allen, which has been published in rec.games.programmer.
  1123.  
  1124. The program called VICTOR consists of a pure knowledge-based evaluation
  1125. function which can give three values to a position: 
  1126.  1 won by white,
  1127.  0 still unclear.
  1128. -1 at least a draw for Black,
  1129.  
  1130. This evaluation function is based on 9 strategic rules concerning the game,
  1131. which all nine have been (mathematically) proven to be correct.
  1132. This means that a claim made about the game-theoretical value of a position
  1133. by VICTOR, is correct, although no search tree is built.
  1134. If the result 1 or -1 is given, the program outputs a set of rules applied,
  1135. indicating the way the result can be achieved.
  1136. This way one evaluation can be used to play the game to the end without any
  1137. extra calculation (unless the position was still unclear, of course).
  1138.  
  1139. Using the evaluation function alone, it has been shown that Black can at least
  1140. draw the game on any 6 x (2n) board. VICTOR found an easy strategy for
  1141. these boardsizes, which can be taught to anyone within 5 minutes. Nevertheless,
  1142. this strategy had not been encountered before by any humans, as far as I know.
  1143.  
  1144. For 7 x (2n) boards a similar strategy was found, in case White does not
  1145. start the game in the middle column. In these cases Black can therefore at
  1146. least draw the game.
  1147.  
  1148. Furthermore, VICTOR needed only to check a few dozen positions to show
  1149. that Black can at least draw the game on the 7 x 4 board.
  1150.  
  1151. Evaluation of a position on a 7 x 4 or 7 x 6 board costs between 0.01 and 10
  1152. CPU seconds on a Sun4.
  1153.  
  1154. For the 7 x 6 board too many positions were unclear. For that reason a
  1155. combination of Conspiracy-Number Search and Depth First Search was used
  1156. to determine the game-theoretical value. This took several hundreds of hours
  1157. on a Sun4.
  1158.  
  1159. The main reason for the large amount of search needed, was the fact that in 
  1160. many variations, the win for White was very difficult to achieve. 
  1161. This caused many positions to be unclear for the evaluation function.
  1162.  
  1163. Using the results of the search, a database will be constructed
  1164. of roughly 500.000 positions with their game-theoretical value. 
  1165. Using this datebase, VICTOR can play against humans or other programs, 
  1166. winning all the time (playing White).  The average move takes less 
  1167. than a second of calculation (search in the database or evaluation 
  1168. of the position by the evaluation function).
  1169.  
  1170. Some variations are given below (columns and rows are numbered as is customary
  1171. in chess):
  1172.  
  1173. 1. d1, ..  The only winning move.
  1174.  
  1175. After 1. .., a1 wins 2. e1. Other second moves for White has not been
  1176. checked yet.
  1177. After 1. .., b1 wins 2. f1. Other second moves for White has not been
  1178. checked yet.
  1179. After 1. .., c1 wins 2. f1. Only 2 g1 has not been checked yet. All other
  1180. second moves for White give Black at least a draw.
  1181. After 1. .., d2 wins 2. d3. All other second moves for White give black
  1182. at least a draw.
  1183.  
  1184. A nice example of the difficulty White has to win:
  1185.  
  1186. 1. d1, d2 
  1187. 2. d3, d4
  1188. 3. d5, b1
  1189. 4. b2!
  1190.  
  1191. The first three moves for White are forced, while alternatives at the
  1192. fourth moves of White are not checked yet.
  1193.  
  1194. A variation which took much time to check and eventually turned out
  1195. to be at least a draw for Black, was:
  1196.  
  1197. 1. d1, c1
  1198. 2. c2?, .. f1 wins, while c2 does not.
  1199. 2. .., c3 Only move which gives Black the draw.
  1200. 3. c4, .. White's best chance.
  1201. 3. .., g1!! Only 3 .., d2 has not been checked completely, while all
  1202.         other third moves for Black have been shown to lose.
  1203.  
  1204. The project has been described in my 'doctoraalscriptie' (Master thesis)
  1205. which has been supervised by Prof.Dr H.J. van den Herik of the
  1206. Rijksuniversiteit Limburg (The Netherlands).
  1207.  
  1208. I will give more details if requested.
  1209.  
  1210. Victor Allis.
  1211. Vrije Universiteit van Amsterdam.
  1212. The Netherlands.
  1213. victor@cs.vu.nl
  1214.  
  1215. ==> competition/games/craps.p <==
  1216. What are the odds in craps?
  1217.  
  1218. ==> competition/games/craps.s <==
  1219. The game of craps:
  1220. There is a person who rolls the two dice, and then there is the house.
  1221. 1) On the first roll, if a 7 or 11 comes up, the roller wins.
  1222.    If a 2, 3, or 12 comes up the house wins.
  1223.    Anything else is a POINT, and more rolling is necessary, as per rule 2.
  1224. 2) If a POINT appears on the first roll, keep rolling the dice.
  1225.    At each roll, if the POINT appears again, the roller wins.
  1226.    At each roll, if a 7 comes up, the house wins.
  1227.    Keep rolling until the POINT or a 7 comes up.
  1228.  
  1229. Then there are the players, and they are allowed to place their bets with
  1230. either the roller or with the house.
  1231.  
  1232. -----
  1233. My computations:
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239. On the first roll, P.roller.trial(1) = 2/9, and P.house.trial(1) = 1/9.
  1240. Let  P(x) stand for the probability of a 4,5,6,8,9,10 appearing.
  1241. Then on the second and onwards rolls, the probability is:
  1242.  
  1243. Roller:
  1244.                          ---                        (i - 2)
  1245. P.roller.trial(i) =      \   P(x)   *   ((5/6 - P(x))         *   P(x)
  1246. (i > 1)                  /
  1247.                  ---
  1248.                  x = 4,5,6,8,9,10
  1249.  
  1250. House:
  1251.                         ---                        (i - 2)
  1252. P.house.trial(i) =      \   P(x)   *   ((5/6 - P(x))         *   1/6
  1253. (i > 1)                 /
  1254.                 ---
  1255.                 x = 4,5,6,8,9,10
  1256.  
  1257. Reasoning (roller): For the roller to win on the ith trial, a POINT
  1258. should have appeared on the first trial (the first P(x) term), and the
  1259. same POINT should appear on the ith trial (the last P(x) term). All the in
  1260. between trials should come up with a number other than 7 or the POINT
  1261. (hence the (5/6 - P(x)) term).
  1262. Similar reasoning holds for the house.
  1263.  
  1264. The numbers are:
  1265. P.roller.trial(i) (i > 1) =
  1266.  
  1267.                 (i-1)                 (i-1)                     (i-1)  
  1268.  1/72 * (27/36)      + 2/81 * (26/36)        + 25/648 * (25/36)
  1269.  
  1270.  
  1271. P.house.trial(i) (i > 1) =
  1272.  
  1273.                 (i-1)                 (i-1)                     (i-1)  
  1274.  2/72 * (27/36)      + 3/81 * (26/36)        + 30/648 * (25/36)
  1275.  
  1276.  
  1277. -------------------------------------------------
  1278. The total probability comes to:
  1279. P.roller = 2/9   +   (1/18 + 4/45 + 25/198)  = 0.4929292929292929..
  1280. P.house  = 1/9   +   (1/9  + 2/15 + 15/99)  =  0.5070707070707070..
  1281.  
  1282. which is not even.
  1283. ===========================================================================
  1284.  
  1285. ==
  1286. Avinash Chopde                 (with standard disclaimer)
  1287. abc@unhcs.unh.edu, abc@unh.unh.edu            {.....}!uunet!unh!abc
  1288.  
  1289. ==> competition/games/crosswords.p <==
  1290. Are there programs to make crosswords?  What are the rules for cluing cryptic
  1291. crosswords?  Is there an on-line competition for cryptic cluers?
  1292.  
  1293. ==> competition/games/crosswords.s <==
  1294. You need to read the rec.puzzles.crosswords FAQL.
  1295.  
  1296.