-
Notifications
You must be signed in to change notification settings - Fork 0
/
linethreat.h
151 lines (118 loc) · 5.46 KB
/
linethreat.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
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
/************************************************************************
* This file is part of IntelliCon. *
* *
* IntelliCon is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* IntelliCon is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with IntelliCon. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************/
#ifndef LINETHREAD_H
#define LINETHREAD_H
#include <vector>
#include <list>
class ThreatSolution;
class PieceCoords
{
public:
PieceCoords(const int& c = 0, const int& r = 0);
int col;
int row;
bool isValid() const;
bool operator==(const PieceCoords& other) const;
bool operator!=(const PieceCoords& other) const;
};
class LineThreat
{
public:
enum Direction
{ Vertical, Horizontal, DiagonalRight, DiagonalLeft };
/* Directions are as follows:
* Vertical: vertically down
* Horizontal: horizontally to the right
* DiagonalRight: diagonally down to the right
* DiagonalLeft: diagonally down to the left */
LineThreat(const int& startCol, const int& startRow, const Direction& dir, const int& threatLevel);
LineThreat(const PieceCoords& startCoords, const Direction& dir, const int& threatLevel);
Direction dir;
bool operator==(const LineThreat& other) const;
PieceCoords operator[](const unsigned int& n) const;
PieceCoords at(const unsigned int& n) const;
const PieceCoords& startCoords() const;
bool coversCoords(const int& col, const int& row);
bool coversCol(const int& col);
int mostLeftCol() const;
int mostRightCol() const;
int level() const;
void setLevel(const int& newThreatLevel);
std::list<ThreatSolution*> solutions;
bool solved; // Whether this threat is solved or not
bool solvedTemp; // Temporarily marks this threat as solved
private:
PieceCoords start;
int threatLevel;
};
class ThreatSolution
{
public:
enum Type
{
ClaimEven = 0,
BaseInverse = 1,
Vertical = 2,
AfterEven = 3,
LowInverse = 4,
HighInverse = 5,
BaseClaim = 6,
Before = 7,
SpecialBefore = 8,
AfterBaseInverse= 9,
AfterVertical = 10
};
ThreatSolution(const Type& type);
Type type;
std::vector<LineThreat*> solvedThreats;
std::vector<ThreatSolution*> cantCombine;
virtual bool operator==(const ThreatSolution& other) const;
// The squares are sorted by column first and then by row, in ascending order
const PieceCoords& operator[](const unsigned int& n) const;
const PieceCoords& at(const unsigned int& n) const;
unsigned int squareCount() const;
void addSquare(const PieceCoords& square);
void addSquare(const int& col, const int& row);
// Returns true if this solution will win the game
bool winsGame() const;
// Make this solution a game winner
void makeGameWinner();
// Whether the set of squares used by this solution interferes with the set of squares of the other solution
bool interferes(const ThreatSolution* other) const;
// Check per column whether the squares used by this solution interfere with the set of squares used by the other solution
// The squares in a column are not said to interfere if exaclty the same squares are used by both solutions in that column
bool interferesColumnWise(const ThreatSolution* other) const;
bool dontUse;
protected:
std::vector<PieceCoords> squares;
bool win;
};
class ThreatSolutionBefore : public ThreatSolution
{
public:
ThreatSolutionBefore(const Type& type);
bool operator==(const ThreatSolution& other) const;
void useClaimEvenIn(const int& col);
bool claimEvenUsedInCol(const int& col) const;
int lowestUsedSquareInCol(const int& col) const;
void addSpecialSquareColumn(const int& col);
bool isSpecialSquareColumn(const int& col) const;
private:
std::vector<bool> claimEvenUsed; // In which columns a ClaimEven is used
std::vector<bool> specialSquareCols; // In which columns special squares are used, and therefore in these columns the set of squares must be disjoint
};
#endif // LINETHREAD_H