/**
  * @param ai
  * @param instance
  * @param field
  * @param parameter
  * @throws IllegalAccessException
  */
 private void initClassFieldDigitParameter(
     final Class<? extends AI> ai,
     final AI instance,
     final Field field,
     final AIDigitParameters parameter)
     throws IllegalAccessException {
   AIJComponent uiComponent = null;
   if (field.getType().equals(int.class)) {
     uiComponent =
         new AIDigitParameterJComponent<Integer>(
             (int) parameter.value(),
             (int) parameter.min(),
             (int) parameter.max(),
             ai,
             instance,
             field);
     field.setInt(instance, (int) parameter.value());
   } else if (field.getType().equals(double.class)) {
     uiComponent =
         new AIDigitParameterJComponent<Double>(
             parameter.value(), parameter.min(), parameter.max(), ai, instance, field);
     field.setDouble(instance, parameter.value());
   }
   if (uiComponent != null) {
     uiComponent.addComponents(instance.component());
   }
 }
 /** @param event */
 @Subscribe
 public void play(final PlayEvent event) {
   _affected = _model.paint(event.paint());
   if (won()) {
     _bus.post(new GameWonEvent(_affected, _model.turns()));
     _model =
         DrenchModel.Generator.createRandomModel(
             _model.width(), _model.height(), _model.maxTurns() - 1);
     for (AI ai : _loader._ais.values()) {
       ai.initialize(this);
     }
   } else if (lost()) {
     _bus.post(new GameOverEvent(_affected));
     _model =
         DrenchModel.Generator.createRandomModel(
             _model.width(), _model.height(), _model.maxTurns());
   } else {
     _bus.post(new PlayedEvent(_affected, _model.turns()));
   }
 }
 /**
  * @param ai
  * @param instance
  * @param field
  * @param annotation
  */
 private void initClassFieldBooleanParameter(
     final Class<? extends AI> ai,
     final AI instance,
     final Field field,
     final AIBooleanParameter annotation)
     throws IllegalAccessException {
   AIJComponent uiComponent =
       new AIBooleanParameterJComponent(annotation.value(), ai, instance, field);
   field.setBoolean(instance, annotation.value());
   uiComponent.addComponents(instance.component());
 }
 public GameAILoader() {
   _finder = new ClassAIFinder();
   _classes = _finder.getAIClasses(AI.class, "ch.hesso");
   ImmutableMap.Builder<String, AI> builder = ImmutableMap.builder();
   for (Class<? extends AI> ai : _classes) {
     try {
       AI instance = ai.newInstance();
       instance.initialize(GameController.this);
       if (instance.kind().equals(PLAYER)) {
         _default = instance;
         _defaultAIName = instance.name();
       }
       builder.put(instance.name(), instance);
       initClassFields(ai, instance);
     } catch (InstantiationException | IllegalAccessException e) {
       LOG.log(Level.SEVERE, "[GameController.GameAILoader.GameAILoader]: " + e.getMessage());
     }
   }
   _ais = builder.build();
   if (_default == null && _ais.size() > 0) {
     _default = _ais.values().asList().get(0);
     _defaultAIName = _ais.keySet().asList().get(0);
   }
 }
 /** @param event */
 @Subscribe
 public void nextAI(final NextEvent event) {
   Paint paintAI = _ai.play(_model);
   _bus.post(new PlayEvent(paintAI));
 }