Scid  4.6.5
material.tcl
Go to the documentation of this file.
1 ###
2 ### search/material.tcl: Material Search routine for Scid.
3 ###
4 
5 namespace eval ::search::material {}
6 
7 ##########
8 # Size 20 is only used in Material search window, not for boards.
9 # It has two special extra images, wm20 and bm20, which contain a
10 # bishop and knight, for indicating a minor piece.
11 #
12 
13 image create photo wm20 -data {
14  R0lGODlhFAAUAMIAAH9/f7+/vz8/PwAAAP///////////////yH5BAEKAAcALAAAAAAUABQA
15  AANweLp8cCG02cSwNB8RSACctgBAR3iDqJDd5wlidBLCHGb1CQzzx+yPDYAWyJ1gixpSwOLM
16  CClFESSRup7RImF42zxP0Vpg0EE6SGjSCqxTKYxHN4RJ6sYETHxVNa3vM2gDQyBoGkNbhIdq
17  FHRBZyAaCQA7}
18 
19 image create photo bm20 -data {
20  R0lGODlhFAAUAMIAAH9/f7+/vwAAAD8/P////////////////yH5BAEKAAcALAAAAAAUABQA
21  AANneLp8cCG02YQYgupj+5CbEgyYAAQCuJHlNYZo1wHDo7VyOjSAebQxS69R25UCvVlmMXIp
22  TrmhSGgB4S5LzoVQegK+YJtWwLWEFjnzGVL7ftYQMoGQggerZ3CrLealoxomXxJIX1kNCQA7
23 }
24 
25 image create photo p20 -data {
26  R0lGODlh8AAUAMIAAH9/fz8/P7+/vwAAAP///////////////yH5BAEKAAcALAAAAADwABQA
27  AAP+eLrc/jDKSau9OOvNu/8VAIBkJAhl2ohqe5xuCgTBGL/oQaMwJew30KwWhAkGA0Vv8gvk
28  LALRUxJ9BTSAk40qFXWzkKZWCmQit5Uo2GdDW4ZuiFQ9koZ33mxZAjhjBidJFDNIRBgBhRQD
29  Q4t9NH0NP3o1BEgEYjNTDix/SIITfQOIcROIooOFpouekV6PlQMEQ2qaK6QSsZUholGit5GA
30  BJeAuMIixgDCnwrJAbKLsMPNsiY0VxeeyxGhnoZm2cTb4OMrP88C0X3NVWF+2CLaELnCUTRm
31  6CfDtQuUwv7G1xb8iHUkmSV1lZy0GpErSZR9DbJVUOULCUQl3VRdPDL+rtsKRM8MxuqDjlcr
32  FBIflkomK+CdLP8I2Ivg5NIOmxIe5RnygOSzhDKlLGqg01LCGjMhUHQpj1AhmfEYmHIy8JSJ
33  jlZXAHIUDWRBojWcFnK1zZk/bw9oBLt09lcuMcpA7eS0CU8WVyIeMTBHD9ARdMjkjPt14BhF
34  QEkddDuhSm7MqIUrrgJ0ZhSDvJIr+7o14x9dB3z9zTtCE3A+nHxiUpNXsFKgXj+mHPN3pKa/
35  z5cH48LqJJwDVWoT8enYDis4W9k4cjzjliWk0p5ZBn5QcKdvOardXqqXN1nJVjFpxMTNgJw4
36  4zypj3V6kRlxecYl7g0+mZtewcLQ/vYMjTb+U6lh5fXfJtmVNcpOj/xnGzL/kHaeO/AZ1xtN
37  AaY3nHk9dZOHKnH0th43M1D4T2KXzebEbKKVFcoMhDEz1y8cvUjIPo3AU2MmNI0zYGEU2eiJ
38  a3JUqF9PFT6nnnd5GHMdRrScQMeSC3Q23oCdxXaEapAdMI+Sisy1I0YyQslMgOi48iU34AzY
39  yxlQJTfUA1hRoJMXYmJkHESOLIXIl1v+A5mAMgE2IkS9qLUGdDH9gIt0fprAaHQRxHeHeIfV
40  eEc2CuV0Z6TrNVYcVrdEodp0ZY36WVVsPrPYb/HxmVFykfrYyJfLddTeCx15MZ8ovJlEVHx1
41  zoNillrWICgh2zxpeluLfbZVnllK9pefNiiaSopPWLrVD0BZoqnbboOhBexxEQF7bXxuGfdg
42  rlTEJxt9YDh1n0Dj7rOmjhtVmmmG6E2ArlRpapGmYsDa6+2qlwYcxAWHyrHwwxAX1h47EVds
43  8cUYZ6xxBwkAADs=
44 }
45 
46 image create photo e20 -height 20 -width 20
47 set x 0
48 foreach p {wp wn wb wr wq wk bp bn bb br bq bk} {
49  image create photo ${p}20 -width 20 -height 20
50  ${p}20 copy p20 -from $x 0 [expr $x + 19] 19
51  incr x 20
52 }
53 
54 set ignoreColors 0
55 set minMoveNum 1
56 set maxMoveNum 999
57 set minHalfMoves 1
58 set oppBishops "Either"
59 set minMatDiff -40
60 set maxMatDiff +40
61 
62 trace variable minMoveNum w {::utils::validate::Integer 999 0}
63 trace variable maxMoveNum w {::utils::validate::Integer 999 0}
64 trace variable minHalfMoves w {::utils::validate::Integer 99 0}
65 trace variable minMatDiff w {::utils::validate::Integer -99 0}
66 trace variable maxMatDiff w {::utils::validate::Integer -99 0}
67 
68 set nPatterns 10
69 
70 array set pMin [list wq 0 bq 0 wr 0 br 0 wb 0 bb 0 wn 0 bn 0 wm 0 bm 0 wp 0 bp 0]
71 array set pMax [list wq 2 bq 2 wr 2 br 2 wb 2 bb 2 wn 2 bn 2 wm 4 bm 4 wp 8 bp 8]
72 for { set i 1} { $i <= $nPatterns } { incr i} {
73  set pattPiece($i) "?"; set pattFyle($i) "?"; set pattRank($i) "?"
74 }
75 
76 proc checkPieceCounts {name el op} {
77  global pMin pMax
78  ::utils::validate::Integer 9 0 $name $el $op
79  # Now make sure minor piece counts fit with bishop/knight counts:
80  set wmMin [expr {$pMin(wn) + $pMin(wb)}]
81  set wmMax [expr {$pMax(wn) + $pMax(wb)}]
82  set bmMin [expr {$pMin(bn) + $pMin(bb)}]
83  set bmMax [expr {$pMax(bn) + $pMax(bb)}]
84  if {$pMin(wm) < $wmMin} { set pMin(wm) $wmMin}
85  if {$pMax(wm) > $wmMax} { set pMax(wm) $wmMax}
86  if {$pMin(bm) < $bmMin} { set pMin(bm) $bmMin}
87  if {$pMax(bm) > $bmMax} { set pMax(bm) $bmMax}
88  foreach p {wq wr wb wn wm wp bq br bb bn bm bp} {
89  if {$pMax($p) != "" && $pMax($p) < $pMin($p)} { set pMax($p) $pMin($p)}
90  }
91 }
92 
93 trace variable pMin w checkPieceCounts
94 trace variable pMax w checkPieceCounts
95 
96 
97 proc makeBoolMenu {w varName} {
98  upvar #0 $varName var
99  if {![info exists var]} { set var "Yes"}
100  # ttk::menubutton $w -textvariable $varName -menu $w.menu -image "" -style pad0.TMenubutton ;# -relief raised -bd 2 -highlightthickness 2 -indicatoron 0 -anchor w
101  menubutton $w -textvariable $varName -indicatoron 0 -menu $w.menu \
102  -relief raised -bd 2 -highlightthickness 0 -anchor w -image ""
103 
104  menu $w.menu -tearoff 0
105  $w.menu add radiobutton -label Yes -image tb_tick -variable $varName -value Yes \
106  -command "$w configure -image tb_tick" ;# -hidemargin 1
107  $w.menu add radiobutton -label No -image tb_cross -variable $varName -value No \
108  -command "$w configure -image tb_cross" ;# -hidemargin 1
109  return $w.menu
110 }
111 
112 proc makePieceMenu {w varName} {
113  global dark
114  upvar #0 $varName var
115  if {![info exists var]} { set var "?"}
116  # ttk::menubutton $w -textvariable $varName -menu $w.menu -image "" -style pad0.TMenubutton ;# -indicatoron 0 -relief raised -bd 2 -highlightthickness 2 -anchor w
117  menubutton $w -textvariable $varName -indicatoron 0 -menu $w.menu \
118  -relief raised -bd 2 -highlightthickness 0 -anchor w -image ""
119  menu $w.menu -tearoff 0
120  $w.menu add radiobutton -label " ? " -variable $varName -value "?" \
121  -command "$w configure -image e20" -hidemargin 1
122  foreach i {wk wq wr wb wn wp bk bq br bb bn bp} {
123  $w.menu add radiobutton -label $i -image ${i}20 -value $i \
124  -variable $varName \
125  -command "$w configure -image ${i}20" -hidemargin 1
126  }
127  foreach i {" ? " wk bk} {
128  $w.menu entryconfigure $i -columnbreak 1
129  }
130  return $w.menu
131 }
132 
133 proc updatePatternImages {} {
134  global pattPiece nPatterns pattBool
135  if {! [winfo exists .sm]} { return}
136  for {set i 1} {$i <= $nPatterns} {incr i} {
137  if {$pattBool($i) == "Yes"} {
138  .sm.mp.patt.grid.b$i configure -image tb_tick
139  } else {
140  .sm.mp.patt.grid.b$i configure -image tb_cross
141  }
142  if {$pattPiece($i) == "?"} {
143  .sm.mp.patt.grid.p$i configure -image e20
144  } else {
145  .sm.mp.patt.grid.p$i configure -image "$pattPiece($i)20"
146  }
147  }
148 }
149 
150 # ::search::material::zero
151 #
152 # Called to clear all material minimum/maximum values to zero.
153 #
154 proc ::search::material::zero {} {
155  global pMin pMax
156  array set pMin {wq 0 bq 0 wr 0 br 0 wb 0 bb 0 wn 0 bn 0 wm 0 bm 0 wp 0 bp 0}
157  array set pMax {wq 0 bq 0 wr 0 br 0 wb 0 bb 0 wn 0 bn 0 wm 0 bm 0 wp 0 bp 0}
158 }
159 
160 proc ::search::material::any {} {
161  global pMin pMax
162  array set pMin {wq 0 bq 0 wr 0 br 0 wb 0 bb 0 wn 0 bn 0 wm 0 bm 0 wp 0 bp 0}
163  array set pMax {wq 2 bq 2 wr 2 br 2 wb 2 bb 2 wn 2 bn 2 wm 4 bm 4 wp 8 bp 8}
164  set ::minMatDiff -40
165  set maxMatDiff +40
166 }
167 
168 proc clearPatterns {} {
169  global pattPiece pattFyle pattRank pattBool nPatterns
170 
171  for { set i 1} { $i <= $nPatterns } { incr i} {
172  set pattPiece($i) "?"; set pattFyle($i) "?"; set pattRank($i) "?"
173  set pattBool($i) "Yes"
174  }
176 }
177 
178 proc setPatterns {pattlist} {
179  global pattPiece pattFyle pattRank pattBool nPatterns
180 
182  set count 1
183  foreach patt $pattlist {
184  if {$count <= $nPatterns && [llength $patt] == 4} {
185  set pattPiece($count) [lindex $patt 0]
186  set pattFyle($count) [lindex $patt 1]
187  set pattRank($count) [lindex $patt 2]
188  set pattBool($count) [lindex $patt 3]
189  incr count
190  }
191  }
193 }
194 
195 set smDisplayed(Material) 1
196 set smDisplayed(Patterns) 0
197 
198 
199 # ::search::material
200 #
201 # Opens the window for searching by material or patterns.
202 #
203 proc ::search::material {{ref_base ""}} {
204  global dark pMin pMax ignoreColors minMoveNum maxMoveNum
205  global pattPiece pattFyle pattRank pattBool oppBishops nPatterns
206  global minHalfMoves smDisplayed
207 
208  set w .sm
209  if {[winfo exists $w]} {
210  wm deiconify $w
211  raiseWin $w
212  return
213  }
214  set small font_Small
215 
216  toplevel $w
217  wm title $w "Scid: $::tr(MaterialSearch)"
218  # button $w.piecelabel -font font_Bold -textvar ::tr(Material:) -command {
219  # if {$smDisplayed(Material)} {
220  # set smDisplayed(Material) 0
221  # pack forget .sm.q .sm.r .sm.b .sm.n .sm.m .sm.p .sm.b1 .sm.mdiff
222  # } else {
223  # set smDisplayed(Material) 1
224  # pack .sm.q .sm.r .sm.b .sm.n .sm.m .sm.p .sm.b1 .sm.mdiff \
225  # -after .sm.piecelabel
226  # }
227  # }
228 
229  bind $w <F1> { helpWindow Searches Material }
230  bind $w <Escape> "$w.b3.cancel invoke"
231  bind $w <Return> "$w.b3.search invoke"
232 
233  pack [ttk::frame $w.refdb] -side top -fill x
234  CreateSelectDBWidget "$w.refdb" "refDatabaseM" "$ref_base"
236 
237  pack [ttk::frame $w.mp] -side top
238  pack [ttk::frame $w.mp.material] -side left
239 
240  ttk::label $w.mp.material.title -font font_Bold -textvar ::tr(Material:)
241  pack $w.mp.material.title -side top -pady 3
242 
243  foreach piece {q r b n m p} {
244  ttk::frame $w.mp.material.$piece
245  pack $w.mp.material.$piece -side top
246  }
247 
248  foreach i {q r b n m p} {
249  set f $w.mp.material.$i
250  ttk::button $f.w0 -text "0" -command "set pMin(w$i) 0; set pMax(w$i) 0"
251  ttk::button $f.w1 -text "1" -command "set pMin(w$i) 1; set pMax(w$i) 1"
252  ttk::button $f.w2 -text "2" -command "set pMin(w$i) 2; set pMax(w$i) 2"
253  ttk::button $f.wa -text "0+" -command "set pMin(w$i) 0; set pMax(w$i) 2"
254  ttk::button $f.w1p -text "1+" -command "set pMin(w$i) 1; set pMax(w$i) 2"
255  ttk::label $f.wi -image w${i}20 -font font_Small
256  ttk::label $f.wto -text "-" -font font_Small -padding 0
257  ttk::entry $f.wmin -width 2 -textvar pMin(w$i) -font font_Small -justify right ;#-relief sunken
258  ttk::entry $f.wmax -width 2 -textvar pMax(w$i) -font font_Small -justify right ;#-relief sunken
259  pack $f.w0 $f.w1 $f.w2 $f.wa $f.w1p $f.wi $f.wmin $f.wto $f.wmax -side left -pady 1
260 
261  pack [ttk::frame $f.space -width 20] -side left
262  ttk::button $f.b0 -text "0" -command "set pMin(b$i) 0; set pMax(b$i) 0"
263  ttk::button $f.b1 -text "1" -command "set pMin(b$i) 1; set pMax(b$i) 1"
264  ttk::button $f.b2 -text "2" -command "set pMin(b$i) 2; set pMax(b$i) 2"
265  ttk::button $f.ba -text "0+" -command "set pMin(b$i) 0; set pMax(b$i) 2"
266  ttk::button $f.b1p -text "1+" -command "set pMin(b$i) 1; set pMax(b$i) 2"
267  ttk::label $f.bi -image b${i}20 -font font_Small
268  ttk::label $f.bto -text "-" -font font_Small
269  ttk::entry $f.bmin -width 2 -textvar pMin(b$i) -font font_Small -justify right ;#-relief sunken
270  ttk::entry $f.bmax -width 2 -textvar pMax(b$i) -font font_Small -justify right ;#-relief sunken
271  pack $f.b0 $f.b1 $f.b2 $f.ba $f.b1p $f.bi $f.bmin $f.bto $f.bmax -side left -pady 1
272 
273  foreach b {0 1 2 a 1p} {
274  $f.w$b configure -width 2 -takefocus 0 -style Pad0.Small.TButton ;# -font $small -pady 0 -padx 1
275  $f.b$b configure -width 2 -takefocus 0 -style Pad0.Small.TButton ;# -font $small -pady 0 -padx 1
276  }
277  foreach widget {wmin wmax bmin bmax} {
278  bindFocusColors $f.$widget
279  }
280  if {$i == "p"} {
281  $f.w1p configure -command "set pMin(wp) 1; set pMax(wp) 8"
282  $f.wa configure -command "set pMin(wp) 0; set pMax(wp) 8"
283  $f.b1p configure -command "set pMin(bp) 1; set pMax(bp) 8"
284  $f.ba configure -command "set pMin(bp) 0; set pMax(bp) 8"
285  }
286  if {$i == "m"} {
287  $f.w1p configure -command "set pMin(wm) 1; set pMax(wm) 4"
288  $f.wa configure -command "set pMin(wm) 0; set pMax(wm) 4"
289  $f.b1p configure -command "set pMin(bm) 1; set pMax(bm) 4"
290  $f.ba configure -command "set pMin(bm) 0; set pMax(bm) 4"
291  }
292  }
293 
294  # Buttons that manipulate material settings:
295  set f $w.mp.material.b1
296  pack [ttk::frame $f] -side top -ipady 2
297 
298  dialogbuttonsmall $f.zero [ list -textvar ::tr(Zero) -command ::search::material::zero] Pad0.Small.TButton
299  dialogbuttonsmall $f.reset [ list -textvar ::tr(Any) -command ::search::material::any] Pad0.Small.TButton
300  dialogbuttonsmall $f.current [ list -textvar ::tr(CurrentBoard) -command {
301  ::search::material::zero
302  set bd [sc_pos board]
303  for {set i 0} {$i < 64} {incr i} {
304  set piece $::board::letterToPiece([ string index $bd $i ])
305  if {$piece != "e" && $piece != "wk" && $piece != "bk"} {
306  incr pMin($piece); set pMax($piece) $pMin($piece)
307  }
308  }
309  }] Pad0.Small.TButton
310 
311  ttk::menubutton $f.common -textvar ::tr(CommonEndings...) -menu $f.common.m -style pad0.TMenubutton ;# -font $small -relief raised
312  menu $f.common.m -font $small
313  set m $f.common.m
314  $m add command -label [tr EndingPawns] -command {
315  ::search::material::zero
316  array set pMin {wp 1 bp 1}
317  array set pMax {wp 8 bp 8}
318  }
319  $m add command -label [tr EndingRookVsPawns] -command {
320  ::search::material::zero
321  array set pMin {wr 1 bp 1}
322  array set pMax {wr 1 bp 8}
323  }
324  $m add command -label [tr EndingRookPawnVsRook] -command {
325  ::search::material::zero
326  array set pMin {wr 1 br 1 wp 1}
327  array set pMax {wr 1 br 1 wp 1}
328  }
329  $m add command -label [tr EndingRookPawnsVsRook] -command {
330  ::search::material::zero
331  array set pMin {wr 1 br 1 wp 1}
332  array set pMax {wr 1 br 1 wp 8}
333  }
334  $m add command -label [tr EndingRooks] -command {
335  ::search::material::zero
336  array set pMin {wr 1 br 1}
337  array set pMax {wr 1 br 1 wp 8 bp 8}
338  set pMin(wr) 1; set pMax(wr) 1; set pMin(wp) 0; set mPax(wp) 8
339  set pMin(br) 1; set pMax(br) 1; set pMin(bp) 0; set mPax(bp) 8
340  }
341  $m add command -label [tr EndingRooksPassedA] -command {
342  ::search::material::zero
343  array set pMin {wr 1 br 1 wp 1}
344  array set pMax {wr 1 br 1 wp 8 bp 8}
345  setPatterns {{wp a ? Yes} {bp a ? No} {bp b ? No}}
346  set ignoreColors 1
347  }
348  $m add command -label [tr EndingRooksDouble] -command {
349  ::search::material::zero
350  array set pMin {wr 2 br 2}
351  array set pMax {wr 2 br 2 wp 8 bp 8}
352  }
353  $m add command -label [tr EndingBishops] -command {
354  ::search::material::zero
355  array set pMin {wb 1 bb 1 wm 1 bm 1}
356  array set pMax {wb 1 bb 1 wm 1 bm 1 wp 8 bp 8}
357  }
358  $m add command -label [tr EndingBishopVsKnight] -command {
359  ::search::material::zero
360  array set pMin {wb 1 bn 1 wm 1 bm 1}
361  array set pMax {wb 1 bn 1 wm 1 bm 1 wp 8 bp 8}
362  }
363  $m add command -label [tr EndingKnights] -command {
364  ::search::material::zero
365  array set pMin {wn 1 bn 1 wm 1 bm 1}
366  array set pMax {wn 1 bn 1 wm 1 bm 1 wp 8 bp 8}
367  }
368  $m add command -label [tr EndingQueens] -command {
369  ::search::material::zero
370  array set pMin {wq 1 bq 1}
371  array set pMax {wq 1 bq 1 wp 8 bp 8}
372  }
373  $m add command -label [tr EndingQueenPawnVsQueen] -command {
374  ::search::material::zero
375  array set pMin {wq 1 bq 1 wp 1}
376  array set pMax {wq 1 bq 1 wp 1}
377  }
378  $m add command -label [tr BishopPairVsKnightPair] -command {
379  ::search::material::zero
380  array set pMin {wb 2 bn 2 wm 2 bm 2}
381  array set pMax {wq 1 bq 1 wr 2 br 2 wb 2 bn 2 wm 2 bm 2 wp 8 bp 8}
382  }
383 
384  pack $f.zero $f.reset $f.current $f.common -side left -pady 5 -padx 10
385  #if {! $smDisplayed(Material)} {
386  # pack forget .sm.q .sm.r .sm.b .sm.n .sm.m .sm.p .sm.b1 .sm.mdiff
387  #}
388 
389  set f $w.mp.material.mdiff
390  pack [ttk::frame $f] -side top
391  ttk::label $f.label -font font_SmallBold -textvar ::tr(MaterialDiff:)
392  ttk::entry $f.min -width 3 -textvar minMatDiff -font $small -justify right ;#-relief sunken
393  bindFocusColors $f.min
394  ttk::label $f.sep -text "-" -font $small
395  ttk::entry $f.max -width 3 -textvar maxMatDiff -font $small -justify right ;#-relief sunken
396  bindFocusColors $f.max
397  ttk::label $f.sep2 -text " " -font $small
398  ttk::button $f.any -textvar ::tr(Any) -style Pad0.Small.TButton -command {set minMatDiff -40; set maxMatDiff +40} -width 0
399  ttk::button $f.w1 -text " + " -style Pad0.Small.TButton -command {set minMatDiff +1; set maxMatDiff +40} -width 0
400  ttk::button $f.equal -text " = " -style Pad0.Small.TButton -command {set minMatDiff 0; set maxMatDiff 0} -width 0
401  ttk::button $f.b1 -text " - " -style Pad0.Small.TButton -command {set minMatDiff -40; set maxMatDiff -1} -width 0
402  pack $f.label $f.min $f.sep $f.max -side left
403  pack $f.sep2 $f.any $f.w1 $f.equal $f.b1 -side left -padx 1 -pady 1
404  set f [ttk::frame $w.mp.material.mdiff2]
405  pack $f -side top
406  ttk::label $f.explan -font $small -text "($::tr(MaterialDiff) = $::tr(White) - $::tr(Black); Q=9 R=5 B=3 N=3 P=1)"
407  pack $f.explan -side top
408 
409  addVerticalRule $w.mp
410 
411  set f [ttk::frame $w.mp.patt]
412  pack $f -side top
413 
414  #dialogbutton $w.pattl -font font_Bold -textvar ::tr(Patterns:) -command {
415  # if {$smDisplayed(Patterns)} {
416  # set smDisplayed(Patterns) 0
417  # pack forget .sm.patt .sm.b2
418  # } else {
419  # set smDisplayed(Patterns) 1
420  # pack .sm.patt .sm.b2 -after .sm.pattl
421  # }
422  #}
423  ttk::label $w.mp.patt.title -textvar ::tr(Patterns:) -font font_Bold
424  pack $w.mp.patt.title -side top -pady 3
425 
426  pack [ttk::frame $f.grid] -side top -fill both -expand 1
427  for { set i 1} { $i <= $nPatterns } { incr i} {
428  makeBoolMenu $f.grid.b$i pattBool($i)
429  set menuPiece1 [ makePieceMenu $f.grid.p$i pattPiece($i)]
430  tk_optionMenu $f.grid.f$i pattFyle($i) "?" a b c d e f g h
431  tk_optionMenu $f.grid.r$i pattRank($i) "?" 1 2 3 4 5 6 7 8
432  # $f.grid.b$i configure -style pad0.TMenubutton
433  $f.grid.b$i configure -indicatoron 0 ;# -width 4
434 
435  $f.grid.f$i configure -width 1 -indicatoron 0 -pady 0
436  $f.grid.r$i configure -width 1 -indicatoron 0 -pady 0
437  set column [expr {5 * (($i - 1) / 5)}]
438  set row [expr {($i - 1) % 5}]
439  grid $f.grid.b$i -row $row -column $column -padx 0 -pady 0 ; incr column
440  grid $f.grid.p$i -row $row -column $column -padx 0 -pady 0 ; incr column
441  grid $f.grid.f$i -row $row -column $column -padx 0 -pady 0 ; incr column
442  grid $f.grid.r$i -row $row -column $column -padx 0 -pady 0; incr column
443  if {$column == 4 || $column == 9} {
444  ttk::label $f.grid.sp_$i -text " "
445  grid $f.grid.sp_$i -row $row -column $column
446  }
447  }
448 
450 
451  ### Buttons that manipulate patterns:
452  set f .sm.mp.patt.b2
453  ttk::frame $f
454  dialogbutton $f.clearPat -textvar ::tr(Clear) -command clearPatterns
455  ttk::menubutton $f.common -textvar ::tr(CommonPatterns...) -menu $f.common.m
456  menu $f.common.m -font $small
457  $f.common.m add command -label [tr PatternWhiteIQP] -command {
458  if {$pMin(wp) < 1} { set pMin(wp) 1 }
459  setPatterns {{wp d ? Yes} {wp c ? No} {wp e ? No}}
460  }
461  $f.common.m add command -label [tr PatternWhiteIQPBreakE6] -command {
462  if {$pMin(wp) < 1} { set pMin(wp) 1 }
463  if {$pMin(bp) < 1} { set pMin(bp) 1 }
464  setPatterns {{wp d 5 Yes} {wp c ? No} {wp e ? No} {wp d 4 No} \
465  {bp e 6 Yes} {bp c ? No} {bp d ? No}}
466  }
467  $f.common.m add command -label [tr PatternWhiteIQPBreakC6] -command {
468  if {$pMin(wp) < 1} { set pMin(wp) 1 }
469  if {$pMin(bp) < 1} { set pMin(bp) 1 }
470  setPatterns {{wp d 5 Yes} {wp c ? No} {wp e ? No} {wp d 4 No} \
471  {bp c 6 Yes} {bp e ? No} {bp d ? No}}
472  }
473  $f.common.m add command -label [tr PatternBlackIQP] -command {
474  if {$pMin(bp) < 1} { set pMin(bp) 1 }
475  setPatterns {{bp d ? Yes} {bp c ? No} {bp e ? No}}
476  }
477  $f.common.m add command -label [tr PatternWhiteBlackIQP] -command {
478  if {$pMin(wp) < 1} { set pMin(wp) 1 }
479  if {$pMin(bp) < 1} { set pMin(bp) 1 }
480  setPatterns {{wp d ? Yes} {wp c ? No} {wp e ? No} \
481  {bp d ? Yes} {bp c ? No} {bp e ? No}}
482  }
483  $f.common.m add command -label [tr PatternCoupleC3D4] -command {
484  set pMin(wp) 4; set pMax(wp) 6
485  set pMin(bp) 4; set pMax(bp) 6
486  setPatterns {{wp c 3 Yes} {wp d 4 Yes} {wp b ? No} {wp e ? No}
487  {bp c ? No} {bp d ? No}}
488  }
489  $f.common.m add command -label [tr PatternHangingC5D5] -command {
490  set pMin(bp) 4; set pMax(bp) 6
491  set pMin(wp) 4; set pMax(wp) 6
492  setPatterns {{bp c 5 Yes} {bp d 5 Yes} {bp b ? No} {bp e ? No}
493  {wp c ? No} {wp d ? No}}
494  }
495  $f.common.m add command -label [tr PatternMaroczy] -command {
496  if {$pMin(bp) < 1} { set pMin(bp) 1 }
497  if {$pMax(bp) > 7} { set pMax(bp) 7 }
498  if {$pMin(wp) < 2} { set pMin(wp) 2 }
499  if {$pMax(wp) > 7} { set pMax(wp) 7 }
500  setPatterns {{wp c 4 Yes} {wp e 4 Yes} {bp d ? Yes} {wp d ? No}
501  {bp c ? No} {bp d 5 No}}
502  }
503  $f.common.m add command -label [tr PatternRookSacC3] -command {
504  set pMin(br) 2; set pMax(br) 2
505  set pMin(wr) 2; set pMax(wr) 2
506  setPatterns { {br c 3 Yes} {wp b 2 Yes} }
507  }
508  $f.common.m add command -label [tr PatternKc1Kg8] -command {
509  setPatterns { {wk c 1 Yes} {bk g 8 Yes} }
510  }
511  $f.common.m add command -label [tr PatternKg1Kc8] -command {
512  setPatterns { {wk g 1 Yes} {bk c 8 Yes} }
513  }
514  $f.common.m add command -label [tr PatternLightFian] -command {
515  set pMin(wb) 1; set pMin(bb) 1
516  setPatterns { {wb g 2 Yes} {bb b 7 Yes} }
517  }
518  $f.common.m add command -label [tr PatternDarkFian] -command {
519  set pMin(wb) 1; set pMin(bb) 1
520  setPatterns { {wb b 2 Yes} {bb g 7 Yes} }
521  }
522  $f.common.m add command -label [tr PatternFourFian] -command {
523  set pMin(wb) 2; set pMin(bb) 2
524  setPatterns { {wb b 2 Yes} {wb g 2 Yes} {bb b 7 Yes} {bb g 7 Yes} }
525  }
526 
527  pack $f -side top
528  pack $f.clearPat $f.common -side left -pady 5 -padx 10
529  #if {! $smDisplayed(Patterns)} {
530  # pack forget $w.patt $w.b2
531  #}
533 
535 
536  ### Now the move counter:
537  pack [ ttk::frame $w.fmc] -side top -expand 1 -fill both
538 
539  set f $w.fmc.bishops
540  pack [ttk::frame $f] -side top ;#-expand 1 -fill both
541  ttk::label $f.t1 -text "1" -font font_Small
542  ttk::label $f.t2 -image wb20
543  ttk::label $f.t3 -text "- 1" -font font_Small -font font_Small
544  ttk::label $f.t4 -image bb20
545  ttk::label $f.t5 -textvar ::tr(squares:) -font font_Small
546  ttk::radiobutton $f.same -textvar ::tr(SameColor) -variable oppBishops -value "Same" -style Small.TRadiobutton ;# -padx 5 -pady 4
547  ttk::radiobutton $f.opp -textvar ::tr(OppColor) -variable oppBishops -value "Opposite" -style Small.TRadiobutton ;# -padx 5 -pady 4
548  ttk::radiobutton $f.either -textvar ::tr(Either) -variable oppBishops -value "Either" -style Small.TRadiobutton ;# -padx 5 -pady 4
549  foreach i {t1 t2 t3 t4 t5 same opp either} { pack $f.$i -side left}
550 
551  set f $w.fmc.move
552  pack [ttk::frame $f] -side top -ipady 5 ;# -expand 1 -fill both
553  ttk::label $f.fromlab -textvar ::tr(MoveNumberRange:) -font font_Small
554  ttk::entry $f.from -width 4 -textvar minMoveNum -justify right -font font_Small
555  ttk::label $f.tolab -text "-" -font font_Small
556  ttk::entry $f.to -width 4 -textvar maxMoveNum -justify right -font font_Small
557  ttk::label $f.space -text " "
558  ttk::label $f.label1 -textvar ::tr(MatchForAtLeast) -font font_Small
559  ttk::entry $f.hmoves -width 3 -textvar minHalfMoves -justify right -font font_Small
560  ttk::label $f.label2 -textvar ::tr(HalfMoves) -font font_Small
561  bindFocusColors $f.from
562  bindFocusColors $f.to
563  bindFocusColors $f.hmoves
564  pack $f.fromlab $f.from $f.tolab $f.to $f.space $f.label1 $f.hmoves $f.label2 -side left
565 
569 
570  ### Progress bar:
571  ttk::frame $w.fprogress
572  canvas $w.fprogress.progress -height 20 -width 300 -bg white -relief solid -border 1
573  $w.fprogress.progress create rectangle 0 0 0 0 -outline blue -fill blue -tags bar
574  $w.fprogress.progress create text 295 10 -anchor e -font font_Regular -tags time -fill black -text "0:00 / 0:00"
575 
576  ### Last of all, the buttons frame:
577 
578  set f $w.b3
579  pack [ttk::frame $f] -side top -ipady 5 -fill x
580  ttk::checkbutton $f.ignorecol -textvar ::tr(IgnoreColors) -variable ignoreColors ;# -padx 4
581 
582  dialogbutton $f.save -textvar ::tr(Save...) -command ::search::material::save
583 
584  dialogbutton $f.stop -textvar ::tr(Stop) -command progressBarCancel
585  $f.stop configure -state disabled
586 
587  dialogbutton $f.search -textvar ::tr(Search) -command {
588  busyCursor .
589  set curr_base [sc_base current]
590  sc_base switch [lindex $refDatabaseM 0]
591  .sm.b3.stop configure -state normal
592  grab .sm.b3.stop
593  progressBarSet .sm.fprogress.progress 301 21
594  set str [sc_search material \
595  -wq [list $pMin(wq) $pMax(wq)] -bq [list $pMin(bq) $pMax(bq)] \
596  -wr [list $pMin(wr) $pMax(wr)] -br [list $pMin(br) $pMax(br)] \
597  -wb [list $pMin(wb) $pMax(wb)] -bb [list $pMin(bb) $pMax(bb)] \
598  -wn [list $pMin(wn) $pMax(wn)] -bn [list $pMin(bn) $pMax(bn)] \
599  -wm [list $pMin(wm) $pMax(wm)] -bm [list $pMin(bm) $pMax(bm)] \
600  -wp [list $pMin(wp) $pMax(wp)] -bp [list $pMin(bp) $pMax(bp)] \
601  -flip $ignoreColors -filter $::search::filter::operation \
602  -range [list $minMoveNum $maxMoveNum] \
603  -length $minHalfMoves -bishops $oppBishops \
604  -diff [list $minMatDiff $maxMatDiff] \
605  -patt "$pattBool(1) $pattPiece(1) $pattFyle(1) $pattRank(1)" \
606  -patt "$pattBool(2) $pattPiece(2) $pattFyle(2) $pattRank(2)" \
607  -patt "$pattBool(3) $pattPiece(3) $pattFyle(3) $pattRank(3)" \
608  -patt "$pattBool(4) $pattPiece(4) $pattFyle(4) $pattRank(4)" \
609  -patt "$pattBool(5) $pattPiece(5) $pattFyle(5) $pattRank(5)" \
610  -patt "$pattBool(6) $pattPiece(6) $pattFyle(6) $pattRank(6)" \
611  -patt "$pattBool(7) $pattPiece(7) $pattFyle(7) $pattRank(7)" \
612  -patt "$pattBool(8) $pattPiece(8) $pattFyle(8) $pattRank(8)" \
613  -patt "$pattBool(9) $pattPiece(9) $pattFyle(9) $pattRank(9)" \
614  -patt "$pattBool(10) $pattPiece(10) $pattFyle(10) $pattRank(10)" ]
615  grab release .sm.b3.stop
616  .sm.b3.stop configure -state disabled
617  sc_base switch $curr_base
618  .sm.status configure -text $str
619  unbusyCursor .
620  ::notify::DatabaseModified [sc_base current] dbfilter
621  }
622 
623  dialogbutton $f.cancel -textvar ::tr(Close) \
624  -command { focus .; destroy .sm }
625 
626  pack $f.ignorecol $w.b3.save -side left -pady 5 -padx 5
627  pack $w.b3.cancel $w.b3.search $w.b3.stop -side right -pady 5 -padx 5
628  pack $w.fprogress.progress -side top -pady 2
629  pack $w.fprogress -expand 1 -fill both
630 
631  label $w.status -text "" -width 1 -font font_Small -relief sunken -anchor w
632  pack $w.status -side bottom -fill x
633 
634  # update
635  wm resizable $w 0 0
637  focus $f.search
638 }
639 
640 proc ::search::material::save {} {
641  global pMin pMax ignoreColors minMoveNum maxMoveNum minHalfMoves
642  global pattPiece pattFyle pattRank pattBool oppBishops nPatterns
643 
644  set ftype { { "Scid SearchOptions files" {".sso"} } }
645  set fName [tk_getSaveFile -initialdir [pwd] -filetypes $ftype -title "Create a SearchOptions file"]
646  if {$fName == ""} { return}
647 
648  if {[string compare [file extension $fName] ".sso"] != 0} {
649  append fName ".sso"
650  }
651 
652  if {[catch {set searchF [open $fName w]}]} {
653  tk_messageBox -title "Error: Unable to open file" -type ok -icon error \
654  -message "Unable to create SearchOptions file: $fName"
655  return
656  }
657  puts $searchF "\# SearchOptions File created by Scid $::scidVersion"
658  puts $searchF "set searchType Material"
659  # First write the material counts:
660  foreach i {wq bq wr br wb bb wn bn wp bp} {
661  puts $searchF "set pMin($i) $pMin($i)"
662  puts $searchF "set pMax($i) $pMax($i)"
663  }
664  # Now write other numeric values:
665  foreach i {
666  ignoreColors minMoveNum maxMoveNum minHalfMoves oppBishops
667  ::search::filter::operation
668  } {
669  puts $searchF "set $i [set $i]"
670  }
671  # Last, write the patterns:
672  for {set i 1} {$i <= $nPatterns} {incr i} {
673  puts $searchF "set pattPiece($i) $pattPiece($i)"
674  puts $searchF "set pattFyle($i) $pattFyle($i)"
675  puts $searchF "set pattRank($i) $pattRank($i)"
676  puts $searchF "set pattBool($i) $pattBool($i)"
677  }
678  tk_messageBox -type ok -icon info -title "Search Options saved" \
679  -message "Material/pattern search options saved to: $fName"
680  close $searchF
681 }
682