package net.ciklum.icfpc11.parser import net.ciklum.icfpc11.domain.Card import net.ciklum.icfpc11.domain.GameError /** * Input parser * @author mym */ @Typed final class ArgumentParser { Command parse(String arg1, String arg2, String arg3) { Application application = Application.from(arg1) String cardString, slotString if (application == Application.LEFT) { cardString = arg2 slotString = arg3 } else { cardString = arg3 slotString = arg2 } int slot = Integer.parseInt(slotString) if (!isSlotNumberValid(slot)) { throw new GameError("Invalid slot number ${slot}") } Card card = Card.valueOf(cardString) new Command(application, slot, card) } boolean isSlotNumberValid(int slot) { return slot >= 0 && slot <= 255 } }