public static Direction flip_y_dir(Direction d) {
        switch (d) {
            case NW:
                return SW;
            case W:
                return W;
            case SW:
                return NW;
            case N:
                return S;
            case S:
                return N;
            case NE:
                return SE;
            case E:
                return E;
            case SE:
                return NE;
        }
        assert false : "should not happen";
        return NW;
    }