File: Card.itcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (102 lines) | stat: -rw-r--r-- 1,897 bytes parent folder | download | duplicates (4)
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
# Card.itcl --
# 
#       Each card is encoded using two characters, the first one its range,
#       and the second one its suit code, see below.
# 
#       range: 
#           2-9, ordinary numbers, 0 means 10, j (jack) q (queen), k (king), 
#           a (ace)
#       suits: 
#           diamond (d), heart (h), spade (s), and club (c).
#           
# $Id: Card.itcl,v 1.1 2004-07-23 10:15:37 matben Exp $

class Card {

    # ---------------------------------
    # Class constructor and destructor.
    # ---------------------------------

    public {
	constructor {args} {}
	destructor {}
    }

    # ---------------
    # Static methods.
    # ---------------

    public proc Suit {rang}
    public proc SuitRang {suit}
    public proc Value {card}
}

body Card::constructor {} {
    puts $this
}

# Card::Suit --
#
#	Returns the suit character code.
#
# Arguments:
#	rang        integer 0-3 enumerating the suits
#
# Results:
#       the suit character code

body Card::Suit {rang} {
    switch -- $rang {
	0 {set suitChar d}
	1 {set suitChar h}
	2 {set suitChar s}
	3 {set suitChar c}
    }
}

# Card::SuitRang --
#
#	Returns the suit rang as an integer 0-3.
#
# Arguments:
#	suit        the suit character code
#
# Results:
#       enumeration from 0-3 corresponding to suit character code

body Card::SuitRang {suit} {
    switch -glob -- $suit {
	*d* {set suitNum 0}
	*h* {set suitNum 1}
	*s* {set suitNum 2}
	*c* {set suitNum 3}
    }
}

# Card::Value --
#
#	Returns the cards value as an integer 1-13.
#
# Arguments:
#	card        the card code as a two character code
#
# Results:
#       the numerical value of the card

body Card::Value {card} {
    switch [string index $card 0] {
	a {return 1}
	2 {return 2}
	3 {return 3}
	4 {return 4}
	5 {return 5}
	6 {return 6}
	7 {return 7}
	8 {return 8}
	9 {return 9}
	0 {return 10}
	j {return 11}
	q {return 12}
	k {return 13}
    }
}