|
|
|
@ -28,3 +28,26 @@ SameGame::SameGame(int rows, int columns)
|
|
|
|
|
QString SameGame::getCell(int row, int column) {
|
|
|
|
|
return gameMatrix[row][column];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SameGame::getConnected(std::set<std::vector<int>> *connectedSet, QString color, int row, int column) {
|
|
|
|
|
std::vector<int> cellCoords;
|
|
|
|
|
cellCoords.push_back(row);
|
|
|
|
|
cellCoords.push_back(column);
|
|
|
|
|
connectedSet->insert(cellCoords);
|
|
|
|
|
// check below
|
|
|
|
|
if ((unsigned long) row+1 < gameMatrix.size() && !(connectedSet->contains(std::vector<int>{row+1, column})) && gameMatrix[row+1][column] == color) {
|
|
|
|
|
getConnected(connectedSet, color, row+1, column);
|
|
|
|
|
}
|
|
|
|
|
// check above
|
|
|
|
|
if (row-1 > -1 && !(connectedSet->contains(std::vector<int>{row-1, column})) && gameMatrix[row-1][column] == color) {
|
|
|
|
|
getConnected(connectedSet, color, row-1, column);
|
|
|
|
|
}
|
|
|
|
|
// check right
|
|
|
|
|
if ((unsigned long) column+1 < gameMatrix[0].size() && !(connectedSet->contains(std::vector<int>{row, column+1})) && gameMatrix[row][column+1] == color) {
|
|
|
|
|
getConnected(connectedSet, color, row, column+1);
|
|
|
|
|
}
|
|
|
|
|
// check left
|
|
|
|
|
if ((unsigned long) column-1 > -1 && !(connectedSet->contains(std::vector<int>{row, column-1})) && gameMatrix[row][column-1] == color) {
|
|
|
|
|
getConnected(connectedSet, color, row, column-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|