home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / expect / scripts / bonfield.exp < prev    next >
Encoding:
Text File  |  1993-02-21  |  2.6 KB  |  59 lines

  1. #!/depot/path/expect -f
  2. # Script to solve Jim Bonfield's game that won the 1991 Obfuscated C contest.
  3. # Originally written by Don Libes, NIST, 1/3/91, later rewritten using
  4. # John Tromp's highly optimized set of moves
  5.  
  6. # If you want to play part of the game, just put in an "interact;exit"
  7. # anywhere and expect will do the first part, leaving the rest for you!
  8. # (That was how I solved the game in the first place - by pushing the
  9. # interact further and further back as I figured things out.)
  10.  
  11. proc do {moves} {send $moves; expect *}
  12.  
  13. trap exit SIGINT
  14. set timeout 1000;# need a long timeout because expect can get far enough
  15.          # ahead of the game that by the final expect, we have to
  16.          # wait quite a bit for the I/O to complete!
  17. spawn puzzle
  18.  
  19. # In the opening scene, we don't know exactly what to watch for (a lota #s?),
  20. # so just wait for a 1000 or so characters to go by!
  21. set count 0
  22. while {$count<1000} {
  23.     expect -re .+
  24.     incr count [llength [split $expect_out(buffer) ""]]
  25. }
  26.  
  27. # opening
  28. do kkklllllljjlll;    # to key room
  29. do kkllljjhjkhhhhh;    # make gems, push left-key-1 into door
  30. do lllllkkll;        # to key room & pick up gems in upper-right-hand corner
  31. do jjjhjjjjhkhkhhk;    # take remaining gems, push up-key free
  32. do jllk;        # push boulder up as long as we're here
  33. do jjllkkhkkkhhjjl;     # manipulate left-key-2 and boulder
  34. do hhhhhhh;        # push up-key into door-room
  35. do jhkkllllll;        # unlock door and go back to key room
  36. do jjllklkhhhhhhhh;    # get behind left-key-2 and push into door room
  37. do lllkkhhhhjj;        # leave left-key-2 next to door
  38. do lllllllkkhjljhhhhhh;    # go back to key-room, return with down-key
  39. do jhhhhkkklljjkkhhjjjllklj;    # unlock two remaining doors
  40.    # retrieve boulder from key room and smash into boulder at bottom
  41. do llllllkklljjkklljjjhhljjhhkklkhhhhhhhhlllkkhhhhjjkkhhjjjllkljjjjjjjj
  42. do hkkkkhhhllkk;    # go back up, making/picking up gems along the way
  43. do hhhhkhkkkhjjjjlllll;    # make/collect gems from upper-left-hand corner
  44. do kljjjjjjhjhllll;    # move remaining boulder down, pick up remaining gems
  45. do hkkllkkkkjjj;    # make/pick up gems from central chute
  46. do ljjhkkkk;        # move uncompressible into shute
  47. do ljjjhjlll;        # move boulder out of shute, make/pickup gems on bottom
  48. do klljllkhhhhhlll
  49. do lljlllhkhhhhhhjhkkk;    # move another unc into shute
  50. do jjlllllllljlkklkkkhjhjljjhhkljl;    # get beneath boulder, prepare to lift
  51. do kkkkkklkhkl;        # pick up lots of gems
  52. do kkhjjjjjljhkhjjlj;    # get behind key, prepare to move to door
  53. do hhhhhhhhjhklkhhhhhhhhhk;        # unlock door, enter & pick up a gem
  54. do hkhljjjjh;# pick up remaining gems
  55. do jllkhklllllllkljhjlllllllllll;    # move last boulders together
  56. # send final command by hand to wait for congrat message
  57. send l
  58. expect -re "Well done!"
  59.