Skip to content

Complete ties should be broken randomly #381

@rooklift

Description

@rooklift

It's possible for both the territory and the territory integral of two players to be the same. (Especially when someone is testing versions of their bots locally -- they may behave identically.)

Such ties should be broken randomly (instead of based on player index).

I believe the relevant piece of code is at:
https://github.com/HaliteChallenge/Halite/blob/master/environment/core/Halite.cpp#L347

Which I think could be replaced with something like this, except I'm not a C++ person. Presumably we also need to import some PRNG function and seed it at some point...

// Sort newRankings by last territory count. If it's the same, use the territory integral instead to break that tie.
// But if that's the same, flip a coin.
std::stable_sort(newRankings.begin(), newRankings.end(), [&](const unsigned int & u1, const unsigned int & u2) -> bool {
    if (last_territory_count[u1] != last_territory_count[u2]) {
        return last_territory_count[u1] < last_territory_count[u2];
    }
    if (full_territory_count[u1] != full_territory_count[u2]) {
        return full_territory_count[u1] < full_territory_count[u2];
    }
    return RESULT_OF_SOME_COIN_FLIP;    // Don't know the C++ way to do this.
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions