battlecode / battlecode-server-2017

Official Battlecode game engine.
http://www.battlecode.org/
GNU Affero General Public License v3.0
23 stars 10 forks source link

RobotType.values() doesn't print in alphabetical order #404

Closed dwang733 closed 7 years ago

dwang733 commented 7 years ago

If you run this code

for (RobotType c : RobotType.values())
    System.out.println(c);

you get

Archon Gardener Lumberjack Soldier Tank Scout

Is it possible to make the values print out in alphabetical order instead?

Pear0 commented 7 years ago

Is it possible? Yes, by making your own array. I imagine changing this in the framework isn't very high on the devs' todo list though.

public class RobotTypes {
    public static final RobotType[] SORTED = {
        RobotType.ARCHON,
        RobotType.GARDENER,
        RobotType.LUMBERJACK,
        RobotType.SCOUT,
        RobotType.SOLDIER,
        RobotType.TANK
    };
}

// Somewhere else
for (RobotType c : RobotTypes.SORTED)
    System.out.println(c);