forked from Mordequess/CS247_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayed.cpp
51 lines (42 loc) · 1.23 KB
/
Played.cpp
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
#include "Played.h"
#include <iostream>
#include "Card.h"
Played::Played() {
//resetBoard();
}
bool Played::isLegal(Card card) {
//7, A, K
if (card.getRank() == 7) return true;
if (card.getRank() == 0) return playedCards[card.getSuit()][1];
if (card.getRank() == 12) return playedCards[card.getSuit()][11];
return playedCards[card.getSuit()][card.getRank()-1] || playedCards[card.getSuit()][card.getRank()+1];
}
void Played::setCard(Card card) {
playedCards[card.getSuit()][card.getRank()] = true;
}
void Played::resetBoard(){
for (int i = 0; i < 13; i++) {
for (int j = 0; j < 4; j++) {
playedCards[j][i] = false;
}
}
}
std::ostream &operator<<(std::ostream &out, Played &p){
out << "Cards on the table:" << std::endl << "Clubs:";
for (int i = 0; i < 13; i++) {
if (p.playedCards[0][i]) out << " " << static_cast<Rank>(i);
}
out << std::endl << "Diamonds:";
for (int i = 0; i < 13; i++){
if (p.playedCards[1][i]) out << " " << static_cast<Rank>(i);
}
out << std::endl << "Hearts:";
for (int i = 0; i < 13; i++) {
if (p.playedCards[2][i]) out << " " << static_cast<Rank>(i);
}
out << std::endl << "Spades:";
for (int i = 0; i < 13; i++) {
if (p.playedCards[3][i]) out << " " << static_cast<Rank>(i);
}
return out;
}