예제 #1
0
  /**
   * Parse a line of UNITSPOT.DAT data.
   *
   * @param s
   * @param file_name
   * @param line_nr
   * @return double[]
   */
  public static double[] getCosts(String s, String file_name, int line_nr) {

    double[] ret_val = new double[C.UNIT_SPOT_MOVE];

    Pattern planet_type = Pattern.compile("\"[a-zA-Z]+\"");
    Matcher m = planet_type.matcher(s);
    // skip "planet type"
    Util.testFFErrorAndExit(m.find(), file_name, line_nr);
    // last one is a big string of ten of decimal numbers
    Pattern costs_pattern = Pattern.compile("\"[0-9][0-9\\. ]+[0-9]\"");
    m = costs_pattern.matcher(s);
    //        System.out.println("s = " + s);
    Util.testFFErrorAndExit(m.find(), file_name, line_nr);
    //        String costs = s.substring(m.start() + 1, m.end() - 1);
    String costs = s.substring(m.start() + 1, m.end());
    //        System.out.println("costs = " + costs);
    //        costs_pattern = Pattern.compile("[0-9]+\\.[0-9]+");
    //
    //        m = costs_pattern.matcher(costs);
    //
    //        for (int i = 0; i < C.UNIT_SPOT_MOVE; i++) {
    //            System.out.println("i = " + i);
    //            ret_val[i] = processDoubleVal(costs, m, file_name, line_nr);
    //        }

    processDoubleVals(costs, ret_val, file_name, line_nr);

    return ret_val;
  }
예제 #2
0
  /**
   * Parse a double value.
   *
   * @param s
   * @param m
   * @param file_name
   * @param line_nr
   * @return
   */
  public static double processDoubleVal(String s, Matcher m, String file_name, int line_nr) {
    Util.testFFErrorAndExit(m.find(), file_name, line_nr);
    //        System.out.println("s = " + s);
    double ret_val = Double.parseDouble(s.substring(m.start(), m.end()));
    //        System.out.println("ret_val = " + ret_val);

    return ret_val;
  }