Skip to content

Conversation

@gustebeast
Copy link

@gustebeast gustebeast commented Jan 24, 2026

Main branch without Tetris
Flash: [======== ] 79.8% (used 1255301 bytes from 1572864 bytes)

Main branch with Tetris (+196kb)
Flash: [========= ] 92.3% (used 1452049 bytes from 1572864 bytes)

This commit with Tetris (+6kb, 97% less flash)
Flash: [======== ] 80.2% (used 1261625 bytes from 1572864 bytes)

Summary by CodeRabbit

Release Notes

  • Refactor

    • Optimized internal code structure in Tetris AI module by removing unused dependencies and streamlining queue management implementation.
  • Chores

    • Removed a public method from TetrisBag class; verify compatibility if your code relies on queue piece indexing functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

Main branch without Tetris
Flash: [========  ]  79.8% (used 1255301 bytes from 1572864 bytes)

Main branch with Tetris (+196kb)
Flash: [========= ]  92.3% (used 1452049 bytes from 1572864 bytes)

This commit with Tetris (+6kb, 97% less flash)
Flash: [========  ]  80.2% (used 1261625 bytes from 1572864 bytes)
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Walkthrough

This PR removes unused include dependencies from three header files in the TetrisAI_v2 module and refactors the TetrisBag class by removing a public method overload and replacing std::rotate with a manual loop implementation.

Changes

Cohort / File(s) Summary
Dependency cleanup
usermods/TetrisAI_v2/gridbw.h, usermods/TetrisAI_v2/pieces.h
Removed unused include directives (<iterator> and <iostream> respectively); no logic or API changes.
API and implementation refactoring
usermods/TetrisAI_v2/tetrisbag.h
Removed public method overload void queuePiece(uint8_t idx), refactored void queuePiece() to use manual loop instead of std::rotate, and removed <algorithm> include.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR—reducing flash usage of the TetrisAI_V2 module through dependency removal and code optimization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@usermods/TetrisAI_v2/tetrisbag.h`:
- Around line 86-92: queuePiece() can underflow when the queue is empty because
piecesQueue.size() - 1 will wrap and cause out-of-range access; fix by returning
early (or asserting) when the queue is empty (e.g., check piecesQueue.empty() or
queueLength == 0) before shifting elements and assigning getNextPiece(),
ensuring you guard the piecesQueue access in queuePiece().

Comment on lines 86 to 92
void queuePiece()
{
//move vector to left
std::rotate(piecesQueue.begin(), piecesQueue.begin() + 1, piecesQueue.end());
for (uint8_t i = 1; i < piecesQueue.size(); i++) {
piecesQueue[i - 1] = piecesQueue[i];
}
piecesQueue[piecesQueue.size() - 1] = getNextPiece();
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Guard against empty queue to avoid out-of-range access.

If queueLength == 0, piecesQueue.size() - 1 underflows and the assignment is out-of-bounds. Add a quick empty check (or assert) to keep this safe.

🐛 Suggested fix
 void queuePiece()
 {
+    if (piecesQueue.empty()) return;
     //move vector to left
     for (uint8_t i = 1; i < piecesQueue.size(); i++) {
         piecesQueue[i - 1] = piecesQueue[i];
     }
     piecesQueue[piecesQueue.size() - 1] = getNextPiece();
 }
🤖 Prompt for AI Agents
In `@usermods/TetrisAI_v2/tetrisbag.h` around lines 86 - 92, queuePiece() can
underflow when the queue is empty because piecesQueue.size() - 1 will wrap and
cause out-of-range access; fix by returning early (or asserting) when the queue
is empty (e.g., check piecesQueue.empty() or queueLength == 0) before shifting
elements and assigning getNextPiece(), ensuring you guard the piecesQueue access
in queuePiece().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard, for loop is never entered if piecesQueue.size() < 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aircoookie You're absolutely right that the for loop won't execute when the queue is empty. I was also concerned about the assignment on the next line (piecesQueue[piecesQueue.size() - 1] = getNextPiece();), which could underflow if size() == 0. However, if the queue is always initialized with a non-zero size in practice, that wouldn't be an issue. I'll defer to your judgment on this! 👍

Copy link
Member

@Aircoookie Aircoookie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! Awesome that we can achieve such huge flash savings by avoiding these imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants