-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPuzzlePiecesMapWithRotate.cpp
More file actions
43 lines (37 loc) · 1.28 KB
/
PuzzlePiecesMapWithRotate.cpp
File metadata and controls
43 lines (37 loc) · 1.28 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
//
// Created by okleinfeld on 12/13/17.
//
#include "PuzzlePiecesMapWithRotate.h"
PuzzlePiecesMapWithRotate::PuzzlePiecesMapWithRotate(vector<PuzzlePiece>& pieces){
toBuckets(pieces);
}
void PuzzlePiecesMapWithRotate::toBuckets(vector<PuzzlePiece>& pieces){
for(auto& p : pieces){
PuzzleTypeWithRotation type = PuzzleTypeWithRotation(p.getLeftEdge(),p.getTopEdge(),p.getRightEdge(), p.getBottomEdge());
typesMap[type].push_back(p);
}
}
PuzzlePiece* PuzzlePiecesMapWithRotate::nextPiece(PuzzleRequirement& req){
int rotations;
for (auto& typeVectorPair : typesMap){
rotations = 0;
PuzzleTypeWithRotation puzzleType = typeVectorPair.first;
do{
if(req.typeSatisfiesReq(puzzleType)){
for(auto& puzzlePiece : typeVectorPair.second){
if(!puzzlePiece.isUsed()){
for(int j = 0; j < rotations; j++){
puzzlePiece.rotate();
}
puzzlePiece.setUsed(true);
return &puzzlePiece;
}
}
}
puzzleType.rotate();
rotations++;
} while (rotations < 4);
puzzleType.resetRotation();
}
return nullptr;
}