Example #1
0
static bool
test_replay(const Contest olc_type,
            const ContestResult &official_score)
{
  Directory::Create(_T("output/results"));
  std::ofstream f("output/results/res-sample.txt");

  GlidePolar glide_polar(fixed(2));

  Error error;
  FileLineReaderA *reader = new FileLineReaderA(replay_file.c_str(), error);
  if (reader->error()) {
    delete reader;
    fprintf(stderr, "%s\n", error.GetMessage());
    return false;
  }

  ReplayLoggerSim sim(reader);

  ComputerSettings settings_computer;
  settings_computer.SetDefaults();
  settings_computer.contest.enable = true;
  load_scores(settings_computer.contest.handicap);

  if (verbose) {
    switch (olc_type) {
    case Contest::OLC_LEAGUE:
      std::cout << "# OLC-League\n";
      break;
    case Contest::OLC_SPRINT:
      std::cout << "# OLC-Sprint\n";
      break;
    case Contest::OLC_FAI:
      std::cout << "# OLC-FAI\n";
      break;
    case Contest::OLC_CLASSIC:
      std::cout << "# OLC-Classic\n";
      break;
    case Contest::OLC_PLUS:
      std::cout << "# OLC-Plus\n";
      break;
    default:
      std::cout << "# Unknown!\n";
      break;
    }
  }

  bool do_print = verbose;
  unsigned print_counter=0;

  MoreData basic;
  basic.Reset();

  FlyingComputer flying_computer;
  flying_computer.Reset();

  FlyingState flying_state;
  flying_state.Reset();

  TraceComputer trace_computer;

  ContestManager contest_manager(olc_type,
                                 trace_computer.GetFull(),
                                 trace_computer.GetFull(),
                                 trace_computer.GetSprint());
  contest_manager.SetHandicap(settings_computer.contest.handicap);

  DerivedInfo calculated;

  while (sim.Update(basic)) {
    n_samples++;

    flying_computer.Compute(glide_polar.GetVTakeoff(),
			    basic, calculated,
			    flying_state);

    calculated.flight.flying = true;
    
    trace_computer.Update(settings_computer, basic, calculated);
    
    contest_manager.UpdateIdle();
  
    if (verbose>1) {
      sim.print(f, basic);
      f.flush();
    }
    if (do_print) {
      PrintHelper::trace_print(trace_computer.GetFull(), basic.location);
    }
    do_print = (++print_counter % output_skip ==0) && verbose;
  };

  contest_manager.SolveExhaustive();

  if (verbose) {
    PrintDistanceCounts();
  }
  return compare_scores(official_score, 
                        contest_manager.GetStats().GetResult(0));
}
Example #2
0
static bool
test_replay(const Contests olc_type, 
            const ContestResult &official_score)
{
  std::ofstream f("results/res-sample.txt");

  GlidePolar glide_polar(fixed_two);
  AircraftState state_last;

  FileLineReaderA *reader = new FileLineReaderA(replay_file.c_str());
  if (reader->error()) {
    delete reader;
    return false;
  }

  ReplayLoggerSim sim(reader);

  ComputerSettings settings_computer;
  settings_computer.SetDefaults();
  settings_computer.task.enable_olc = true;
  load_scores(settings_computer.task.contest_handicap);

  if (verbose) {
    switch (olc_type) {
    case OLC_League:
      std::cout << "# OLC-League\n";
      break;
    case OLC_Sprint:
      std::cout << "# OLC-Sprint\n";
      break;
    case OLC_FAI:
      std::cout << "# OLC-FAI\n";
      break;
    case OLC_Classic:
      std::cout << "# OLC-Classic\n";
      break;
    case OLC_Plus:
      std::cout << "# OLC-Plus\n";
      break;
    default:
      std::cout << "# Unknown!\n";
      break;
    }
  }

  bool do_print = verbose;
  unsigned print_counter=0;

  MoreData basic;
  basic.Reset();

  while (sim.Update(basic, fixed_one) && !sim.started) {
  }
  state_last = sim.state;

  fixed time_last = sim.state.time;

  FlyingComputer flying_computer;
  flying_computer.Reset();

  FlyingState flying_state;
  flying_state.Reset();

  TraceComputer trace_computer;

  ContestManager contest_manager(olc_type,
                                 trace_computer.GetFull(),
                                 trace_computer.GetSprint());
  contest_manager.SetHandicap(settings_computer.task.contest_handicap);

  DerivedInfo calculated;

  while (sim.Update(basic, fixed_one)) {
    if (sim.state.time>time_last) {

      n_samples++;

      flying_computer.Compute(glide_polar.GetVTakeoff(),
                              sim.state, flying_state);

      calculated.flight.flying = flying_state.flying;

      trace_computer.Update(settings_computer, basic, calculated);

      contest_manager.UpdateIdle();
  
      state_last = sim.state;

      if (verbose>1) {
        sim.print(f);
        f.flush();
      }
      if (do_print) {
        PrintHelper::trace_print(trace_computer.GetFull(), sim.state.location);
      }
      do_print = (++print_counter % output_skip ==0) && verbose;
    }
    time_last = sim.state.time;
  };

  contest_manager.SolveExhaustive();

  if (verbose) {
    PrintDistanceCounts();
  }
  return compare_scores(official_score, 
                        contest_manager.GetStats().GetResult(0));
}