📜 ⬆️ ⬇️

Fifteen TCL in 10 lines

Reversi in 64 lines is already there . Now write the tag.
image



Source Code (upuzzle.tcl)
 package require Tk
 foreach {p} {7 2 10 11 5 4 9 12 13 8 3 14 15 1 6} {i} {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} {
	 button. $ p -relief solid -bd 1 -width 8 -height 4 -text $ p -command "move $ p"
	 grid. $ p -row [expr {$ i / 4}] -column [expr {$ i% 4}] -padx 1 -pady 1}
 proc move {b} {
	 lassign [list [dict get [grid info. $ b] -column] [dict get [grid info. $ b] -row]] xy
	 foreach {ix iy} {0 -1 0 1 -1 0 1 0} {
		 lassign [list [expr {$ x + $ ix}] [expr {$ y + $ iy}]] ij
		 if {$ i> = 0 && $ i <= 3 && $ j> = 0 && $ j <= 3 &&! [llength [grid slaves.  -col $ i -row $ j]]} {
			 grid configure. $ b -column $ i -row $ j}}}

')
As knuckles used conventional buttons. They are packed in a window using the grid manager, where the position of the widget is specified by the row and column number of the virtual table.

The move procedure for a given knuckle checks all possible movements (up, down, left, right) and, if necessary, changes the position of the button in the table.

image

References:
Fifteen on Wikipedia
ActiveTcl (Tcl distribution for Windows / OSX / Linux)
eTcl (Windows Mobile)



Alternatives from habrauys:
Game "tag" from michurin
Fifteen on Midp1.0-2.0 from SKYnv

Source: https://habr.com/ru/post/89919/


All Articles