This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcounter.cpp
120 lines (100 loc) · 3.66 KB
/
counter.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
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
#pragma once
#include "card.h"
#include "iplayer.h"
#include "counter.h"
void Counter<global::players>::moveout(std::vector<iCard*>& set, iCard*& target) {
std::vector<iCard*>::iterator iter = std::find(set.begin(), set.end(), target);
if (iter == set.end()) return;
set.erase(iter);
}
Counter<global::players>::Counter(
CardManager& manager, iCard* trump) {
this->_desk.clear();
this->_unknown = manager.getall();
this->manager = &manager;
for (int index = 0; index < global::players; index++) {
this->players[index] = nullptr;
this->count[index] = 0;
this->inhand[index] = std::vector<iCard*>();
}
// Moveout trump
this->moveout(this->_unknown, trump);
}
Counter<global::players>::Counter(const Counter<global::players>& counter) {
this->_desk = counter._desk;
this->_unknown = counter._unknown;;
this->players = counter.players;
this->count = counter.count;
this->inhand = counter.inhand;
}
int Counter<global::players>::join(iPlayer* player) {
int index = 0;
for (; index < global::players; index++)
if (this->players[index] == nullptr) {
this->players[index] = player;
return index;
}
return index;
}
iPlayer* Counter<global::players>::player(int index) const {
if (index > int(this->players.max_size()) - 1)
return nullptr;
return this->players[index];
}
iPlayer* Counter<global::players>::player(std::string name) const {
for (iPlayer* player : this->players)
if (player->name() == name)
return player;
return nullptr;
}
void Counter<global::players>::grab(iPlayer* player) {
int index = player->index();
std::vector<iCard*>& inhand = this->inhand[index];
std::vector<iCard*>& desk = this->_desk;
this->count[index] += desk.size();
for (auto& card : desk) inhand.push_back(card);
desk.clear();
}
void Counter<global::players>::replenish(iPlayer* player, int count){
int index = player->index();
int current = this->count[index];
if (count > current)
this->count[index] = count;
}
void Counter<global::players>::get(iPlayer* player, iCard* card) {
int index = player->index();
std::vector<iCard*>& inhand = this->inhand[index];
this->count[index] += 1;
inhand.push_back(card);
this->moveout(this->_unknown, card);
}
void Counter<global::players>::hit(iPlayer* player, iCard* card) {
int index = player->index();
std::vector<iCard*>& inhand = this->inhand[index];
this->moveout(inhand, card); // for us
this->moveout(this->_unknown, card); // for enemy
this->count[index] -= 1;
this->_desk.push_back(card);
}
void Counter<global::players>::get(iPlayer* player, std::string& rank, std::string& suit) {
int index = player->index();
iCard* card = this->manager->get(rank, suit);
std::vector<iCard*>& inhand = this->inhand[index];
this->count[index] += 1;
inhand.push_back(card);
this->moveout(this->_unknown, card);
}
void Counter<global::players>::hit(iPlayer* player, std::string& rank, std::string& suit) {
int index = player->index();
iCard* card = this->manager->get(rank, suit);
std::vector<iCard*>& inhand = this->inhand[index];
this->moveout(inhand, card); // for us
this->moveout(this->_unknown, card); // for enemy
this->count[index] -= 1;
this->_desk.push_back(card);
}
std::vector<iCard*>& Counter<global::players>::desk(void) { return this->_desk; }
std::vector<iCard*>& Counter<global::players>::unknown(void) { return this->_unknown; }
void Counter<global::players>::clear(void) { this->_desk.clear(); }
std::vector<iCard*>& Counter<global::players>::hand(iPlayer* player) { return this->inhand[player->index()]; }
int Counter<global::players>::left(iPlayer* player) { return this->count[player->index()]; }