-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFireAI.cpp
More file actions
196 lines (164 loc) · 5.67 KB
/
FireAI.cpp
File metadata and controls
196 lines (164 loc) · 5.67 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// Created by Ricky Marly & Jouse on 11/18/20.
//
#include "FireAI.h"
#include <iostream>
using namespace std;
Card c;
int cw = 0;
FireAI::FireAI(int playerNumber):
AI(playerNumber)
{
}
void FireAI::onOtherPlayerMove(int playerNumber, Card justPlayed, Color choosenCardColor)
{
}
void FireAI::onOtherPlayerDraw(int playerNumber)
{
playerNumber = c.getNumber();
}
bool sortingCardByNumber(Card i, Card j)
{
return i.getNumber() > j.getNumber();
}
int FireAI::makeMove(Card justPlayed, Color choosenCardColor, bool justDrew, vector<int> scores, vector<int> cardAmountsByPlayer, vector<Card> cardsInHand, int direction)
{
//my playable cards vec
vector<Card> cards = getPlayableCardsInHand(justPlayed, choosenCardColor, cardsInHand);
if (cards.size() == 0)
{
return -1; //draw & safety code
}
//vector to hold sorted cards, since random isn't how the real UNO game is played(Uno King RM)
vector<Card> cardsSortedByNumberToUse;
//unsorted card stored into new Vec for sorting, don't want to mess with OG vec(cards)
cardsSortedByNumberToUse.reserve(cards.size());
for (auto card : cards)
{
cardsSortedByNumberToUse.push_back(card);
}
//new vector gets sorted by card int rather than random
//utilizing the bool function
//**********VERY IMPORTANT TO SORT************
//Results(100K G): UNSORTED = 30.53362 FireAI_Gang -> SORTED = 23.855
sort(cardsSortedByNumberToUse.begin(), cardsSortedByNumberToUse.end(), sortingCardByNumber);
//cards will be stored by color together,
//rather than randomly
vector<int> colorCounterOfWildCards;
//color counter initialized
//colors will be counter and stored to ref later
int yellowColorQt = 0, blueColorQt = 0, greenColorQt = 0,redColorQt = 0, blackColorQt = 0;
//goes thru hand of cards and count them,
//base on the count the,
// values(yellowColorQt = 0, blueColorQt = 0, greenColorQt = 0,redColorQt = 0),
//increase for storage
//RED = 0, BLUE, GREEN, YELLOW, BLACK
int x = 0;
for(auto & i : cardsInHand)
{
if (i.getColor() == RED)
{
redColorQt++;// x red
}
else if (i.getColor() == GREEN)
{
greenColorQt++;
}
else if (i.getColor() == YELLOW)
{
yellowColorQt++;
}
else if (i.getColor() == BLUE)
{
blueColorQt++;
}
else if (i.getColor() == BLACK)
{
blackColorQt++;
}
}
//colors are in the colorCounterOfWildCards vector
colorCounterOfWildCards.push_back(redColorQt); //index 0
colorCounterOfWildCards.push_back(greenColorQt); //index 1
colorCounterOfWildCards.push_back(yellowColorQt); //index 2
colorCounterOfWildCards.push_back(blueColorQt); //index 3
colorCounterOfWildCards.push_back(blackColorQt); //index 4
//vector for both wild & draw4 -> colorCounterOfWildCards sorted
//sort(colorCounterOfWildCards.begin(), colorCounterOfWildCards.end());
//100 -> 99
for(int i = 0; i < colorCounterOfWildCards.size();i++)//losses card & keeps playing its own
{
//picks the saved color based on the color with the greatest quantity of cards
if (colorCounterOfWildCards[i] == redColorQt /*|| redColorQt == blackColorQt*/ )
{
//savedColor = BLUE;
savedColor = RED;
}
else if (colorCounterOfWildCards[i] == blueColorQt /*|| blueColorQt == blackColorQt*/ )
{
//savedColor = RED;
savedColor = BLUE;
}
else if (colorCounterOfWildCards[i] == yellowColorQt /*|| yellowColorQt == blackColorQt*/)
{
//savedColor = GREEN;
savedColor = YELLOW;
}
else if (colorCounterOfWildCards[i] == greenColorQt /*|| greenColorQt == blackColorQt*/)
{
//savedColor = YELLOW;
savedColor = GREEN;
}
else
{
//if(colorCounterOfWildCards[i] == blackColorQt)
if(colorCounterOfWildCards[i] == blackColorQt)
{
int k = i;
if((colorCounterOfWildCards[k-1] == yellowColorQt) || (colorCounterOfWildCards[k+1] == yellowColorQt))
{
savedColor = YELLOW;
//check the color i have
//see what card is on the top
//decide the best card to play
}
else if((colorCounterOfWildCards[k-1] == greenColorQt) || (colorCounterOfWildCards[k+1] == greenColorQt))
{
savedColor = YELLOW;
}
else if((colorCounterOfWildCards[k-1] == blueColorQt) || (colorCounterOfWildCards[k+1] == blueColorQt))
{
savedColor = YELLOW;
}
else if( (colorCounterOfWildCards[k-1] == redColorQt) || (colorCounterOfWildCards[k+1] == redColorQt))
{
savedColor = YELLOW;
}
}
}
}
//initializes our card that we will find in our actual hand
c = cardsSortedByNumberToUse[0];
//c = cards[rand() % cards.size()];
//loops through hand until card is found and returns it's index
for (int i = 0; i < cardsInHand.size(); i++)
{
if (c == cardsInHand[i])
{
return i;
}
}
}
//the name of the AI is defined here
string FireAI::getName()
{
string d = to_string(cw);
string first_name = "FireAI_Gang";
string together = first_name+d;
return together;
}
//saved first play saved here
Color FireAI::getNewColor()
{
return savedColor;
}