Skip to content

Refactor wave generation logic - #144

Merged
candour merged 1 commit into
mainfrom
refactor-wave-generation-logic-17506379874865715895
May 11, 2026
Merged

Refactor wave generation logic#144
candour merged 1 commit into
mainfrom
refactor-wave-generation-logic-17506379874865715895

Conversation

@candour

@candour candour commented May 11, 2026

Copy link
Copy Markdown
Owner

Refactored the generateEnemyList function in MainViewModel.kt to be simpler and more efficient. The early wave logic is now data-driven, and the budget-based generation for later waves has been optimized to avoid unnecessary iterations by pre-filtering affordable enemy types. Recorded the improvement in fixes.md.


PR created automatically by Jules for task 17506379874865715895 started by @candour

Summary by CodeRabbit

  • Refactor
    • Optimized wave enemy composition logic for improved balance and consistency.
    • Enhanced enemy selection algorithm for later waves using a more efficient budget-based tier selection system.

Review Change Stack

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03f058c7-fa40-4627-a17f-50f68af39774

📥 Commits

Reviewing files that changed from the base of the PR and between c162dd1 and fc62ec5.

📒 Files selected for processing (2)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
  • fixes.md

📝 Walkthrough

Walkthrough

MainViewModel's generateEnemyList method was refactored to separate early-wave (1–6) enemy composition from dynamic wave-7+ budget allocation. A new earlyWaveConfigs map replaces hardcoded when-branches; the wave-7+ loop now filters affordable tiers iteratively instead of using bounded attempts, improving clarity and logic flow.

Changes

Enemy Wave Composition Refactoring

Layer / File(s) Summary
Early Wave Configuration Map
app/src/main/java/com/messark/hawker/MainViewModel.kt
New private earlyWaveConfigs map specifies fixed (EnemyType, count) pairs for waves 1–6.
Early Wave Generation
app/src/main/java/com/messark/hawker/MainViewModel.kt
generateEnemyList uses earlyWaveConfigs[wave] to look up and flatten enemy configs for waves 1–6, then shuffles the result.
Wave 7+ Budget Allocation Loop
app/src/main/java/com/messark/hawker/MainViewModel.kt
Wave-7+ loop now iteratively filters allowedTiers to only "affordable" tiers (where HP fits in remainingBudget), enforces single Tiger Mom constraint, and terminates when no tier is affordable or budget depletes.
Changelog Documentation
fixes.md
REF-005 entry added documenting refactoring and efficiency improvements to enemy generation logic.

Sequence Diagram(s)

flowchart TD
    A["Wave received by generateEnemyList"] --> B{Wave <= 6?}
    B -->|Yes| C["Look up earlyWaveConfigs[wave]"]
    C --> D["Flatten enemy pairs into list"]
    D --> E["Shuffle list"]
    E --> F["Return enemies"]
    B -->|No| G["Initialize remainingBudget and enemies list"]
    G --> H["Filter allowedTiers to affordable tiers<br/>where HP <= remainingBudget"]
    H --> I{Any affordable<br/>tiers?}
    I -->|Yes| J["Select random affordable tier"]
    J --> K["Deduct HP from remainingBudget"]
    K --> L["Add tier to enemies"]
    L --> H
    I -->|No| M{Enemies<br/>empty?}
    M -->|Yes| N["Add fallback enemy"]
    M -->|No| O["Shuffle enemies list"]
    N --> O
    O --> F
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • candour/towerpower#131: Both PRs modify MainViewModel.generateEnemyList — this refactors enemy selection logic and early-wave configs; that PR makes RNG usage deterministic and replaces global Random calls.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-wave-generation-logic-17506379874865715895

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.

…iency

- Replaced procedural 'when' logic for early waves (1-6) with a data-driven configuration map 'earlyWaveConfigs'.
- Optimized the budget-filling loop for waves 7+ by pre-filtering affordable enemy tiers and board constraints (Tiger Mom limit) during selection.
- Updated 'fixes.md' with entry REF-005.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@candour
candour force-pushed the refactor-wave-generation-logic-17506379874865715895 branch from 5a43e4a to fc62ec5 Compare May 11, 2026 01:50
@candour
candour merged commit c2283cc into main May 11, 2026
2 of 3 checks passed
@candour
candour deleted the refactor-wave-generation-logic-17506379874865715895 branch May 11, 2026 01:51
@github-actions

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

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.

1 participant