|
@@ -8,8 +8,13 @@ std::array<Vector, 8> Game::neighbours;
|
|
|
std::array<Vector, 9 * 5> Game::fieldVectors;
|
|
|
|
|
|
Game::Game() : active(-1, -1), mustTake(false) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
std::cout << "0\n1\n0\n";
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
neighbours[0].set(1, 0);
|
|
|
neighbours[1].set(0, 1);
|
|
|
neighbours[2].set(-1, 0);
|
|
@@ -19,6 +24,7 @@ Game::Game() : active(-1, -1), mustTake(false) {
|
|
|
neighbours[6].set(1, -1);
|
|
|
neighbours[7].set(-1, -1);
|
|
|
|
|
|
+
|
|
|
uint index = 0;
|
|
|
for(uint y = 0; y < 5; y++) {
|
|
|
for(uint x = 0; x < 9; x++) {
|
|
@@ -30,19 +36,24 @@ Game::Game() : active(-1, -1), mustTake(false) {
|
|
|
void Game::readLine() {
|
|
|
String line;
|
|
|
while(true) {
|
|
|
+
|
|
|
char c = std::cin.get();
|
|
|
if(c == '\n') {
|
|
|
+
|
|
|
if(parseLine(line)) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
line.clear();
|
|
|
} else if(c != '\r') {
|
|
|
+
|
|
|
line.append(c);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool Game::parseLine(const String& line) {
|
|
|
+
|
|
|
if(line == " 0 1 2 3 4 5 6 7 8") {
|
|
|
fields.read();
|
|
|
fields.print(active);
|
|
@@ -53,9 +64,11 @@ bool Game::parseLine(const String& line) {
|
|
|
} else if(line == "Please enter wether you want to Withdraw or Approach [W/A]") {
|
|
|
takeStone();
|
|
|
} else if(line == "Do you want to continue with your turn [Y/N]?") {
|
|
|
+
|
|
|
std::cout << "Y\n";
|
|
|
} else if(line == "************************Player 1 won!**********************" ||
|
|
|
line == "************************Player 2 won!**********************") {
|
|
|
+
|
|
|
std::cerr << line << "\n";
|
|
|
return true;
|
|
|
}
|
|
@@ -67,10 +80,12 @@ bool Game::isInRange(const Vector& v) const {
|
|
|
}
|
|
|
|
|
|
bool Game::areNeighbors(const Vector& from, const Vector& to) const {
|
|
|
+
|
|
|
if(from == to) {
|
|
|
return false;
|
|
|
}
|
|
|
Vector diff = from - to;
|
|
|
+
|
|
|
if(diff.x < -1 || diff.x > 1 || diff.y < -1 || diff.y > 1) {
|
|
|
return false;
|
|
|
}
|
|
@@ -83,11 +98,14 @@ bool Game::areNeighbors(const Vector& from, const Vector& to) const {
|
|
|
}
|
|
|
|
|
|
uint Game::removeLine(const Vector& from, const Vector& to, Fields::State state) {
|
|
|
+
|
|
|
Vector current = to;
|
|
|
Vector unit = to - from;
|
|
|
+
|
|
|
uint rank = 0;
|
|
|
while(true) {
|
|
|
current += unit;
|
|
|
+
|
|
|
if(!isInRange(current) || !fields.hasState(current, state)) {
|
|
|
return rank;
|
|
|
}
|
|
@@ -97,6 +115,7 @@ uint Game::removeLine(const Vector& from, const Vector& to, Fields::State state)
|
|
|
}
|
|
|
|
|
|
uint Game::getRank(const Vector& from, const Vector& to, Fields::State state) const {
|
|
|
+
|
|
|
Vector current = to;
|
|
|
Vector unit = to - from;
|
|
|
uint rank = 0;
|