public boolean checkValid(GameUnit unit, double effectiveness) {
   for (Outcome o : myOutcomes) {
     if (!o.checkValidOutcome(unit, effectiveness)) {
       return false;
     }
   }
   return true;
 }
  private Outcome convertOutcome(Outcome outcome) {
    Player[] players = outcome.players().toArray(new Player[0]);
    Action[] actions = new Action[players.length];

    for (int i = 0; i < players.length; i++) {
      actions[i] = actionConverter.get(players[i]).get(outcome.getAction(players[i]));
    }

    return Games.createOutcome(players, actions);
  }
  public Outcome dispatch(Target target) {
    Outcome to = this.rules.get(target.name()).run();

    if (!to.get().isAttached()) {
      this.container.add(to.get());
    }

    this.event.onDispatch(this.currentOutcome, to);
    return this.currentOutcome = to;
  }
Exemple #4
0
  public void play(Outcome result, Tie tie) {
    int s1 = p1.play();
    int s2 = p2.play();

    double player1score = game.score(s1, s2);
    double player2score = game.score(s2, s1);

    if (player1score == player2score) {
      tie.tie(s1, s2, player1score);
    } else if (player1score > player2score) {
      result.outcome(p1, s1, player1score, p2, s2, player2score);
    } else if (player2score > player1score) {
      result.outcome(p2, s2, player2score, p1, s1, player1score);
    }
  }
    @Override
    public Outcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

      ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
      String[] beans = beanFactory.getBeanNamesForType(DispatcherServlet.class, false, false);
      if (beans.length == 0) {
        return Outcome.match("no DispatcherServlet found");
      }
      if (Arrays.asList(beans).contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) {
        return Outcome.noMatch(
            "found DispatcherServlet named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
      }
      return Outcome.match(
          "multiple DispatcherServlets found and none is named "
              + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
    }
Exemple #6
0
  /**
   * Updates the outcome with respect to the labels found.
   *
   * @param goldLabels - gold labels
   * @param systemLabels - system labels
   * @param outcome -outcome
   */
  private static void evaluate(String[] goldLabels, String[] systemLabels, Outcome outcome) {
    List<String> goldList = new ArrayList<String>();
    if (goldLabels != null) goldList = new ArrayList<String>(Arrays.asList(goldLabels));

    List<String> systemList = new ArrayList<String>();
    if (systemLabels != null) systemList = new ArrayList<String>(Arrays.asList(systemLabels));

    JAXBUtil.normalizeLists(
        goldList, systemList, NULL); // make lists of the same size by adding additional nulls

    //
    for (Iterator<String> iterator = systemList.iterator(); iterator.hasNext(); ) {
      String systemLabel = iterator.next();
      int goldLabelIndex =
          goldList.indexOf(systemLabel); // look for the same label in the gold list

      // if not found, try to find the Null
      if (goldLabelIndex == -1) goldLabelIndex = goldList.indexOf(NULL);

      // if NULL label is not a gold label either, pick the first one
      if (goldLabelIndex == -1 && goldList.size() > 0) goldLabelIndex = 0;
      /*
      else{
      	System.err.println(new IllegalArgumentException(String.format("Ups! No label pair is found. System label: %s Gold labels: %s",
      			systemLabel, goldList)));
      }
      */

      String goldLabel = goldList.get(goldLabelIndex);
      // store the results
      outcome.evaluate(goldLabel, systemLabel);
      // remove labels
      iterator.remove();
      goldList.remove(goldLabelIndex);
    }
  }
Exemple #7
0
  /**
   * Evaluates relations.
   *
   * @param gold
   * @param system
   * @param labelClass
   * @param evalOption
   * @param matchLabel TODO
   * @param strictSpan TODO
   * @param outcomes
   */
  private static <T extends WithIdentifier> void evaluateRelations(
      SpRL gold,
      SpRL system,
      Class<T> labelClass,
      String evalOption,
      Outcome outcome,
      boolean matchLabel,
      boolean strictSpan) {

    if (!gold.getTEXT().getContent().equalsIgnoreCase(system.getTEXT().getContent())) {
      if (!gold.getTEXT().getContent().contains(system.getTEXT().getContent()))
        // throw new IllegalArgumentException("The content of the data is not equal.");
        System.err.println(
            system.getFilename()
                + ": The content of the data is not equal. Gold text length: "
                + gold.getTEXT().getContent().length()
                + " System text length:"
                + system.getTEXT().getContent().length()
                + " EVALUATING ANYWAY!");
    }
    // else{

    List<T> goldAnnotations = null;
    List<T> systemAnnotations = null;

    if (labelClass == null) {
      throw new NullPointerException("Annotation class is not defined.");
    } else {
      goldAnnotations = JAXBUtil.getAnnotations(gold, labelClass);
      systemAnnotations = JAXBUtil.getAnnotations(system, labelClass);
    }

    List<T> goldRelations = JAXBUtil.getAnnotations(gold, labelClass); // all gold relations

    String goldLabel = "";
    String systemLabel = "";
    if (systemAnnotations != null) {
      for (Iterator<T> iterator = systemAnnotations.iterator(); iterator.hasNext(); ) {
        T t = iterator.next();
        RELATION systemRelation = (RELATION) t;
        if (systemRelation.getGeneralType() != null
            && systemRelation.getGeneralType().trim().length() == 0)
          System.err.println("ERROR in " + system.getFilename());
        if (systemRelation.getRCC8Value() != null
            && systemRelation.getRCC8Value().equalsIgnoreCase(RCC8_EQUAL)) continue;

        Map<Class<? extends Markable>, List<? extends Markable>> args =
            JAXBUtil.getArgs(systemRelation, system);
        RELATION goldMatch =
            (RELATION)
                evaluateRelation(
                    args, goldRelations, gold, labelClass, evalOption, outcome, strictSpan);

        if (evalOption.equalsIgnoreCase(TASK_E)) {
          goldLabel = goldMatch != null ? goldMatch.getGeneralType() : NULL;
          systemLabel = systemRelation.getGeneralType();
        } else {
          goldLabel = labelClass.getSimpleName();
          systemLabel = labelClass.getSimpleName();
        }

        if (systemLabel == null) systemLabel = NULL; // if no rel found

        if (goldMatch != null) {
          outcome.evaluate(
              truncateTo(goldLabel, MAX_LEN),
              truncateTo(systemLabel, MAX_LEN)); // exact match for markables
          goldRelations.remove(goldMatch);
        } else {
          outcome.evaluate(NULL, truncateTo(systemLabel, MAX_LEN));
          goldMatch = null;
        }

        /*
        System.out.println("SYSTEM OUTPUT:\t"+r.toString(args));
        if(goldMatch != null){
        	System.out.println("MATCH FOUND:\t"+goldMatch.toString(JAXBUtil.getArgs(goldMatch, gold)));
        }else
        	System.out.println("NO MATCH FOUND");
        System.out.println();
        */

        iterator.remove();
      }
    }

    if (goldRelations != null) {
      // for the rest of gold annotation which were not matched by markables
      for (Iterator<T> iterator = goldRelations.iterator(); iterator.hasNext(); ) {
        T t = iterator.next();
        RELATION r = (RELATION) t;

        // ignore coreferential relations
        if (r.getRCC8Value() != null && r.getRCC8Value().equalsIgnoreCase(RCC8_EQUAL)) continue;

        if (evalOption.equalsIgnoreCase(TASK_E)) {
          goldLabel = r.getGeneralType();
          systemLabel = NULL;
        } else {
          goldLabel = labelClass.getSimpleName();
          systemLabel = NULL;
        }

        outcome.evaluate(truncateTo(goldLabel, MAX_LEN), NULL);

        /*
        System.out.println("SYSTEM OUTPUT:\t"+null);
        System.out.println("GOLD ANN:\t"+r.toString(JAXBUtil.getArgs((RELATION) r, gold)));
        System.out.println();
        */
      }
    }
    // }
  }
Exemple #8
0
  public static void main(String[] args) {
    String serverResponse = new String();
    ArrayList prevGameHits = new ArrayList();

    Log.WriteLog("\nStarting new match.");
    while (!Outcome.isMatchOver(serverResponse)) {

      /* Clear the string so we don't continue exiting the inner while-loop */
      serverResponse = null;
      serverResponse = new String();

      Log.WriteLog("\nStarting new game.");
      Battleship bShip = new Battleship();

      /* Connect to the game server */
      try {
        bShip.pComm.connect();
      } catch (IOException e) {
        System.err.println(e);
      }

      /* Log the connection banner */
      try {
        Log.WriteLog("Connection banner: " + bShip.pComm.readLine());
      } catch (IOException e) {
        System.err.println(e);
      }

      /* Login to the game */
      bShip.pComm.login();

      /* Print the login response */
      try {
        serverResponse = bShip.pComm.readLine();
        Log.WriteLog("Login response: " + serverResponse);
      } catch (IOException e) {
        System.err.println(e);
      }

      if (Outcome.didFail(serverResponse)) return;

      /* Send ship layout */
      bShip.pComm.sendShipLayout(bShip.myShips.generateLayout());

      /* Print ship layout response */
      try {
        serverResponse = bShip.pComm.readLine();
        Log.WriteLog("Ship layout response: " + serverResponse);
      } catch (IOException e) {
        System.err.println(e);
      }

      /* Copy over the previous games hits to our Attack object */
      bShip.attack.prevGameHits = prevGameHits;

      /* Begin the game & wait until it's over */
      while (!Outcome.isGameOver(serverResponse) && !Outcome.isMatchOver(serverResponse)) {

        Coordinate attackCoordinate = bShip.attack.generateAttack();
        bShip.pComm.fire(attackCoordinate);

        /* Increment the current turn */
        bShip.attack.incrementTurn();

        /* Process the response (HIT/MISS) */
        try {
          serverResponse = bShip.pComm.readLine();
          Log.WriteLog(
              "Turn " + bShip.attack.getCurrentTurn() + " attack response: " + serverResponse);
          bShip.attack.processAttackResponse(serverResponse, attackCoordinate);
        } catch (IOException e) {
          System.err.println(e);
        }
      }

      /* The game is now over. Copy all the hits into prevGameHits so we can check them next game. */
      prevGameHits.clear();
      bShip.attack.copyGameHits(prevGameHits);

      /* Close the connection */
      try {
        bShip.pComm.close();
      } catch (IOException e) {
        System.err.println(e);
      }
    }
  }
 public void applyOutcomes(GameUnit unit, double effectiveness) {
   for (Outcome o : myOutcomes) {
     o.applyOutcome(unit, effectiveness);
   }
 }