-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.cpp
More file actions
49 lines (42 loc) · 767 Bytes
/
deck.cpp
File metadata and controls
49 lines (42 loc) · 767 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <cstdlib>
#include "deck.h"
using namespace std;
Deck::Deck()
{
char suits[] = {'C','D','H','S'};
for(int i=0;i < 52; i++){
_cards[i] = Card(suits[i/13], i%13);
}
_topIndex = 0;
}
void Deck::shuffle()
{
for(int i=51; i > 0; i--){
int r = rand() % (i+1);
Card temp = _cards[i];
_cards[i] = _cards[r];
_cards[r] = temp;
}
}
void Deck::cut()
{
for(int i = 0; i < 26; i++){
Card temp = _cards[i];
_cards[i] = _cards[i+26];
_cards[i+26] = temp;
}
}
Card Deck::getTop()
{
Card retval = _cards[_topIndex];
_topIndex = ((_topIndex+1) % 52);
return retval;
}
void Deck::printDeck()
{
for(int i=_topIndex; i < 52; i++){
cout << _cards[i].toString() << " " ;
}
cout << endl;
}