From 8a34d6389bf2e5133b45772eb5a95fc2b17d53f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:43:49 +0000 Subject: [PATCH 1/4] Initial plan From b8c1b3fd1f70b7b8f3305e1ed90cb43ba1aedc56 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:48:40 +0000 Subject: [PATCH 2/4] Add ANSI escape code colors to tetris pieces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update blocks texture with 7 colored block strings (comma-separated) - Add inline coloredBlocks array in tetromino.h indexed by Shape enum - Use colored blocks in shapes map and rotate() in tetromino.cc - Update board.cc comparisons from == "■" to != " " for colored blocks - Preserve colored block strings when locking pieces to the grid Co-authored-by: itssimmons <62354548+itssimmons@users.noreply.github.com> --- _codeql_detected_source_root | 1 + tetris/assets/textures/blocks | 2 +- tetris/include/game/tetromino.h | 13 +++++++++++++ tetris/src/game/board.cc | 17 +++++++++-------- tetris/src/game/tetromino.cc | 28 ++++++++++++++-------------- 5 files changed, 38 insertions(+), 23 deletions(-) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/tetris/assets/textures/blocks b/tetris/assets/textures/blocks index 2dd4142..e575eca 100644 --- a/tetris/assets/textures/blocks +++ b/tetris/assets/textures/blocks @@ -1 +1 @@ -■ \ No newline at end of file +■,■,■,■,■,■,■ \ No newline at end of file diff --git a/tetris/include/game/tetromino.h b/tetris/include/game/tetromino.h index e7c0738..b611d96 100644 --- a/tetris/include/game/tetromino.h +++ b/tetris/include/game/tetromino.h @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -23,6 +24,18 @@ enum Shape : std::uint8_t I }; +// Colored blocks using ANSI escape codes, indexed by Shape enum +// L=Orange, T=Pink, J=Purple/DarkBlue, S=Green, Z=Red, O=Yellow, I=Cyan +inline const std::array coloredBlocks = { + "\x1b[38;5;208m■\x1b[0m", // L - Orange + "\x1b[35m■\x1b[0m", // T - Pink + "\x1b[34m■\x1b[0m", // J - Purple/Dark Blue + "\x1b[32m■\x1b[0m", // S - Green + "\x1b[31m■\x1b[0m", // Z - Red + "\x1b[33m■\x1b[0m", // O - Yellow + "\x1b[36m■\x1b[0m", // I - Cyan +}; + class Tetromino { public: diff --git a/tetris/src/game/board.cc b/tetris/src/game/board.cc index e33030b..5ac10e5 100644 --- a/tetris/src/game/board.cc +++ b/tetris/src/game/board.cc @@ -58,8 +58,8 @@ void Board::lockPiece(Tetromino& piece) { for (auto col = piece.x.begin; col <= piece.x.end; ++col) { - if (piece.matrix[row - piece.y.begin][col - piece.x.begin] == - "■") + if (piece.matrix[row - piece.y.begin][col - piece.x.begin] != + " ") { if (coords.x == col && coords.y == row) { @@ -79,10 +79,11 @@ void Board::lockPiece(Tetromino& piece) { for (auto col = piece.x.begin; col <= piece.x.end; ++col) { - if (piece.matrix[row - piece.y.begin][col - piece.x.begin] == - "■") + if (piece.matrix[row - piece.y.begin][col - piece.x.begin] != + " ") { - grid[row][col] = "■"; + grid[row][col] = + piece.matrix[row - piece.y.begin][col - piece.x.begin]; } } } @@ -96,7 +97,7 @@ void Board::gameOver(bool& running) { for (std::uint16_t col = 0; col < Board::bounds.RIGHT; ++col) { - if (grid[0][col] == "■") + if (grid[0][col] != " ") { running = false; break; @@ -113,7 +114,7 @@ void Board::calculateBaseline(Tetromino& piece) { for (auto col = piece.x.begin; col <= piece.x.end; ++col) { - if (piece.matrix[row - piece.y.begin][col - piece.x.begin] == "■") + if (piece.matrix[row - piece.y.begin][col - piece.x.begin] != " ") { std::int16_t r = row + 1; baseline.push_back({col, r}); @@ -149,7 +150,7 @@ void Board::render(Tetromino& piece) { int y = row - piece.y.begin; int x = col - piece.x.begin; - if (piece.matrix[y][x] == "■") cell = "■"; + if (piece.matrix[y][x] != " ") cell = piece.matrix[y][x]; } std::cout << cell; diff --git a/tetris/src/game/tetromino.cc b/tetris/src/game/tetromino.cc index 3e7b10e..e9388b9 100644 --- a/tetris/src/game/tetromino.cc +++ b/tetris/src/game/tetromino.cc @@ -7,38 +7,38 @@ std::unordered_map shapes{ {Shape::L, - {{{" ", " ", "■", " "}, - {"■", "■", "■", " "}, + {{{" ", " ", coloredBlocks[L], " "}, + {coloredBlocks[L], coloredBlocks[L], coloredBlocks[L], " "}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, {Shape::T, - {{{" ", "■", " ", " "}, - {"■", "■", "■", " "}, + {{{" ", coloredBlocks[T], " ", " "}, + {coloredBlocks[T], coloredBlocks[T], coloredBlocks[T], " "}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, {Shape::J, - {{{"■", " ", " ", " "}, - {"■", "■", "■", " "}, + {{{coloredBlocks[J], " ", " ", " "}, + {coloredBlocks[J], coloredBlocks[J], coloredBlocks[J], " "}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, {Shape::S, - {{{" ", "■", "■", " "}, - {"■", "■", " ", " "}, + {{{" ", coloredBlocks[S], coloredBlocks[S], " "}, + {coloredBlocks[S], coloredBlocks[S], " ", " "}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, {Shape::Z, - {{{"■", "■", " ", " "}, - {" ", "■", "■", " "}, + {{{coloredBlocks[Z], coloredBlocks[Z], " ", " "}, + {" ", coloredBlocks[Z], coloredBlocks[Z], " "}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, {Shape::O, - {{{"■", "■", " ", " "}, - {"■", "■", " ", " "}, + {{{coloredBlocks[O], coloredBlocks[O], " ", " "}, + {coloredBlocks[O], coloredBlocks[O], " ", " "}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, {Shape::I, {{{" ", " ", " ", " "}, - {"■", "■", "■", "■"}, + {coloredBlocks[I], coloredBlocks[I], coloredBlocks[I], coloredBlocks[I]}, {" ", " ", " ", " "}, {" ", " ", " ", " "}}}}, }; @@ -137,7 +137,7 @@ void Tetromino::rotate(const std::vector& baseline, bool clockwise) { int row = 1 - offsetY; // invert y-axis for correct rotation int col = offsetX + 1; // shift x-axis to fit in 3x3 grid - grid[row][col] = "■"; + grid[row][col] = coloredBlocks[shapeType]; } matrix = grid; From da29b06cb7761ed7df156debd313e2c7d7e93932 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:48:59 +0000 Subject: [PATCH 3/4] Remove accidentally committed codeql artifact and add to .gitignore Co-authored-by: itssimmons <62354548+itssimmons@users.noreply.github.com> --- .gitignore | 1 + _codeql_detected_source_root | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/.gitignore b/.gitignore index d8a8932..91d2a10 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ saves/ scores/ *.sav *.score +_codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b4..0000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file From 7fbd61970d4c03d9d98fb64d3cf14238cff28852 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:58:44 +0000 Subject: [PATCH 4/4] Load coloredBlocks from assets/textures/blocks file instead of hardcoding The blocks file is now the single source of truth for piece colors. coloredBlocks is declared extern in tetromino.h and defined in tetromino.cc via loadBlocks() which reads and parses the file. Co-authored-by: itssimmons <62354548+itssimmons@users.noreply.github.com> --- tetris/include/game/tetromino.h | 13 ++----------- tetris/src/game/tetromino.cc | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tetris/include/game/tetromino.h b/tetris/include/game/tetromino.h index b611d96..fb2cb59 100644 --- a/tetris/include/game/tetromino.h +++ b/tetris/include/game/tetromino.h @@ -24,17 +24,8 @@ enum Shape : std::uint8_t I }; -// Colored blocks using ANSI escape codes, indexed by Shape enum -// L=Orange, T=Pink, J=Purple/DarkBlue, S=Green, Z=Red, O=Yellow, I=Cyan -inline const std::array coloredBlocks = { - "\x1b[38;5;208m■\x1b[0m", // L - Orange - "\x1b[35m■\x1b[0m", // T - Pink - "\x1b[34m■\x1b[0m", // J - Purple/Dark Blue - "\x1b[32m■\x1b[0m", // S - Green - "\x1b[31m■\x1b[0m", // Z - Red - "\x1b[33m■\x1b[0m", // O - Yellow - "\x1b[36m■\x1b[0m", // I - Cyan -}; +// Colored blocks loaded from assets/textures/blocks, indexed by Shape enum +extern const std::array coloredBlocks; class Tetromino { diff --git a/tetris/src/game/tetromino.cc b/tetris/src/game/tetromino.cc index e9388b9..bf4ccea 100644 --- a/tetris/src/game/tetromino.cc +++ b/tetris/src/game/tetromino.cc @@ -1,10 +1,30 @@ #include +#include +#include #include #include "core/rng.h" #include "game/board.h" #include "game/tetromino.h" +static std::array loadBlocks() +{ + std::array blocks; + std::ifstream file("tetris/assets/textures/blocks"); + if (!file.is_open()) return blocks; + + std::string content((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); + std::stringstream ss(content); + std::string token; + for (size_t i = 0; i < 7 && std::getline(ss, token, ','); ++i) + blocks[i] = token; + + return blocks; +} + +const std::array coloredBlocks = loadBlocks(); + std::unordered_map shapes{ {Shape::L, {{{" ", " ", coloredBlocks[L], " "},