battlecode/battlecode-server-2017

Add methods to easily write/read other types of data to/from the broadcast array

Closed this issue · 1 comments

Pear0 commented

For booleans, I just use 1 or 0, but for floats, I have:

public class Broadcast {
    public static float getFloat(int channel) throws GameActionException {
        return Float.intBitsToFloat(rc.readBroadcast(channel));
    }

    public static void setFloat(int channel, float value) throws GameActionException {
        rc.broadcast(channel, Float.floatToIntBits(value));
    }
}

The internals of Float.floatToIntBits and Float.intBitsToFloat don't cost anything because Float is in java/lang.