Initial commit, some logic added

This commit is contained in:
2026-05-23 11:50:32 +03:00
commit 96eefbe181
9 changed files with 370 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#include "line.h"
Line::Line() {
this->line.clear();
this->line.reserve(4);
}
Line::Line(size_t length) {
this->line.clear();
this->line.reserve(length);
}
void Line::processLine() {
std::vector<Tile> result;
Tile pending = 0;
bool hasPending = false;
for (Tile element : this->line) {
if (element == 0) continue;
if (!hasPending) {
pending = element;
hasPending = true;
continue;
}
if (element == pending) {
result.push_back(pending * 2);
this->score += pending * 2;
hasPending = false;
pending = 0;
} else {
result.push_back(pending);
pending = element;
}
}
if (hasPending) {
result.push_back(pending);
}
while (result.size() < sourceLine.size()) {
result.push_back(0);
}
return result;
}