-
Notifications
You must be signed in to change notification settings - Fork 0
/
suit.go
53 lines (45 loc) · 1.08 KB
/
suit.go
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
package card
// Suit of a Card (one of ♣, ♦, ♥, ♠).
type Suit int
// ParseSuit string to a Suit.
func ParseSuit(suit string) (Suit, error) {
switch suit {
case "♣":
return Clubs, nil
case "♦":
return Diamonds, nil
case "♥":
return Hearts, nil
case "♠":
return Spades, nil
default:
return -1, ParseErr{"ParseSuit", suit, ErrSyntax}
}
}
// Card in the suit given its rank.
func (s Suit) Card(r Rank) Card {
return Card(int(s)*13 + int(r))
}
// Symbol representation of the suit.
func (s Suit) Symbol() rune {
return suitSymbols[s]
}
// Name of the suit (proper noun).
func (s Suit) Name() string {
return suitNames[s]
}
// String representation of the suit.
func (s Suit) String() string {
return string(s.Symbol())
}
const (
Clubs = Suit(0) // '♣' "Clubs"
Diamonds = Suit(1) // '♦' "Diamonds"
Hearts = Suit(2) // '♥' "Hearts"
Spades = Suit(3) // '♠' "Spades"
)
var (
suits = [...]Suit{Clubs, Diamonds, Hearts, Spades}
suitSymbols = [...]rune{'♣', '♦', '♥', '♠'}
suitNames = [...]string{"Clubs", "Diamonds", "Hearts", "Spades"}
)