The wonders of QTK again !  This is really great for showing off !!

Thank you very much Raph !

Fred.


Op 2-jun-07, om 12:02 heeft Raphael Collet het volgende geschreven:

declare
[QTk]={Module.link ['x-oz://system/wp/QTk.ozf']}

%% return a label description for the variable X
fun {MakeLabel X}
   H
   proc {Init}
      Sz={FD.reflect.size X}
   in
      {H set(text:{Value.toVirtualString X 10 10})}
      thread {Loop Sz} end
   end
   proc {Loop Sz}
      %% keeps updating the widget
      if {FD.watch.size X Sz} then
         Sz1={FD.reflect.size X}
      in
         {H set(text:{Value.toVirtualString X 10 10})}
         %% "flash" effect; comment out if you want
         {H set(bg:yellow)}
         {Delay 500}
         {H set(bg:white)}
         %% end of "flash"
         {Loop Sz1}
      end
   end
in
   label(handle:H onCreation:Init anchor:center
         width:12 height:3 bg:white glue:nswe)
end

%% display a window for the given sudoku grid (tuple or row tuples)
proc {ShowSudoku Grid}
   _|Ls = for Row in {Record.toList Grid}   collect:Collect do
             {Collect newline}
             for X in {Record.toList Row} do
                {Collect {MakeLabel X}}
             end
          end
   Desc={List.toTuple lr Ls}
   Window={QTk.build Desc}
in
   {Window show}
end

Grid={MakeTuple grid 9}
{Record.forAll Grid proc {$ Row} Row={FD.tuple row 9 1#9} end}

%% alldiff constraints
for I in 1..9 do
   {FD.distinctD Grid.I}
end
for J in 1..9 do
   {FD.distinctD {Record.map Grid fun {$ Row} Row.J end}}
end
for BI in 0..2 do
   for BJ in 0..2 do
      Block = for I in 1..3   collect:Collect do
                 for J in 1..3 do
                    {Collect Grid.(3*BI+I).(3*BJ+J)}
                 end
              end
   in
      {FD.distinctD Block}
   end
end

{ShowSudoku Grid}

%% feed assignments (or constraints) here
Grid.1.1=3
Grid.1.5=7

---------------------
Dr. Fred Spiessens
IT Research & Consultancy
Evoluware
http://www.evoluware.eu/


_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to