/usr/share/mozart/doc/demo/node1.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Root functor: AnimateQueens.oz</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="queens.html">- Up -</A></TD></TR></TABLE><DIV class="unnumbered" id="code.queens"><H3><A name="code.queens">Root functor: <CODE>AnimateQueens.oz</CODE></A></H3><P class="margin"><A href="AnimatedQueens.oz">Source File</A></P><P> </P><BLOCKQUOTE><PRE><SPAN class="keyword">functor</SPAN> <BR> <BR><SPAN class="keyword">require</SPAN> <BR> DemoUrls(image)<BR> <BR><SPAN class="keyword">import</SPAN> <BR> FD<BR> Space<BR> Tk<BR> TkTools<BR> Application <BR> <BR><SPAN class="keyword">prepare</SPAN> <BR> <BR> URL = {VirtualString<SPAN class="keyword">.</SPAN>toAtom DemoUrls<SPAN class="keyword">.</SPAN>image <SPAN class="keyword">#</SPAN> <SPAN class="string">'animated-queens/'</SPAN>}<BR> <BR> MaxWidth = 600 % <SPAN class="comment">How large can the drawing area be<BR></SPAN> <BR> FailWidth = 10<BR> <BR> DefaultSize = 6 % <SPAN class="comment">With which N-Queens problem should we start<BR></SPAN> <BR> ParamWinTitle = <SPAN class="string">'Animated Queens: Size'</SPAN> <BR> <BR> <BR> %% <SPAN class="comment">Derived Parameters<BR></SPAN> WidthByMag = s(micro:2 tiny:5 small:10 middle:25 large:50)<BR> <BR> MaxBoardSize = 255<BR> <BR><SPAN class="keyword">define</SPAN> <BR> <BR> LargeFont = {New Tk<SPAN class="keyword">.</SPAN>font tkInit(family:times weight:bold size:<SPAN class="keyword">~</SPAN>24)}<BR> <BR> BlackColor <SPAN class="keyword">#</SPAN> <BR> WhiteColor <SPAN class="keyword">#</SPAN> <BR> QueenColor <SPAN class="keyword">#</SPAN> <BR> CrossColor <SPAN class="keyword">#</SPAN> <BR> FailColor = <SPAN class="keyword">if</SPAN> Tk<SPAN class="keyword">.</SPAN>isColor <SPAN class="keyword">then</SPAN> <BR> gray85 <SPAN class="keyword">#</SPAN> gray95 <SPAN class="keyword">#</SPAN> darkorange1 <SPAN class="keyword">#</SPAN> gray75 <SPAN class="keyword">#</SPAN> firebrick<BR> <SPAN class="keyword">else</SPAN> black <SPAN class="keyword">#</SPAN> white <SPAN class="keyword">#</SPAN> black <SPAN class="keyword">#</SPAN> black <SPAN class="keyword">#</SPAN> black<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> QueenByMag = {List<SPAN class="keyword">.</SPAN>toRecord <SPAN class="string">''</SPAN> <BR> {Map [micro tiny small middle large]<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> S}<BR> S<SPAN class="keyword">#</SPAN>{New Tk<SPAN class="keyword">.</SPAN>image<BR> tkInit(type:bitmap foreground:QueenColor<BR> url: URL <SPAN class="keyword">#</SPAN> S<SPAN class="keyword">#</SPAN> <SPAN class="string">'-queen.xbm'</SPAN>)}<BR> <SPAN class="keyword">end</SPAN>}}<BR> <BR> CrossByMag = c(micro: <SPAN class="keyword">false</SPAN> <BR> tiny: <SPAN class="keyword">false</SPAN> <BR> small: <SPAN class="keyword">false</SPAN> <BR> middle: {New Tk<SPAN class="keyword">.</SPAN>image<BR> tkInit(type:bitmap foreground:CrossColor <BR> url: URL <SPAN class="keyword">#</SPAN> <SPAN class="string">'middle-cross.xbm'</SPAN>)}<BR> large: {New Tk<SPAN class="keyword">.</SPAN>image<BR> tkInit(type:bitmap foreground:CrossColor<BR> url: URL <SPAN class="keyword">#</SPAN> <SPAN class="string">'large-cross.xbm'</SPAN>)})<BR> <BR> NaiveStrat = 1<BR> FirstFailStrat = 2<BR> UpFirstStrat = 3<BR> MiddleOutStrat = 4<BR> <BR> DefaultStrat = MiddleOutStrat<BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">The problem solving part<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">local</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">OrderUp</SPAN> X Y}<BR> SizeX = {FD<SPAN class="keyword">.</SPAN>reflect<SPAN class="keyword">.</SPAN>size X}<BR> SizeY = {FD<SPAN class="keyword">.</SPAN>reflect<SPAN class="keyword">.</SPAN>size Y}<BR> <SPAN class="keyword">in</SPAN> <BR> SizeX <SPAN class="keyword"><</SPAN> SizeY <SPAN class="keyword">orelse</SPAN> <BR> SizeX<SPAN class="keyword">==</SPAN>SizeY <SPAN class="keyword">andthen</SPAN> <BR> {FD<SPAN class="keyword">.</SPAN>reflect<SPAN class="keyword">.</SPAN>min X} <SPAN class="keyword"><</SPAN> {FD<SPAN class="keyword">.</SPAN>reflect<SPAN class="keyword">.</SPAN>min Y}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">QueensScript</SPAN> Size Strategy}<BR> Distribute = <SPAN class="keyword">case</SPAN> Strategy<BR> <SPAN class="keyword">of</SPAN> <SPAN class="keyword">!</SPAN>NaiveStrat <SPAN class="keyword">then</SPAN> naive<BR> <SPAN class="keyword">[]</SPAN> <SPAN class="keyword">!</SPAN>FirstFailStrat <SPAN class="keyword">then</SPAN> ff<BR> <SPAN class="keyword">[]</SPAN> <SPAN class="keyword">!</SPAN>UpFirstStrat <SPAN class="keyword">then</SPAN> generic(order:OrderUp)<BR> <SPAN class="keyword">[]</SPAN> <SPAN class="keyword">!</SPAN>MiddleOutStrat <SPAN class="keyword">then</SPAN> generic(value:mid)<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> Xs}<BR> Xs = {FD<SPAN class="keyword">.</SPAN>list Size 1<SPAN class="keyword">#</SPAN>Size}<BR> {FD<SPAN class="keyword">.</SPAN>distinct Xs}<BR> {FD<SPAN class="keyword">.</SPAN>distinctOffset Xs {List<SPAN class="keyword">.</SPAN>number 1 Size 1}}<BR> {FD<SPAN class="keyword">.</SPAN>distinctOffset Xs {List<SPAN class="keyword">.</SPAN>number Size 1 <SPAN class="keyword">~</SPAN>1}}<BR> {FD<SPAN class="keyword">.</SPAN>distribute Distribute Xs}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Engine</SPAN> <BR> <SPAN class="keyword">feat</SPAN> <BR> canvas<BR> <BR> <SPAN class="keyword">attr</SPAN> <BR> Stack: nil<BR> Stopped: <SPAN class="keyword">false</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(Size Strategy Canvas)<BR> S={Space<SPAN class="keyword">.</SPAN>new {QueensScript Size Strategy}}<BR> <SPAN class="keyword">in</SPAN> <BR> Stopped <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">false</SPAN> <BR> Stack <SPAN class="keyword"><-</SPAN> [S]<BR> <SPAN class="keyword">self.</SPAN>canvas = Canvas<BR> {<SPAN class="keyword">self</SPAN> next}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">next</SPAN> <BR> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>Stack<BR> <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <BR> {<SPAN class="keyword">self</SPAN> finish}<BR> Stopped <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">true</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>canvas stop}<BR> <SPAN class="keyword">[]</SPAN> S<SPAN class="keyword">|</SPAN>Sr <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">if</SPAN> S<SPAN class="keyword">==</SPAN>backtrack <SPAN class="keyword">then</SPAN> <BR> Stack <SPAN class="keyword"><-</SPAN> Sr<BR> {<SPAN class="keyword">self</SPAN> backtrack}<BR> Engine<SPAN class="keyword">,</SPAN>next<BR> <SPAN class="keyword">else</SPAN> <BR> {<SPAN class="keyword">self</SPAN> show(S)}<BR> <SPAN class="keyword">case</SPAN> {Space<SPAN class="keyword">.</SPAN>ask S}<BR> <SPAN class="keyword">of</SPAN> alternatives(M) <SPAN class="keyword">then</SPAN> <BR> C={Space<SPAN class="keyword">.</SPAN>clone S}<BR> <SPAN class="keyword">in</SPAN> <BR> {Space<SPAN class="keyword">.</SPAN>commit S 1}<BR> {Space<SPAN class="keyword">.</SPAN>commit C 2<SPAN class="keyword">#</SPAN>M}<BR> Stack <SPAN class="keyword"><-</SPAN> S<SPAN class="keyword">|</SPAN>C<SPAN class="keyword">|</SPAN>backtrack<SPAN class="keyword">|</SPAN>Sr<BR> <SPAN class="keyword">[]</SPAN> failed <SPAN class="keyword">then</SPAN> <BR> Stack <SPAN class="keyword"><-</SPAN> backtrack<SPAN class="keyword">|</SPAN>Sr<BR> <SPAN class="keyword">[]</SPAN> succeeded <SPAN class="keyword">then</SPAN> <BR> Stack <SPAN class="keyword"><-</SPAN> backtrack<SPAN class="keyword">|</SPAN>Sr<BR> Stopped <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">true</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>canvas stop}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">sol</SPAN> <BR> Engine<SPAN class="keyword">,</SPAN> next<BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">@</SPAN>Stopped <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <SPAN class="keyword">else</SPAN> <BR> Engine<SPAN class="keyword">,</SPAN>sol<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">stop</SPAN> <BR> Stopped <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">true</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">start</SPAN> <BR> Stopped <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">false</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">ReflectForCrosses</SPAN> Xs}<BR> <SPAN class="keyword">case</SPAN> Xs <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> nil<BR> <SPAN class="keyword">[]</SPAN> X<SPAN class="keyword">|</SPAN>Xr <SPAN class="keyword">then</SPAN> {FD<SPAN class="keyword">.</SPAN>reflect<SPAN class="keyword">.</SPAN>domList X}<SPAN class="keyword">|</SPAN>{ReflectForCrosses Xr}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Reflect</SPAN> Xs}<BR> <SPAN class="keyword">case</SPAN> Xs <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> nil<BR> <SPAN class="keyword">[]</SPAN> X<SPAN class="keyword">|</SPAN>Xr <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">if</SPAN> {FD<SPAN class="keyword">.</SPAN>reflect<SPAN class="keyword">.</SPAN>size X}<SPAN class="keyword">==</SPAN>1 <SPAN class="keyword">then</SPAN> X <SPAN class="keyword">else</SPAN> void <SPAN class="keyword">end|</SPAN>{Reflect Xr}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">MakePainter</SPAN> Canvas Mag Size}<BR> Width = WidthByMag<SPAN class="keyword">.</SPAN>Mag<BR> Cross = CrossByMag<SPAN class="keyword">.</SPAN>Mag<BR> Queen = QueenByMag<SPAN class="keyword">.</SPAN>Mag<BR> Total = Size <SPAN class="keyword">*</SPAN> Width<BR> Fail0 = Total <SPAN class="keyword">div</SPAN> 4<BR> Fail1 = Fail0 <SPAN class="keyword">+</SPAN> Total <SPAN class="keyword">div</SPAN> 2<BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">DrawFail</SPAN> T}<BR> {Canvas tk(create line Fail0 Fail0 Fail1 Fail1<BR> width:FailWidth fill:FailColor capstyle:round tags:T)}<BR> {Canvas tk(create line Fail0 Fail1 Fail1 Fail0<BR> width:FailWidth fill:FailColor capstyle:round tags:T)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">DrawQueen</SPAN> X Y T}<BR> <SPAN class="keyword">if</SPAN> X<SPAN class="keyword">\=</SPAN>void <SPAN class="keyword">andthen</SPAN> Y<SPAN class="keyword">\=</SPAN>void <SPAN class="keyword">then</SPAN> <BR> {Canvas tk(create image (X<SPAN class="keyword">-</SPAN>1)<SPAN class="keyword">*</SPAN>Width (Y<SPAN class="keyword">-</SPAN>1)<SPAN class="keyword">*</SPAN>Width<BR> image: Queen<BR> tags: T<BR> anchor: nw)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> UpdateBoard<BR> ReflectBoard<BR> <BR> <SPAN class="keyword">if</SPAN> Cross<SPAN class="keyword">\=false</SPAN> <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">DrawCross</SPAN> X Y T}<BR> {Canvas tk(create image (X<SPAN class="keyword">-</SPAN>1)<SPAN class="keyword">*</SPAN>Width (Y<SPAN class="keyword">-</SPAN>1)<SPAN class="keyword">*</SPAN>Width<BR> image: Cross<BR> tags: T<BR> anchor: nw)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">DrawCrosses</SPAN> Os Ns I T}<BR> <SPAN class="keyword">case</SPAN> Os <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">[]</SPAN> O<SPAN class="keyword">|</SPAN>Or <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">case</SPAN> Ns <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> {DrawCross O I T} {DrawCrosses Or Ns I T}<BR> <SPAN class="keyword">[]</SPAN> N<SPAN class="keyword">|</SPAN>Nr <SPAN class="keyword">then</SPAN> <BR> {DrawCrosses Or <SPAN class="keyword">if</SPAN> O<SPAN class="keyword"><</SPAN>N <SPAN class="keyword">then</SPAN> {DrawCross O I T} Ns<BR> <SPAN class="keyword">else</SPAN> Nr <SPAN class="keyword">end</SPAN> I T}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">UpdateBoard</SPAN> Os Ns I T}<BR> <SPAN class="keyword">case</SPAN> Os <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">[]</SPAN> O<SPAN class="keyword">|</SPAN>Or <SPAN class="keyword">then</SPAN> N<SPAN class="keyword">|</SPAN>Nr=Ns <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> O<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">\=</SPAN>nil <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">case</SPAN> N <SPAN class="keyword">of</SPAN> [M] <SPAN class="keyword">then</SPAN> <BR> {DrawQueen M I T}<BR> <SPAN class="keyword">else</SPAN> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> {DrawCrosses O N I T}<BR> <SPAN class="keyword">end</SPAN> <BR> {UpdateBoard Or Nr I<SPAN class="keyword">+</SPAN>1 T}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> ReflectBoard = ReflectForCrosses<BR> <SPAN class="keyword">else</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">UpdateBoard</SPAN> Os Ns I T}<BR> <SPAN class="keyword">case</SPAN> Os <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">[]</SPAN> O<SPAN class="keyword">|</SPAN>Or <SPAN class="keyword">then</SPAN> N<SPAN class="keyword">|</SPAN>Nr=Ns <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> O<SPAN class="keyword">\=</SPAN>N <SPAN class="keyword">then</SPAN> <BR> {DrawQueen N I T}<BR> <SPAN class="keyword">end</SPAN> <BR> {UpdateBoard Or Nr I<SPAN class="keyword">+</SPAN>1 T}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> ReflectBoard = Reflect<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">$</SPAN> <BR> <SPAN class="keyword">from</SPAN><SPAN class="type"> Engine</SPAN> <BR> <SPAN class="keyword">attr</SPAN> Stack:nil<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">backtrack</SPAN> <BR> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>Stack <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">[]</SPAN> S<SPAN class="keyword">|</SPAN>Sr <SPAN class="keyword">then</SPAN> {S<SPAN class="keyword">.</SPAN>2 tkClose} Stack <SPAN class="keyword"><-</SPAN> Sr<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">show</SPAN>(S)<BR> NewT = {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:Canvas)}<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">case</SPAN> {Space<SPAN class="keyword">.</SPAN>ask S}<BR> <SPAN class="keyword">of</SPAN> failed <SPAN class="keyword">then</SPAN> <BR> {DrawFail NewT}<BR> Stack <SPAN class="keyword"><-</SPAN> _<SPAN class="keyword">#</SPAN>NewT<SPAN class="keyword">|@</SPAN>Stack<BR> <SPAN class="keyword">else</SPAN> <BR> NewB = {ReflectBoard {Space<SPAN class="keyword">.</SPAN>merge {Space<SPAN class="keyword">.</SPAN>clone S}}}<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>Stack <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <BR> Stack <SPAN class="keyword"><-</SPAN> [NewB<SPAN class="keyword">#</SPAN>NewT]<BR> <SPAN class="keyword">[]</SPAN> OldB<SPAN class="keyword">#</SPAN>_<SPAN class="keyword">|</SPAN>_ <SPAN class="keyword">then</SPAN> <BR> {UpdateBoard OldB NewB 1 NewT}<BR> Stack <SPAN class="keyword"><-</SPAN> NewB<SPAN class="keyword">#</SPAN>NewT<SPAN class="keyword">|@</SPAN>Stack<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">finish</SPAN> <BR> {Canvas tk(delete all)}<BR> <SPAN class="keyword">thread</SPAN> <BR> {Canvas<SPAN class="keyword">.</SPAN>sol tk(conf state:disabled)}<BR> {Canvas<SPAN class="keyword">.</SPAN>next tk(conf state:disabled)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Board</SPAN> <BR> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.canvas</SPAN> <BR> <BR> <SPAN class="keyword">prop</SPAN> <BR> locking<BR> <BR> <SPAN class="keyword">attr</SPAN> <BR> engine<BR> size: DefaultSize<BR> strategy: DefaultStrat<BR> <BR> <SPAN class="keyword">feat</SPAN> <BR> stop<BR> next<BR> sol<BR> toplevel<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(Top)<BR> <SPAN class="keyword">lock</SPAN> <BR> <SPAN class="keyword">self.</SPAN>toplevel = Top<BR> StratVar = {New Tk<SPAN class="keyword">.</SPAN>variable tkInit(DefaultStrat)}<BR> Menu = {TkTools<SPAN class="keyword">.</SPAN>menubar Top Top<BR> [menubutton(text:<SPAN class="string">'Queens'</SPAN> feature:queens<BR> menu: [command(label: <SPAN class="string">'About Queens'</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> about)<BR> command(label: <SPAN class="string">'Restart Search'</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> start)<BR> separator<BR> command(label: <SPAN class="string">'Quit'</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> close)])<BR> menubutton(text:<SPAN class="string">'Options'</SPAN> feature:options<BR> menu: [radiobutton(label: <SPAN class="string">'No Heuristic'</SPAN> <BR> var: StratVar<BR> value: NaiveStrat<BR> action:<BR> <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> <BR> setStrategy(NaiveStrat))<BR> radiobutton(label: <SPAN class="string">'Least First'</SPAN> <BR> var: StratVar<BR> value: FirstFailStrat<BR> action:<BR> <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> <BR> setStrategy(FirstFailStrat))<BR> radiobutton(label: <SPAN class="string">'Smart Least First'</SPAN> <BR> var: StratVar<BR> value: UpFirstStrat<BR> action:<BR> <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> <BR> setStrategy(UpFirstStrat))<BR> radiobutton(label: <SPAN class="string">'Middle First'</SPAN> <BR> var: StratVar<BR> value: MiddleOutStrat<BR> action:<BR> <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> <BR> setStrategy(MiddleOutStrat))<BR> separator<BR> command(label: <SPAN class="string">'Change Size'</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> setSize)])]<BR> nil}<BR> Frame = {New Tk<SPAN class="keyword">.</SPAN>frame tkInit(parent: Top)}<BR> <BR> Tk<SPAN class="keyword">.</SPAN>canvas<SPAN class="keyword">,</SPAN>tkInit(parent: Top<BR> relief: sunken<BR> bd: 2<BR> xscrollincrement: 1<BR> yscrollincrement: 1<BR> highlightthickness: 0<BR> background: WhiteColor)<BR> {<SPAN class="keyword">self</SPAN> tk(xview scroll <SPAN class="keyword">~</SPAN>2 units)}<BR> {<SPAN class="keyword">self</SPAN> tk(yview scroll <SPAN class="keyword">~</SPAN>2 units)}<BR> <BR> Stop = {New Tk<SPAN class="keyword">.</SPAN>button tkInit(parent: Frame<BR> text: <SPAN class="string">'Stop'</SPAN> <BR> state: disabled<BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> stop)}<BR> Next = {New Tk<SPAN class="keyword">.</SPAN>button tkInit(parent: Frame<BR> text: <SPAN class="string">'Next Step'</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> next)}<BR> Sol = {New Tk<SPAN class="keyword">.</SPAN>button tkInit(parent: Frame<BR> text: <SPAN class="string">'Next Solution'</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> sol)} <BR> <SPAN class="keyword">in</SPAN> <BR> {Menu<SPAN class="keyword">.</SPAN>options<SPAN class="keyword">.</SPAN>menu tk(conf tearoff:<SPAN class="keyword">false</SPAN>)}<BR> {Menu<SPAN class="keyword">.</SPAN>queens<SPAN class="keyword">.</SPAN>menu tk(conf tearoff:<SPAN class="keyword">false</SPAN>)}<BR> {Tk<SPAN class="keyword">.</SPAN>batch [pack(Menu side:top fill:x)<BR> pack(Stop Next Sol fill:x side:left)<BR> pack(<SPAN class="keyword">self</SPAN> Frame padx:4 pady:4 side:top)]}<BR> <SPAN class="keyword">self.</SPAN>stop = Stop<BR> <SPAN class="keyword">self.</SPAN>next = Next<BR> <SPAN class="keyword">self.</SPAN>sol = Sol<BR> Board<SPAN class="keyword">,</SPAN>start<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">setStrategy</SPAN>(Strat)<BR> <SPAN class="keyword">lock</SPAN> <BR> strategy <SPAN class="keyword"><-</SPAN> Strat<BR> Board<SPAN class="keyword">,</SPAN>stop<BR> Board<SPAN class="keyword">,</SPAN>start<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">setSize</SPAN> <BR> <SPAN class="keyword">lock</SPAN> <BR> Size<BR> Dialog = {New TkTools<SPAN class="keyword">.</SPAN>dialog<BR> tkInit(title: ParamWinTitle<BR> master: <SPAN class="keyword">self.</SPAN>toplevel<BR> buttons: [<SPAN class="string">'Okay'</SPAN> <SPAN class="keyword">#</SPAN> <BR> tkClose(<SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN>}<BR> Size={Top tkReturnInt(get $)}<BR> <SPAN class="keyword">end</SPAN>)]<BR> pack: <SPAN class="keyword">false</SPAN> <BR> focus: 1<BR> default: 1)}<BR> Frame = {New TkTools<SPAN class="keyword">.</SPAN>textframe tkInit(parent: Dialog<BR> text: <SPAN class="string">'Board Size'</SPAN>)}<BR> Top = {New Tk<SPAN class="keyword">.</SPAN>scale tkInit(parent: Frame<SPAN class="keyword">.</SPAN>inner<BR> <SPAN class="string">'from'</SPAN>: 4<BR> to: MaxBoardSize<BR> length: 8<SPAN class="keyword">#</SPAN>c<BR> orient: horizo<BR> showvalue: <SPAN class="keyword">true</SPAN>)}<BR> <SPAN class="keyword">in</SPAN> <BR> {Top tk(set <SPAN class="keyword">@</SPAN>size)}<BR> {Tk<SPAN class="keyword">.</SPAN>batch [pack(Top) pack(Frame fill:both)]}<BR> {Dialog tkPack}<BR> {Wait Size}<BR> size <SPAN class="keyword"><-</SPAN> Size<BR> Board<SPAN class="keyword">,</SPAN>stop<BR> Board<SPAN class="keyword">,</SPAN>start<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">about</SPAN> <BR> <SPAN class="keyword">lock</SPAN> <BR> Dialog = {New TkTools<SPAN class="keyword">.</SPAN>dialog tkInit(title: ParamWinTitle<BR> buttons: [<SPAN class="string">'Okay'</SPAN> <SPAN class="keyword">#</SPAN> tkClose]<BR> default: 1<BR> focus: 1<BR> master: <SPAN class="keyword">self.</SPAN>toplevel)}<BR> TitleAndQueen = {New Tk<SPAN class="keyword">.</SPAN>frame tkInit(parent: Dialog)}<BR> Title = {New Tk<SPAN class="keyword">.</SPAN>label tkInit(parent: TitleAndQueen<BR> font: LargeFont<BR> fg: blue<BR> text: <SPAN class="string">'Animated Queens'</SPAN>)}<BR> Queen = {New Tk<SPAN class="keyword">.</SPAN>label tkInit(parent: TitleAndQueen<BR> image: QueenByMag<SPAN class="keyword">.</SPAN>large)}<BR> Author = {New Tk<SPAN class="keyword">.</SPAN>label tkInit(parent: Dialog<BR> text:(<SPAN class="string">'Christian Schulte\n'</SPAN> <SPAN class="keyword">#</SPAN> <BR> <SPAN class="string">'(schulte@dfki.uni-sb.de)\n'</SPAN>))}<BR> <SPAN class="keyword">in</SPAN> <BR> {Tk<SPAN class="keyword">.</SPAN>batch [pack(Queen Title<BR> side:left fill:both ipadx:2<SPAN class="keyword">#</SPAN>m ipady:2<SPAN class="keyword">#</SPAN>m)<BR> pack(TitleAndQueen Author<BR> side:top padx:2<SPAN class="keyword">#</SPAN>m pady:2<SPAN class="keyword">#</SPAN>m)]}<BR> {Wait Dialog<SPAN class="keyword">.</SPAN>tkClosed}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">start</SPAN> <BR> <SPAN class="keyword">lock</SPAN> <BR> Size = <SPAN class="keyword">@</SPAN>size<BR> Strat = <SPAN class="keyword">@</SPAN>strategy<BR> Mag = <SPAN class="keyword">if</SPAN> Size<SPAN class="keyword">*</SPAN>WidthByMag<SPAN class="keyword">.</SPAN>large <SPAN class="keyword">=<</SPAN>MaxWidth <SPAN class="keyword">then</SPAN> large<BR> <SPAN class="keyword">elseif</SPAN> Size<SPAN class="keyword">*</SPAN>WidthByMag<SPAN class="keyword">.</SPAN>middle<SPAN class="keyword">=<</SPAN>MaxWidth <SPAN class="keyword">then</SPAN> middle<BR> <SPAN class="keyword">elseif</SPAN> Size<SPAN class="keyword">*</SPAN>WidthByMag<SPAN class="keyword">.</SPAN>small <SPAN class="keyword">=<</SPAN>MaxWidth <SPAN class="keyword">then</SPAN> small<BR> <SPAN class="keyword">elseif</SPAN> Size<SPAN class="keyword">*</SPAN>WidthByMag<SPAN class="keyword">.</SPAN>tiny <SPAN class="keyword">=<</SPAN>MaxWidth <SPAN class="keyword">then</SPAN> tiny<BR> <SPAN class="keyword">else</SPAN> micro<BR> <SPAN class="keyword">end</SPAN> <BR> MagWidth = WidthByMag<SPAN class="keyword">.</SPAN>Mag<BR> Width = Size<SPAN class="keyword">*</SPAN>MagWidth<BR> <SPAN class="keyword">in</SPAN> <BR> {<SPAN class="keyword">self</SPAN> tk(delete all)}<BR> {<SPAN class="keyword">self</SPAN> tk(configure width:Width height:Width)}<BR> {For 0 Size<SPAN class="keyword">-</SPAN>1 2<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> {For 1 Size<SPAN class="keyword">-</SPAN>1 2<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> J}<BR> {<SPAN class="keyword">self</SPAN> tk(crea rectangle<BR> I<SPAN class="keyword">*</SPAN>MagWidth J<SPAN class="keyword">*</SPAN>MagWidth<BR> (I<SPAN class="keyword">+</SPAN>1)<SPAN class="keyword">*</SPAN>MagWidth (J<SPAN class="keyword">+</SPAN>1)<SPAN class="keyword">*</SPAN>MagWidth<BR> fill:BlackColor outline:<SPAN class="string">''</SPAN>)}<BR> <SPAN class="keyword">end</SPAN>}<BR> <SPAN class="keyword">end</SPAN>}<BR> {For 1 Size<SPAN class="keyword">-</SPAN>1 2<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> I}<BR> {For 0 Size<SPAN class="keyword">-</SPAN>1 2<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> J}<BR> {<SPAN class="keyword">self</SPAN> tk(crea rectangle<BR> I<SPAN class="keyword">*</SPAN>MagWidth J<SPAN class="keyword">*</SPAN>MagWidth<BR> (I<SPAN class="keyword">+</SPAN>1)<SPAN class="keyword">*</SPAN>MagWidth (J<SPAN class="keyword">+</SPAN>1)<SPAN class="keyword">*</SPAN>MagWidth<BR> fill:BlackColor outline:<SPAN class="string">''</SPAN>)}<BR> <SPAN class="keyword">end</SPAN>}<BR> <SPAN class="keyword">end</SPAN>}<BR> {<SPAN class="keyword">self.</SPAN>sol tk(conf state:normal)}<BR> {<SPAN class="keyword">self.</SPAN>next tk(conf state:normal)}<BR> engine <SPAN class="keyword"><-</SPAN> {New {MakePainter <SPAN class="keyword">self</SPAN> Mag Size}<BR> init(Size Strat <SPAN class="keyword">self</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">stop</SPAN> <BR> {<SPAN class="keyword">@</SPAN>engine stop}<BR> {<SPAN class="keyword">self.</SPAN>stop tk(conf state:disabled)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">next</SPAN> <BR> <SPAN class="keyword">lock</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>sol tk(conf state:disabled)}<BR> {<SPAN class="keyword">self.</SPAN>next tk(conf state:disabled)}<BR> {<SPAN class="keyword">@</SPAN>engine next}<BR> {<SPAN class="keyword">self.</SPAN>sol tk(conf state:normal)}<BR> {<SPAN class="keyword">self.</SPAN>next tk(conf state:normal)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">sol</SPAN> <BR> <SPAN class="keyword">lock</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>sol tk(conf state:disabled)}<BR> {<SPAN class="keyword">self.</SPAN>next tk(conf state:disabled)}<BR> {<SPAN class="keyword">self.</SPAN>stop tk(conf state:normal)}<BR> {<SPAN class="keyword">@</SPAN>engine start}<BR> {<SPAN class="keyword">@</SPAN>engine sol}<BR> {<SPAN class="keyword">self.</SPAN>sol tk(conf state:normal)}<BR> {<SPAN class="keyword">self.</SPAN>next tk(conf state:normal)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">close</SPAN> <BR> <SPAN class="keyword">lock</SPAN> <BR> {Application<SPAN class="keyword">.</SPAN>exit 0}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> Top = {New Tk<SPAN class="keyword">.</SPAN>toplevel tkInit(title: <SPAN class="string">'Animated Queens'</SPAN> <BR> delete: Application<SPAN class="keyword">.</SPAN>exit <SPAN class="keyword">#</SPAN> 0)}<BR> <BR> {New Board init(Top) _}<BR> <BR><SPAN class="keyword">end</SPAN> <BR> <BR></PRE></BLOCKQUOTE><P></P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="queens.html">- Up -</A></TD></TR></TABLE><HR><ADDRESS><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|