-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuzzlePiece.cpp
108 lines (88 loc) · 2.46 KB
/
PuzzlePiece.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
//
// Created by okleinfeld on 11/15/17.
//
#include "PuzzlePiece.h"
PuzzlePiece::PuzzlePiece(int ISD, int l, int t, int r, int b) :
ISD(ISD), leftEdge(l), topEdge(t), rightEdge(r), bottomEdge(b), rotateAngle(0), used(false) {}
PuzzlePiece::PuzzlePiece(const PuzzlePiece& otherPiece){
this->ISD = otherPiece.ISD;
this->leftEdge = otherPiece.leftEdge;
this->topEdge = otherPiece.topEdge;
this->rightEdge = otherPiece.rightEdge;
this->bottomEdge = otherPiece.bottomEdge;
this->rotateAngle = otherPiece.rotateAngle;
this->used = otherPiece.used;
}
int PuzzlePiece::getISD() const {
return this->ISD;
}
int PuzzlePiece::getLeftEdge() const {
return this->leftEdge;
}
int PuzzlePiece::getTopEdge() const {
return this->topEdge;
}
int PuzzlePiece::getRightEdge() const {
return this->rightEdge;
}
int PuzzlePiece::getBottomEdge() const {
return this->bottomEdge;
}
int PuzzlePiece::getAngle() const {
return this->rotateAngle;
}
bool PuzzlePiece::isUsed() const {
return used;
}
void PuzzlePiece::setUsed(bool newUsedStatus) {
used = newUsedStatus;
}
void PuzzlePiece::print(std::ostream &os) const{
os << this->ISD << " " << this->leftEdge << " " << this->topEdge << " " << this->rightEdge << " " << this->bottomEdge;
}
bool PuzzlePiece::lessThan(const PuzzlePiece& p) const{
return this->getISD() < p.getISD();
}
bool PuzzlePiece::isTopLeftCorner(){
return leftEdge == 0 && topEdge == 0;
}
bool PuzzlePiece::isTopRightCorner() {
return rightEdge == 0 && topEdge == 0;
}
bool PuzzlePiece::isBotLeftCorner() {
return leftEdge == 0 && bottomEdge == 0;
}
bool PuzzlePiece::isBotRightCorner(){
return rightEdge == 0 && bottomEdge == 0;
}
int PuzzlePiece::countStraightEdges(){
return (leftEdge == 0) + (topEdge == 0) + (rightEdge == 0) + (bottomEdge == 0);
}
int PuzzlePiece::edgesSum(){
return leftEdge + rightEdge + topEdge + bottomEdge;
}
void PuzzlePiece::rotate(){
// switch edges place
int temp = topEdge;
topEdge = leftEdge;
leftEdge = bottomEdge;
bottomEdge = rightEdge;
rightEdge = temp;
// update the current angle
if(rotateAngle == 270){
rotateAngle = 0;
}
else{
rotateAngle+= 90;
}
}
void PuzzlePiece::resetAngle(){
while(this->rotateAngle != 0)
rotate();
}
void operator<<(std::ostream &os, const PuzzlePiece& p){
p.print(os);
}
bool operator < (const PuzzlePiece& p1, const PuzzlePiece& p2){
return p1.lessThan(p2);
}