-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI.cpp
More file actions
47 lines (44 loc) · 1.41 KB
/
AI.cpp
File metadata and controls
47 lines (44 loc) · 1.41 KB
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
#include "AI.h"
AI::AI(int num)
{
myPlayerNumber = num;
}
vector<Card> AI::getPlayableCardsInHand(Card justPlayed, Color choosenCardColor, vector<Card> cardsInHand)
{
vector<Card> cardsCanPlay;
for (int i = 0; i < cardsInHand.size(); i++)
{
if (choosenCardColor == cardsInHand[i].getColor())
{
//cout << "A"<< cardsCanPlay.size() << choosenCardColor << endl;
cardsCanPlay.push_back(cardsInHand[i]); //same color
}
else if (cardsInHand[i].getColor() != BLACK && justPlayed.getNumber() == cardsInHand[i].getNumber() && justPlayed.getColor() != BLACK)
{
//cout << "B" << cardsCanPlay.size() << choosenCardColor<< endl;
cardsCanPlay.push_back(cardsInHand[i]); //same number
}
else if (cardsInHand[i].getColor() == BLACK && cardsInHand[i].getNumber() == 0)
{
//cout << "C" << cardsCanPlay.size() << choosenCardColor<< endl;
cardsCanPlay.push_back(cardsInHand[i]); //wild
}
else if (cardsInHand[i].getColor() == BLACK && cardsInHand[i].getNumber() == 1) //draw four
{
//cout << "D" << cardsCanPlay.size() << choosenCardColor<< endl;
bool hasColor = false;
for (int j = 0; j < cardsInHand.size(); j++)
{
if (choosenCardColor == cardsInHand[j].getColor())
{
hasColor = true;
}
}
if (!hasColor) //can only play draw4 if doesn't have color.
{
cardsCanPlay.push_back(cardsInHand[i]);
}
}
}
return cardsCanPlay;
}