File: practice

package info (click to toggle)
deal 3.1.9-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,576 kB
  • sloc: ansic: 5,224; cpp: 4,186; tcl: 3,125; makefile: 203; javascript: 21; sh: 10
file content (117 lines) | stat: -rw-r--r-- 2,763 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#
# Copyright (C) 1996-2001, Thomas Andrews
#
# $Id: practice 308 2009-04-06 20:38:34Z thomasoa $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# This writes hands to seperate files

set handcomment ""

rename write_deal old_write_deal

set suit(S) spades
set suit(H) hearts
set suit(D) diamonds
set suit(C) clubs

# Default output prefix to "out"
if {[catch {set output}]} {
	set output out
}

# Default hands to write - all of them
if {[catch {set hands}]} {
	set hands {south north east west}
}

# create file handles for writing
foreach hand $hands {
	set ofile($hand) [open "$output.$hand" "w"]
	stringbox box.$hand 7 80
	for {set i 0; set j 0} {$i<4} {incr i ; incr j 20} {
		box.$hand subbox box.$hand.$i 0 $j 7 20
	}
        puts $ofile($hand) "                               $hand hands"
	set practicecolumn 0
	set practicecount 1
}

proc write_hand {hand} {
	global practicecolumn
	global practicecount
	global handcomment
        global suit

	set box box.$hand.$practicecolumn
	# write number of deal at top of hand box, about midway across
	$box write 0 5 "*$practicecount*"

	set i 1
	foreach suitl {S H D C} {
		$box write $i 2 "$suitl [$hand -void --- $suit($suitl)]"
		incr i
	}
        $box write 6 0 "$handcomment"
}

proc flush_writing {} {
    global hands
    global ofile
    global practicecolumn
    if {$practicecolumn!=0} {
        foreach hand $hands {
	    puts $ofile($hand) "[box.$hand compact]"
            puts $ofile($hand) "============================================================================="
            flush $ofile($hand)
	   box.$hand clear
	}
    }
}
		

proc flush_deal {} {
       global ofile
       global hands
	flush_writing
	foreach hand $hands {
		close $ofile($hand)
	}
}

proc write_deal {} {
	global hands
	global handcomment
	global practicecolumn
	global practicecount
        global ofile

	foreach hand $hands {
		write_hand $hand
	}
	if {$practicecolumn==3} {
		flush_writing
		set practicecolumn 0
	} else {
		incr practicecolumn
	}
       

        puts "Deal: $practicecount"
	old_write_deal
	set handcomment ""
	incr practicecount
}