-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack.go
More file actions
35 lines (30 loc) · 755 Bytes
/
Stack.go
File metadata and controls
35 lines (30 loc) · 755 Bytes
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
package main
// Stack - the discard pile in Gin Rummy.
type Stack []Card
// InitializeStack - puts the top card of the deck onto the stack.
func (d *Deck) InitializeStack() (stack Stack) {
card := (*d)[len(*d)-1]
*d = (*d)[:len(*d)-1]
stack = append(stack, card)
return
}
// DrawCard - picks up the top card of the stack.
func (s *Stack) DrawCard() (card Card) {
card = (*s)[len(*s)-1]
*s = (*s)[:len(*s)-1]
return
}
// PeekAtStack - reveals the top card on the stack.
func (s *Stack) PeekAtStack() (card string) {
if len(*s) == 0 {
return "No cards in the stack."
}
return (*s)[len(*s)-1].PrettyPrintCard()
}
// IsEmpty - checks if the stack is empty.
func (s *Stack) IsEmpty() bool {
if len(*s) == 0 {
return true
}
return false
}