Skip to content

Bug: Inverted tie-breaking condition in ProcessCityElections causes incumbent to win when they shouldn't (Property.cs) #1978

@coderabbitai

Description

@coderabbitai

Summary

In SWLOR.Game.Server/Service/Property.cs, the ProcessCityElections method has an inverted condition for detecting tied votes. The comment says the incumbent mayor should win when the top two candidates are tied, but the condition uses != instead of ==, causing the incumbent to be kept in place whenever the top two candidates have different vote counts — i.e., when there is a clear winner. The actual winner never receives the city in this scenario.

Affected Code

// Comment: "If top two are the same, incumbent mayor wins."
else if (orderedVotes.Count >= 2 && orderedVotes.ElementAt(0).Value != orderedVotes.ElementAt(1).Value)
//                                                                    ^^^ should be ==
{
    Log.Write(LogGroup.Property, $"Top 2 candidates were tied. Incumbent mayor '{incumbentMayorId}' wins the election.");
}

Suggested Fix

Change the condition from != to ==:

else if (orderedVotes.Count >= 2 && orderedVotes.ElementAt(0).Value == orderedVotes.ElementAt(1).Value)
{
    Log.Write(LogGroup.Property, $"Top 2 candidates were tied. Incumbent mayor '{incumbentMayorId}' wins the election.");
}

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions