Esempio n. 1
0
File: HSv3.c Progetto: thducng/C
void commandlist(int command){
  switch(command){
    case 1: case 2: case 3: case 4: case 5:
    case 6: case 7: case 8: case 9:
      print_run(command);
      break;
    case 10:
      recover_run();
      break;
    case 11:
      print_all();
      break;
    case 12:
      win_stats();
      break;
    case 13:
      best_class();
      break;
    case 14:
      worst_class();
      break;
    case 15:
      played_class();
      break;
    case 16:
      myelo();
      break;
    case 21: case 22: case 23: case 24: case 25:
    case 26: case 27: case 28: case 29:
      class_win_stats(command);  
      break;
  }
}
Esempio n. 2
0
  /// @brief Attempt a move of the selected type
  ///
  /// This function implements the core of the Metropolis-Hastings algorithm
  /// by generating a random number and comparing with the results of
  /// CalculateA1 and CalculateA2. If the move is accepted, this function
  /// calls make_move(). If not, it updates **attempted_moves_**.
  ///
  /// @param move The type of move
  void attempt_move(const move_type move)
  {
    // Calculate probability
    auto a1 = CalculateA1(move);
    // Make move if random number < probability
    auto a2 = CalculateA2(move);

    const auto trial_value = generate_probability();
    // Convert to Gmpzf because trial_value will be set to 0 when
    // comparing with a1 and a2!
    //    const auto trial = Gmpzf(static_cast<double>(trial_value));
    const auto trial = static_cast<double>(trial_value);

#ifndef NDEBUG
    std::cout << __PRETTY_FUNCTION__ << " called.\n";
    std::cout << "trial_value = " << trial_value << "\n";
    std::cout << "trial = " << trial << "\n";
#endif

    if (trial <= a1 * a2) {
      // Move accepted
      make_move(move);
    }
    else
    {
      // Move rejected
      // Increment attempted_moves_
      ++attempted_moves_[to_integral(move)];
    }

#ifndef NDEBUG
    std::cout << __PRETTY_FUNCTION__ << " called.\n";
    std::cout << "Attempting move.\n";
    std::cout << "Move type = " << to_integral(move) << "\n";
    std::cout << "Trial = " << trial << "\n";
    std::cout << "A1 = " << a1 << "\n";
    std::cout << "A2 = " << a2 << "\n";
    std::cout << "A1*A2 = " << a1 * a2 << "\n";
    std::cout << ((trial <= a1 * a2) ? "Move accepted." : "Move rejected.")
              << "\n";
    print_run();
#endif
  }  // attempt_move()
Esempio n. 3
0
void print_runs(run_t *run) {
    do {
        print_run(run);
        printf("---------------------------------\n");
    } while(run->next != NULL);
}