-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnections.h
109 lines (98 loc) · 2.43 KB
/
connections.h
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
#ifndef CONNECTIONS_H
#define CONNECTIONS_H
// File most include
#include <QVector>
/**
* @brief A class to store the infomation of connections.
* It also contains some functions to know the infomation about each ball.
*/
class Connections
{
public:
/**
* @brief Constructor with the number of the balls.
*/
Connections(int theBallCount) :
ballCount(theBallCount),
connectionsOfIndex(
new QVector<QVector<int> *>[ballCount])
{
for (int i = 0;i < ballCount;++i)
connectionsOfIndex[i].fill(NULL, 10);
}
/**
* @brief Constructor with another Connection.
*/
Connections(const Connections& another) :
ballCount(another.ballCount),
connectionsOfIndex(
new QVector<QVector<int> *>[ballCount])
{
// Copy the information
for (int i = 0;i < another.connections.size();++i)
connections.push_back(
new QVector<int>(*another.connections.at(i)));
for (int i = 0;i < ballCount;++i)
{
connectionsOfIndex[i].reserve(
another.connectionsOfIndex[i].size());
for (int j = 0;
j < another.connectionsOfIndex[i].size();
++j)
{
if (another.connectionsOfIndex[i].at(j))
connectionsOfIndex[i].push_back(
new QVector<int>(
*another.connectionsOfIndex[i].at(j)));
else
connectionsOfIndex[i].push_back(NULL);
}
}
}
/**
* @brief Destructor.
*/
~Connections()
{
for (int i = 0;i < connections.size();++i)
delete connections[i];
delete [] connectionsOfIndex;
}
/**
* @brief Whether a ball is in a chain.
*
* @param index The index of the ball to check.
*/
bool isInAChain(int index)
{
for (int i = 0;i < 10;++i)
if (i != 3 && connectionsOfIndex[index][i])
return true;
return false;
}
/**
* @brief Whether a ball is the center of a chain.
*
* @param index The index of the ball to check.
*/
bool isCenterOfAChain(int index)
{
return connectionsOfIndex[index][3];
}
/**
* @brief Number of the balls.
*/
int ballCount;
/**
* @brief Connections of the balls with the index.
*
* Three directions, center of a circle, six position on the circle.
* Ten pointers of QVector<int> in all.
*/
QVector<QVector<int> *> *connectionsOfIndex;
/**
* @brief All of the connections.
*/
QVector<QVector<int> *> connections;
};
#endif // CONNECTIONS_H