#!/usr/bin/wish -f # This code is a Tcl/Tk version of Edmund Ronald's 1991 Objective-C # puzzle for NeXTStep. Edmund Ronald was: eronald@cnam.cnam.fr # $Id: Quinto,v 1.2 1999/01/07 03:22:20 bediger Exp bediger $ wm geometry . 300x300 set color(1) "black" set color(0) "lightgrey" set tk_strictMotif 1 for {set i 0} {$i < 5} {incr i} { frame .f$i for {set j 0} {$j < 5} {incr j} { button .f$i.a$j -command "buttonclicked $i $j" \ -background $color([set state($i$j) 1]) pack .f$i.a$j -expand 1 -fill both -side left -in .f$i } pack .f$i -expand 1 -side top -fill both } wm title [toplevel .n] "Quinto Controls" frame .n.btns -background lightgrey pack [label .n.btns.l -background lightgrey -text "Quinto"] \ -side top -anchor center -in .n.btns pack [label .n.btns.m -background lightgrey -text "Object of game:"] \ -side top -anchor center -in .n.btns pack [label .n.btns.n -background lightgrey -text "highlight all buttons"] \ -side top -anchor center -in .n.btns pack [label .n.btns.o -background lightgrey -text "Quinto created by Edmund Ronald"] \ -side top -anchor center -in .n.btns pack [button .n.btns.q -background lightgrey -text "Quit" -command "exit"] \ -side right -anchor center -in .n.btns pack [button .n.btns.r -background lightgrey -text "Reset" -command "reset"] \ -side left -anchor center -in .n.btns pack [button .n.btns.s -background lightgrey -text "Readme" -command "readme"] \ -side bottom -anchor center -in .n.btns pack .n.btns -expand 1 -side top -fill x -in .n proc buttonclicked {i j} { global state color; .f$i.a$j configure -background $color([set state($i$j) [expr !$state($i$j)]]); if {$i > 0} { flip_state [expr $i - 1] $j; } if {$i < 4} { flip_state [expr $i + 1] $j; } if {$j > 0} { flip_state $i [expr $j - 1]; } if {$j < 4} { flip_state $i [expr $j + 1]; } } proc flip_state {i j} { global state color; .f$i.a$j configure -background $color([set state($i$j) [expr !$state($i$j)]]); } proc reset {} { global state color; for {set i 0} {$i < 5} {incr i} { for {set j 0} {$j < 5} {incr j} { .f$i.a$j configure -background $color([set state($i$j) 1]); } } } proc readme {} { if {[winfo exists .r]} {return} set Readme { Quinto Quinto is a game. The board is a 5*5 array of buttons, pressing one toggles its' state and that of its 4 neighbors. The aim of the game is to highlight all the buttons. My friend John Horton Conway, who knows some mathematics, took a few hours to solve this back in the early eighties. Other people tend to take slightly longer. The source code is placed in the public domain, however I request that the icon not be used for anything else as it is my own iconic signature. My adress is Edmund Ronald, 24 Rue des Rosiers, 75004 Paris France. email: eronald@cnam.cnam.fr If you like this program, send me a disquette with your favorite game (NeXT, Mac or PC!) Enjoy. Edmund. } wm title [toplevel .r -background lightgrey] "Quinto Readme" text .r.t -background lightgrey .r.t insert 1.0 $Readme pack [label .r.m -background lightgrey -text {This is a Tcl/Tk version of Edmund Ronald's 1991 Objective-C} ] -side top -anchor center -in .r pack [label .r.n -background lightgrey -text {puzzle for NeXTStep. Edmund Ronald was: eronald@cnam.cnam.fr} ] -side top -anchor center -in .r pack [label .r.o -background lightgrey -text {Tcl/Tk version by Bruce Ediger - bediger@csn.net, 1998} ] -side top -anchor center -in .r pack [label .r.p -background lightgrey -text "Edmund Ronald's original Readme"] -side top -anchor center -in .r pack .r.t -padx 10 -pady 10 -side top -anchor center -expand 1 -fill both -in .r pack [button .r.b -background lightgrey -text "OK" -command "destroy .r"] -side top -anchor center -in .r } # The following is one solution to the puzzle. Button 0,0 is the upper left # button, 4,4 is the lower right button. I found a solution in a smaller # number of moves, but I can't reproduce it. # 0,0 # 1,2 # 4,0 # 4,2 # 0,4 # 2,1 # 3,0 # 3,1 # 4,1 # 3,4 # 4,3 # 4,2 # 3,4 # 3,3 # 3,4 # 4,1 # 4,2 # 4,1 # 4,2 # 2,3 # 4,0 # 2,2 # 4,3 # 2,4 # 1,4 # 1,1 # 0,1 # 0,0 # 0,2 # 1,3 # 0,3 # 1,4 # 0,3 # 4,0 # 2,1