Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
move.tcl
Go to the documentation of this file.
1 # Copyright (C) 2009-2015 Fulvio Benini
2 #
3 # This file is part of Scid (Shane's Chess Information Database).
4 #
5 # Scid is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation.
8 #
9 # Scid is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with Scid. If not, see <http://www.gnu.org/licenses/>.
16 
17 ### move.tcl
18 ### Functions for moving within a game.
19 
20 namespace eval ::move {}
21 
22 proc ::move::drawVarArrows {} {
23  if {! $::showVarArrows || $::autoplayMode ||
24  ([info exists ::playMode] && [eval "$::playMode drawVarArrows"] == 0)} {
25  return 0
26  }
27 
28  set bDrawArrow 0
29  set varList [sc_var list UCI]
30 
31  if {$varList != ""} {
32  set move [sc_game info nextMoveUCI]
33  if {$move != ""} { set varList [linsert $varList 0 $move]}
34  foreach { move } $varList {
35  set bDrawn 0
36  set sq_start [ ::board::sq [ string range $move 0 1]]
37  set sq_end [ ::board::sq [ string range $move 2 3]]
38  foreach mark $::board::_mark(.main.board) {
39  if { [lindex $mark 0] == "arrow" } {
40  if {[lindex $mark 1] == $sq_start && [lindex $mark 2] == $sq_end} {
41  set bDrawn 1
42  break
43  }
44  }
45  }
46  if {! $bDrawn } { set bDrawArrow 1; break}
47  }
48  }
49 
50  return $bDrawArrow
51 }
52 
53 proc ::move::showVarArrows {} {
54  set move [sc_game info nextMoveUCI]
55  if {$move != ""} {
56  set sq_start [ ::board::sq [ string range $move 0 1]]
57  set sq_end [ ::board::sq [ string range $move 2 3]]
58  ::board::mark::add ".main.board" "arrow" $sq_start $sq_end "green"
59  }
60  set varList [sc_var list UCI]
61  foreach { move } $varList {
62  set sq_start [ ::board::sq [ string range $move 0 1]]
63  set sq_end [ ::board::sq [ string range $move 2 3]]
64  ::board::mark::add ".main.board" "arrow" $sq_start $sq_end "blue"
65  }
66 }
67 
68 proc ::move::Start {} {
69  if {[info exists ::playMode] && [eval "$::playMode moveStart"] == 0} {
70  return
71  }
72  sc_move start
75 }
76 
77 proc ::move::End {} {
78  if {[info exists ::playMode] && [eval "$::playMode moveEnd"] == 0} {
79  return
80  }
81  sc_move end
84 }
85 
86 proc ::move::ExitVar {} {
87  if {[sc_var level] == 0 } { return 0; }
88  if {[info exists ::playMode] && [eval "$::playMode moveExitVar"] == 0} {
89  return
90  }
91  sc_var exit;
94 }
95 
96 proc ::move::Back {{count 1}} {
97  if {[sc_pos isAt start]} { return}
98  if {[sc_pos isAt vstart]} { ::move::ExitVar; return}
99  if {[info exists ::playMode] && [eval "$::playMode moveBack"] == 0} {
100  return
101  }
102 
103  sc_move back $count
104 
105  if {[sc_pos isAt vstart]} { sc_var exit}
106 
107  if {$count == 1} {
108  updateBoard -animate
110  } else {
112  }
113 
115 }
116 
117 proc ::move::Forward {{count 1}} {
118  if {[sc_pos isAt end] || [sc_pos isAt vend]} { return}
119  if {[info exists ::playMode] && [eval "$::playMode moveForward"] == 0} {
120  return
121  }
122 
123  set bArrows [::move::drawVarArrows]
124 
125  set move [sc_game info next]
126  if {$count == 1} {
127  if {[sc_var count] != 0 && ! $::autoplayMode && $::showVarPopup} {
128  showVars
129  set bArrows $::showVarArrows
130  } else {
131  if {! $bArrows} { sc_move forward}
132  }
133 
134  # Animate and speak this move:
135  updateBoard -animate
137  } else {
138  if {! $bArrows} { sc_move forward $count}
140  }
141  if {$bArrows} { ::move::showVarArrows}
142 }
143 
144 #Follow the main line or enter a variation
145 #Return 0 for main line, 1 for 1st variation, etc...
146 proc ::move::Follow {{moveUCI}} {
147  if {$moveUCI != "null"} {
148  set moveUCI2 "[string range $moveUCI 2 3][string range $moveUCI 0 1][string range $moveUCI 4 end]"
149  } else {
150  set moveUCI2 "0000"
151  }
152  set varList [sc_var list UCI]
153  set varList [linsert $varList 0 "[sc_game info nextMoveUCI]"]
154  set i -1
155  foreach {move} $varList {
156  if { [ string compare -nocase $moveUCI $move] == 0 || \
157  [ string compare -nocase $moveUCI2 $move] == 0 } {
158  if {$i == -1} {
159  sc_move forward
160  } else {
161  sc_var moveInto $i
162  }
163  return 1
164  }
165  incr i
166  }
167  return 0
168 }
169 
170 proc ::move::PGNOffset { location } {
171  sc_move pgn $location
174 }