-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAlgorithm.cpp
50 lines (43 loc) · 1.39 KB
/
TestAlgorithm.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
#include <stdexcept>
#include <iostream>
#include "TestAlgorithm.h"
#include "GameException.h"
TestAlgorithm::TestAlgorithm() :
Algorithm() { }
const Coords TestAlgorithm::calculateRedMove() const {
const Coords& redMove = getFirstEmpty();
std::cerr << "Red move: " << redMove << std::endl;
return redMove;
}
const Coords TestAlgorithm::calculateBlueMove() const {
const Coords& blueMove = getFirstEmpty();
std::cerr << "Blue move: " << blueMove << std::endl;
return blueMove;
}
const Coords TestAlgorithm::calculateGreyMove() const {
const Coords& greyMove = getFirstEmpty();
std::cerr << "Grey move: " << greyMove << std::endl;
return greyMove;
}
SlideDirection TestAlgorithm::calculateSlide() const {
for(SlideDirection dir : {SD_UP, SD_DOWN, SD_LEFT, SD_RIGHT}) {
if(gameBoardPtr->isSlideValid(dir)) {
std::cerr << "Slide direction: " << dir << std::endl;
return dir;
}
}
throw GameException("No valid slide possible");
}
const Coords TestAlgorithm::getFirstEmpty() const {
for (coord row = 0; row < 4; ++row) {
for (coord column = 0; column < 4; ++column) {
if (gameBoardPtr->getPiece(row, column).empty()) {
return Coords(row, column);
}
}
}
throw GameException("No first empty found");
}
void TestAlgorithm::ensureValidState() {
// nothing
}