From 5865a3d099e5be8a55333dcc0669340a28b76c49 Mon Sep 17 00:00:00 2001 From: SKYJAMES777 <3886190@qq.com> Date: Tue, 23 Jun 2026 08:40:15 +0800 Subject: [PATCH] fix: hardDrop should use actual piece height, not fixed 4x4 matrix height --- tetris/src/game/tetromino.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tetris/src/game/tetromino.cc b/tetris/src/game/tetromino.cc index 2f0aeec..e5d5fd9 100644 --- a/tetris/src/game/tetromino.cc +++ b/tetris/src/game/tetromino.cc @@ -211,13 +211,25 @@ void Tetromino::moveRight(std::vector> grid) void Tetromino::hardDrop(const std::vector& boardBaseline) { + // Trim empty rows at bottom of the 4x4 bounding box + std::int16_t pieceBottom = y.begin; + for (auto row = y.begin; row <= y.end; ++row) { + for (auto col = x.begin; col <= x.end; ++col) { + if (matrix[row - y.begin][col - x.begin] != " ") { + pieceBottom = row; + break; + } + } + } + std::int16_t pieceHeight = pieceBottom - y.begin + 1; + std::int16_t highestY = boardBaseline[0].y; for (const auto& coord : boardBaseline) { if (coord.y < highestY) highestY = coord.y; } y.end = highestY; - y.begin = static_cast(y.end - matrix.size() + 1); + y.begin = static_cast(y.end - pieceHeight + 1); } void Tetromino::softDrop()