Skip to content

Instantly share code, notes, and snippets.

@tomohxx
Last active March 30, 2023 07:54
Show Gist options
  • Save tomohxx/5228d7de3fc1fbee93aa3ba104f80928 to your computer and use it in GitHub Desktop.
Save tomohxx/5228d7de3fc1fbee93aa3ba104f80928 to your computer and use it in GitHub Desktop.
国士無双の聴牌確率(巡目別牌種数別)
#include <array>
#include <iomanip>
#include <iostream>
int main()
{
constexpr int T_MAX = 18;
constexpr int T_MIN = 1;
constexpr int S = 123; // 四麻
// constexpr int S = 95; // 三麻
std::array<std::array<std::array<double, T_MAX + 1>, 2>, 14> table = {};
for (int t = T_MIN; t <= T_MAX; ++t) {
table[13][0][t] = 1.;
table[12][1][t] = 1.;
}
for (int i = 12; i >= 0; --i) {
if (i < 12) {
for (int t = T_MAX - 1; t >= T_MIN; --t) {
table[i][1][t] = (1. - 4. * (13 - i) / (S - t)) * table[i][1][t + 1] +
4. * (13 - i) / (S - t) * table[i + 1][1][t + 1];
}
}
for (int t = T_MAX - 1; t >= T_MIN; --t) {
table[i][0][t] = (1. - (52. - i) / (S - t)) * table[i][0][t + 1] +
4 * (13. - i) / (S - t) * table[i + 1][0][t + 1] +
3. * i / (S - t) * table[i][1][t + 1];
}
}
std::cout << std::setw(5) << std::left << "Turn";
for (int i = 12; i >= 0; --i) {
std::cout << std::setw(12) << std::left << i;
}
std::cout << "\n";
for (int j = 0; j <= 1; ++j) {
std::cout << "\n";
for (int t = T_MIN; t <= T_MAX; ++t) {
std::cout << std::setw(5) << t;
for (int i = 12; i >= 0; --i) {
std::cout << std::setw(12) << std::setprecision(4)
<< std::scientific << table[i][j][t];
}
std::cout << "\n";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment