Skip to content

Fix Multiplayer Battle End Condition - Resolves #355#375

Open
Owenb135 wants to merge 2 commits into
lxgr-linux:masterfrom
Owenb135:master
Open

Fix Multiplayer Battle End Condition - Resolves #355#375
Owenb135 wants to merge 2 commits into
lxgr-linux:masterfrom
Owenb135:master

Conversation

@Owenb135

@Owenb135 Owenb135 commented Jun 9, 2026

Copy link
Copy Markdown

Fix Multiplayer Battle End Condition - Resolves #355

Problem:

Multiplayer battles were unable to end properly due to an infinite loop in the outer battle loop. When a player ran out of Pokémon or all opponent Pokémon fainted, the break statement only exited the inner decision loop, causing the outer loop to continue indefinitely and restart rounds instead of concluding the battle.
Root Cause Analysis

The issue occurred at lines 144-147:

if not loser.handle_defeat(ctx, self.fightmap, winner):
    break  # ❌ Only breaks inner while loop

else:
    break
index += 1  # ❌ Always executed, restarting outer loop

The break statements only exit the inner decision loop (while True at line 79), while control flow continues to the outer battle loop (while True at line 73), causing the battle to restart instead of concluding.
Solution

Introduced a fight_over flag to properly control the outer battle loop termination:

  • Line 73: Changed outer loop condition from while True: to while not fight_over:
  • Lines 144-147: Set fight_over = True when battle end conditions are met
  • Lines 149-150: Only increment index if fight_over remains False

This ensures the battle properly exits and transitions to the victory screen when:

A player defeats all opponent Pokémon
A player runs out of active Pokémon

Testing Notes

✅ AI-assisted code review completed — Logic flow verified for all battle end scenarios:

Victory by opponent KO
Victory by opponent player exhaustion
Proper exit to victory screen and XP distribution
No regression in escape mechanics or item usage

Impact

Fixes infinite loop in multiplayer battles
Allows proper battle conclusion and winner determination
Enables correct XP and stat tracking post-battle

Owenb135 added 2 commits June 8, 2026 23:27
Refactor fight loop to use a flag for fight completion.
Replace infinite loop with conditional fight logic

@Owenb135 Owenb135 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Please run workflows on it. Merge

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.

Finish multiplayer battles

1 participant