forked from itsJonnyJyo/Chicken-Feet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand.cpp
More file actions
102 lines (91 loc) · 1.74 KB
/
hand.cpp
File metadata and controls
102 lines (91 loc) · 1.74 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
#include <iostream>
#include <vector>
#include "hand.h"
using namespace std;
//constructor/destructor
Hand::Hand() : handScore(0){}
Hand::~Hand()
{
for (auto it = hand.begin(); it != hand.end(); it++)
{
delete *it;
}
}
//mutator functions
void Hand::addBone(Bone* aBone)
{
hand.push_back(aBone);
int top = aBone->getTop();
int bottom = aBone->getBottom();
handScore += top + bottom;
}
int Hand::getTop(unsigned int pos, Bone*& aBone){
if(pos < 0 || pos >= hand.size())
return false;
aBone = hand.at(pos);
return aBone->getTop();
}
int Hand::getBottom(unsigned int pos, Bone*& aBone){
if(pos < 0 || pos >= hand.size())
return false;
aBone = hand.at(pos);
return aBone->getBottom();
}
int Hand::size() const
{
return hand.size();
}
bool Hand::removeBone(unsigned int pos, Bone*& aBone)
{
if (pos < 0 || pos >= hand.size())
return false;
aBone = hand.at(pos);
hand.erase(hand.begin() + pos);
int top = aBone->getTop();
int bottom = aBone->getBottom();
handScore -= top + bottom;
return true;
}
bool Hand::highestDouble(int& pos, Bone*& aBone)
{
int highest = -1, highestPos = 0;
pos = 0;
for (auto it = hand.begin(); it != hand.end(); it++)
{
if ((*it)->getTop() == (*it)->getBottom())
{
if ((*it)->getTop() > highest)
{
highest = (*it)->getTop();
aBone = (*it);
pos = highestPos;
}
}
highestPos++;
}
if(highest > -1)
return true;
else
return false;
}
//accessor function
int Hand::getHandScore() const
{
return handScore;
}
void Hand::print() const
{
int dominoNumber = 1;
for (auto it = hand.cbegin(); it != hand.cend(); it++)
{
cout << dominoNumber << " - ";
(*it)->print();
cout << endl;
dominoNumber++;
}
}
void Hand::printBone() const
{
auto it = hand.rbegin();
(*it)->print();
}