Skip to content

Unit equals implementation is "bad" #82

Description

@Bytekeeper

I guess the code is copied from BWMirror, which only compares the ids to determine equality.
This is rather bad for BWAPI4J where a type change also results in a new Unit object with the same id.

If, for example used as a Map key the following code or similar might be used:

for (Entry<Unit,Something> u: Units.entrySet()) {
...u.getKey().getPosition().getDistance(u.getValue().goal)...

Now, getKey will always return the initial unit, for example a larva... but now it's a zergling! The position of the larva will never be updated and thus this usage is in vain.

I think the equals method should include the unit type too at the very least. Opinions?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions