-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJigsawSolutionExistsRotationsAllowed.cpp
More file actions
53 lines (41 loc) · 1.54 KB
/
JigsawSolutionExistsRotationsAllowed.cpp
File metadata and controls
53 lines (41 loc) · 1.54 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
//
// Created by okleinfeld on 12/13/17.
//
#include "JigsawSolutionExistsRotationsAllowed.h"
JigsawSolutionExistsRotationsAllowed::JigsawSolutionExistsRotationsAllowed(vector<PuzzlePiece>& puzzlePieces):
JigsawSolutionExistsChecks(puzzlePieces){;}
bool JigsawSolutionExistsRotationsAllowed::checkIfPuzzleIsLegal(){
bool isLegal = true;
//check the edges
if(!hasEnoughEdges()){
this->errorMessages.emplace_back(WRONG_NUM_EDGES);
isLegal = false;
}
//check the corners
bool TLC = false, TRC= false, BRC= false, BLC = false, allcorners = false;
for(int i = 0; i<4; i++){
for(auto& p: this->puzzlePieces){
if(!TLC) {TLC = p.isTopLeftCorner();}
if(!TRC) {TRC = p.isTopRightCorner();}
if(!BRC) {BRC = p.isBotRightCorner();}
if(!BLC) {BLC = p.isBotLeftCorner();}
p.rotate();
}
}
for(auto p : this->puzzlePieces)
p.resetAngle();
allcorners = TLC && TRC && BRC && BLC;
if(!allcorners){
isLegal = false;
if(!TLC){this->errorMessages.emplace_back(NO_CORNER_TL);}
if(!TRC){this->errorMessages.emplace_back(NO_CORNER_TR);}
if(!BLC){this->errorMessages.emplace_back(NO_CORNER_BL);}
if(!BRC){this->errorMessages.emplace_back(NO_CORNER_BR);}
}
//check the sum
if(!isSumEdgesZero()){
this->errorMessages.emplace_back(SUM_TOTAL_EDGES_WRONG);
isLegal = false;
}
return isLegal;
}