Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

フリーランモードに対応 #4

Merged
merged 16 commits into from
Feb 16, 2024
Merged

フリーランモードに対応 #4

merged 16 commits into from
Feb 16, 2024

Conversation

kackyt
Copy link
Owner

@kackyt kackyt commented Feb 15, 2024

Summary by CodeRabbit

  • 新機能

    • .git ディレクトリと logs/ ディレクトリを .dockerignore ファイルで除外するパターンを追加しました。
    • プルリクエストの内容に基づいてラベリングするための設定を導入しました。
    • リリースドラフトの設定を導入しました。
    • GitHub Actions ワークフローを導入し、プルリクエストが自動的にラベル付けされます。
    • GitHub Actions ワークフローを設定し、メインブランチのクローズされたプルリクエストによってリリースが作成されます。
    • デバッグフラグを [profile.release] セクションに追加しました。
    • ベースイメージを切り替え、ユーザー権限を調整し、パッケージのインストールを更新し、ランタイムセットアップを洗練しました。
    • app サービスのビルド設定を更新し、ボリュームマッピングを変更しました。
    • Debianベースのシステムに必要なパッケージをインストールするための設定をしました。
    • クラウドストレージからファイルをダウンロードし、サーバーを実行し、ログをクラウドストレージにアップロードするように変更しました。
  • バグ修正

    • コンパイルされた .dll ファイル、target という名前のディレクトリ、および logs ディレクトリを無視するルールを導入しました。
  • ドキュメント

    • プルリクエストに基づいて自動的にラベルを付ける GitHub Actions ワークフローについて説明しました。
    • メインブランチのクローズされたプルリクエストによってリリースを作成する GitHub Actions ワークフローについて説明しました。
  • リファクタリング

    • load_ai 関数と get_ai_symbol 関数を更新しました。
    • インポートを再編成し、変数宣言を調整し、PaiState インスタンスを初期化しました。
    • インポートの順序を変更し、関数呼び出しを修正し、配列の初期化を調整しました。
    • インポートの順序を変更し、clap::Parser インポートを追加し、ai_bridge のインポートと構造体フィールドを修正し、experiment 関数を更新し、main 関数をリファクタリングしました。
  • 依存関係の更新

    • 新しいパッケージを追加し、既存のパッケージのバージョンを更新しました。
    • 依存関係 clap バージョン 4.5.0 と dotenv バージョン 0.15.0 を追加しました。

Copy link

coderabbitai bot commented Feb 15, 2024

Walkthrough

この変更は、プロジェクト全体の高レベルな改善を行いました。環境変数のチェック、クラウドストレージからファイルのダウンロード、指定されたパラメータでサーバーを実行し、ログをクラウドストレージにアップロードするスクリプトに関する変更が含まれています。

Changes

ファイル 変更概要
.run.sh 環境変数のチェック、クラウドストレージからのファイルダウンロード、サーバーの実行、ログのクラウドストレージへのアップロードコマンドを追加
server/src/main.rs インポートの並べ替え、clap::Parserの追加、ai_bridgeの変更、Command構造体の追加、experiment関数のロジック更新、main関数のリファクタリング

🐰🌟
変更が来た、新しい風、
コードが踊る、夜明けまで。
ビルドは通り、テストも緑、
開発の旅、再び始まる。
🚀🌈

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 7

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between f781fbf and f650286.
Files selected for processing (19)
  • .dockerignore (1 hunks)
  • .github/pr-labeler.yml (1 hunks)
  • .github/release-drafter.yml (1 hunks)
  • .github/workflows/pr_label.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .gitignore (1 hunks)
  • Cargo.lock (13 hunks)
  • Cargo.toml (1 hunks)
  • Dockerfile (1 hunks)
  • ai_bridge/src/ai_loader.rs (1 hunks)
  • ai_bridge/src/interface.rs (12 hunks)
  • ai_bridge/tests/test_func.rs (6 hunks)
  • docker-compose.yml (1 hunks)
  • install.sh (1 hunks)
  • loadlibrary (1 hunks)
  • mahjong-app-engine (1 hunks)
  • run.sh (1 hunks)
  • server/Cargo.toml (1 hunks)
  • server/src/main.rs (3 hunks)
Files skipped from review due to trivial changes (4)
  • .dockerignore
  • Cargo.toml
  • loadlibrary
  • mahjong-app-engine
Additional comments: 28
.gitignore (1)
  • 1-3: .gitignoreファイルに変更が加えられましたが、これらの変更は適切です。
docker-compose.yml (1)
  • 4-13: docker-compose.ymlappサービスのボリュームマッピングで、ホストの現在のディレクトリをコンテナ内の/home/app_copyにマッピングしていますが、このパスはプロジェクトの構造やDockerfileと整合性が取れているか確認が必要です。
.github/workflows/pr_label.yml (1)
  • 1-15: pr_label.ymlの設定は適切に見えますが、実際のラベル名とGitHubリポジトリのラベル設定が一致しているか確認する必要があります。
server/Cargo.toml (1)
  • 16-17: Cargo.tomlに追加されたclapdotenvの依存関係は適切です。
Dockerfile (1)
  • 1-25: Dockerfileの変更は、基本的に適切に見えますが、RUN cargo build -p server --release --features load-dllのコマンドでビルドされるバイナリが実際に/home/app/target/release/serverに存在するか確認する必要があります。
.github/release-drafter.yml (1)
  • 1-31: release-drafter.ymlの設定は適切に見えます。特に修正する必要はありません。
.github/workflows/release.yml (1)
  • 1-33: release.ymlの設定は適切に見えます。GitHub Actionsの設定に関して特に問題はありません。
ai_bridge/tests/test_func.rs (1)
  • 72-118: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-167]

test_func.rsのテストケースにおいて、state.createstate.sutehaiの呼び出しに追加の引数が必要になっていますが、これらの変更は適切に行われています。

ai_bridge/src/interface.rs (6)
  • 40-46: MJRL_AKA5の処理において、明示的なブレースの追加が行われていますが、Rustの慣習として、単一の式であればブレースは省略可能です。ただし、この変更はコードの明確性を向上させるために有用かもしれません。
  • 49-56: MJRL_SHANYUの処理において、if-elseブロックに明示的なブレースが追加されています。この変更はコードの読みやすさを向上させますが、Rustの慣習としては必須ではありません。
  • 59-66: MJRL_NANNYUの処理で、if-elseブロックにブレースが追加されています。この変更はコードの可読性を高めるものですが、Rustでは単一の式の場合ブレースを省略することが一般的です。
  • 90-90: mjsend_message_impl関数のpstateパラメータは、可変参照として渡されています。これは、関数内でPaiStateの状態を変更するために必要です。適切な使用です。
  • 94-99: コメントアウトされたprintln!マクロは、デバッグ目的で使用されていた可能性がありますが、本番コードには含めない方が良いでしょう。不要なコードは削除することを推奨します。
  • 447-455: LinuxまたはWindows以外のOSでmjsend_message関数を使用する場合、PaiState::default()を使用してpstateを初期化しています。このアプローチは、上記のMaybeUninitを使用する方法よりも簡潔で安全です。
Cargo.lock (14)
  • 85-97: 新しいパッケージanstreamとその依存関係が追加されました。これはPRの目的に沿っています。
  • 99-103: 新しいパッケージanstyleが追加されました。これはPRの目的に沿っています。
  • 105-111: 新しいパッケージanstyle-parseとその依存関係が追加されました。これはPRの目的に沿っています。
  • 114-120: 新しいパッケージanstyle-queryとその依存関係が追加されました。これはPRの目的に沿っています。
  • 123-130: 新しいパッケージanstyle-winconとその依存関係が追加されました。これはPRの目的に沿っています。
  • 338-346: 新しいパッケージclapとその依存関係が追加されました。これはPRの目的に沿っています。
  • 348-357: 新しいパッケージclap_builderとその依存関係が追加されました。これはPRの目的に沿っています。
  • 361-369: 新しいパッケージclap_deriveとその依存関係が追加されました。これはPRの目的に沿っています。
  • 387-391: 新しいパッケージcolorchoiceが追加されました。これはPRの目的に沿っています。
  • 463-467: 新しいパッケージdotenvが追加されました。これはPRの目的に沿っています。
  • 669-673: 新しいパッケージheckが追加されました。これはPRの目的に沿っています。
  • 1689-1692: 新しいパッケージstrsimが追加されました。これはPRの目的に沿っています。
  • 1970-1973: 新しいパッケージutf8parseが追加されました。これはPRの目的に沿っています。
  • 1987-1994: 新しいパッケージuuid-macro-internalとその依存関係が追加されました。これはPRの目的に沿っています。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between f650286 and 8df7906.
Files selected for processing (2)
  • install.sh (1 hunks)
  • run.sh (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • install.sh
  • run.sh

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 8df7906 and 1cb4e7f.
Files selected for processing (2)
  • run.sh (1 hunks)
  • server/src/main.rs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • run.sh
Additional comments: 2
server/src/main.rs (2)
  • 148-200: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [120-197]

cmd関数では、複数のunsafeブロックを使用して外部ライブラリとのインタラクションが行われています。unsafeブロックの使用は避けられない場合がありますが、これらのブロック内でのエラーハンドリングが重要です。特に、unwrapを使用する代わりに、エラーが発生した場合に適切なエラーメッセージを提供することで、デバッグを容易にすることが推奨されます。ただし、以前のレビューコメントでunwrapの使用が意図的であることが確認されているため、この点については追加のアクションは不要です。

  • 208-220: main関数において、環境変数の読み込み、コマンドライン引数の解析、Sentryの初期化、そしてcmd関数の呼び出しが行われています。unwrapを使用している箇所がありますが、これは以前のレビューコメントでSentry通知のために意図的に使用されていることが確認されています。このため、この実装については特に問題はありません。

Comment on lines +21 to +30
#[derive(Parser, Debug)]
#[command(author, about, version)]
struct Command {
#[arg(short, long)]
log_path: String,
#[arg(short, long)]
input_dll: String,
#[arg(short, long)]
paiyama_path: Option<String>,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command構造体の定義については、コマンドライン引数を解析するための明確な方法を提供しており、適切に実装されています。ただし、フィールドに対するドキュメントコメントがないため、各フィールドの目的がコードから直接読み取りにくい可能性があります。

#[derive(Parser, Debug)]
#[command(author, about, version)]
struct Command {
+    /// ログファイルのパス
    #[arg(short, long)]
    log_path: String,
+    /// 入力DLLのパス
    #[arg(short, long)]
    input_dll: String,
+    /// パイ山ファイルのパス(オプション)
    #[arg(short, long)]
    paiyama_path: Option<String>,
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
#[derive(Parser, Debug)]
#[command(author, about, version)]
struct Command {
#[arg(short, long)]
log_path: String,
#[arg(short, long)]
input_dll: String,
#[arg(short, long)]
paiyama_path: Option<String>,
}
#[derive(Parser, Debug)]
#[command(author, about, version)]
struct Command {
/// ログファイルのパス
#[arg(short, long)]
log_path: String,
/// 入力DLLのパス
#[arg(short, long)]
input_dll: String,
/// パイ山ファイルのパス(オプション)
#[arg(short, long)]
paiyama_path: Option<String>,
}

Comment on lines +32 to +118
unsafe fn experiment(func: MJPInterfaceFuncP, inst: *mut c_void, play_log: &mut play_log::PlayLog) {
{
let state = &mut G_STATE;
state.start(play_log);
}
func(inst, MJPI_STARTKYOKU.try_into().unwrap(), 0, 0);
println!("start kyoku end");

let mut is_agari = false;

for _i in 0..18 {
let mut tsumohai_num: usize;
{
let state = &mut G_STATE;
state.tsumo(play_log);
tsumohai_num = state.players[state.teban as usize]
.tsumohai
.pai_num
.try_into()
.unwrap();
}

ensure!(args.len() >= 2, "usage: {} DLLPath", args[0]);
let ret: u32 = func(inst, MJPI_SUTEHAI.try_into().unwrap(), tsumohai_num, 0)
.try_into()
.unwrap();
let index = ret & 0x3F;
let flag = ret & 0xFF80;
// println!("ret = {} flag = {:04x}", index, flag);

{
let state = &mut G_STATE;
/*
{
let player = &state.players[state.teban as usize];
for p in &player.tehai {
print!("{}", p);
}

print!("{}", player.tsumohai);
let shanten = PaiState::from(&player.tehai).get_shanten(0);
println!(" シャンテン数 {}\r", shanten);
}
*/

if flag == MJPIR_SUTEHAI {
state.sutehai(play_log, index as usize, false);
} else if flag == MJPIR_REACH {
state.sutehai(play_log, index as usize, true);
} else if flag == MJPIR_TSUMO {
let score: [i32; 4] = [0, 0, 0, 0];
println!("agari!!!");
let agari_r = state.tsumo_agari(play_log);

match agari_r {
Ok(agari) => {
println!("{:?}", agari.yaku);
}
Err(e) => {
println!("{:?}", e);
}
}

let path = PathBuf::from(&args[1]);
is_agari = true;
func(
inst,
MJPI_ENDKYOKU.try_into().unwrap(),
MJEK_RYUKYOKU.try_into().unwrap(),
std::mem::transmute(score.as_ptr()),
);
break;
}
}
}

load_ai(&path);
if !is_agari {
println!("流局(;;)");
let score: [i32; 4] = [-3000, 0, 0, 0];
func(
inst,
MJPI_ENDKYOKU.try_into().unwrap(),
MJEK_RYUKYOKU.try_into().unwrap(),
std::mem::transmute(score.as_ptr()),
);
let state = &mut G_STATE;
state.nagare(play_log);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

experiment関数において、unsafeブロック内での外部関数の呼び出しやポインタ操作が適切に行われています。ただし、println!マクロを使用したデバッグ出力が複数存在します。これらは開発中に有用ですが、本番環境のコードでは不要な出力が発生する可能性があるため、削除するか、条件付きコンパイルを使用してデバッグビルド時のみに含めることを検討してください。

-    println!("start kyoku end");
+    #[cfg(debug_assertions)]
+    println!("start kyoku end");

-    println!("agari!!!");
+    #[cfg(debug_assertions)]
+    println!("agari!!!");

-    println!("流局(;;)");
+    #[cfg(debug_assertions)]
+    println!("流局(;;)");

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
unsafe fn experiment(func: MJPInterfaceFuncP, inst: *mut c_void, play_log: &mut play_log::PlayLog) {
{
let state = &mut G_STATE;
state.start(play_log);
}
func(inst, MJPI_STARTKYOKU.try_into().unwrap(), 0, 0);
println!("start kyoku end");
let mut is_agari = false;
for _i in 0..18 {
let mut tsumohai_num: usize;
{
let state = &mut G_STATE;
state.tsumo(play_log);
tsumohai_num = state.players[state.teban as usize]
.tsumohai
.pai_num
.try_into()
.unwrap();
}
ensure!(args.len() >= 2, "usage: {} DLLPath", args[0]);
let ret: u32 = func(inst, MJPI_SUTEHAI.try_into().unwrap(), tsumohai_num, 0)
.try_into()
.unwrap();
let index = ret & 0x3F;
let flag = ret & 0xFF80;
// println!("ret = {} flag = {:04x}", index, flag);
{
let state = &mut G_STATE;
/*
{
let player = &state.players[state.teban as usize];
for p in &player.tehai {
print!("{}", p);
}
print!("{}", player.tsumohai);
let shanten = PaiState::from(&player.tehai).get_shanten(0);
println!(" シャンテン数 {}\r", shanten);
}
*/
if flag == MJPIR_SUTEHAI {
state.sutehai(play_log, index as usize, false);
} else if flag == MJPIR_REACH {
state.sutehai(play_log, index as usize, true);
} else if flag == MJPIR_TSUMO {
let score: [i32; 4] = [0, 0, 0, 0];
println!("agari!!!");
let agari_r = state.tsumo_agari(play_log);
match agari_r {
Ok(agari) => {
println!("{:?}", agari.yaku);
}
Err(e) => {
println!("{:?}", e);
}
}
let path = PathBuf::from(&args[1]);
is_agari = true;
func(
inst,
MJPI_ENDKYOKU.try_into().unwrap(),
MJEK_RYUKYOKU.try_into().unwrap(),
std::mem::transmute(score.as_ptr()),
);
break;
}
}
}
load_ai(&path);
if !is_agari {
println!("流局(;;)");
let score: [i32; 4] = [-3000, 0, 0, 0];
func(
inst,
MJPI_ENDKYOKU.try_into().unwrap(),
MJEK_RYUKYOKU.try_into().unwrap(),
std::mem::transmute(score.as_ptr()),
);
let state = &mut G_STATE;
state.nagare(play_log);
}
}
unsafe fn experiment(func: MJPInterfaceFuncP, inst: *mut c_void, play_log: &mut play_log::PlayLog) {
{
let state = &mut G_STATE;
state.start(play_log);
}
func(inst, MJPI_STARTKYOKU.try_into().unwrap(), 0, 0);
#[cfg(debug_assertions)]
println!("start kyoku end");
let mut is_agari = false;
for _i in 0..18 {
let mut tsumohai_num: usize;
{
let state = &mut G_STATE;
state.tsumo(play_log);
tsumohai_num = state.players[state.teban as usize]
.tsumohai
.pai_num
.try_into()
.unwrap();
}
let ret: u32 = func(inst, MJPI_SUTEHAI.try_into().unwrap(), tsumohai_num, 0)
.try_into()
.unwrap();
let index = ret & 0x3F;
let flag = ret & 0xFF80;
// println!("ret = {} flag = {:04x}", index, flag);
{
let state = &mut G_STATE;
/*
{
let player = &state.players[state.teban as usize];
for p in &player.tehai {
print!("{}", p);
}
print!("{}", player.tsumohai);
let shanten = PaiState::from(&player.tehai).get_shanten(0);
println!(" シャンテン数 {}\r", shanten);
}
*/
if flag == MJPIR_SUTEHAI {
state.sutehai(play_log, index as usize, false);
} else if flag == MJPIR_REACH {
state.sutehai(play_log, index as usize, true);
} else if flag == MJPIR_TSUMO {
let score: [i32; 4] = [0, 0, 0, 0];
#[cfg(debug_assertions)]
println!("agari!!!");
let agari_r = state.tsumo_agari(play_log);
match agari_r {
Ok(agari) => {
println!("{:?}", agari.yaku);
}
Err(e) => {
println!("{:?}", e);
}
}
is_agari = true;
func(
inst,
MJPI_ENDKYOKU.try_into().unwrap(),
MJEK_RYUKYOKU.try_into().unwrap(),
std::mem::transmute(score.as_ptr()),
);
break;
}
}
}
if !is_agari {
#[cfg(debug_assertions)]
println!("流局(;;)");
let score: [i32; 4] = [-3000, 0, 0, 0];
func(
inst,
MJPI_ENDKYOKU.try_into().unwrap(),
MJEK_RYUKYOKU.try_into().unwrap(),
std::mem::transmute(score.as_ptr()),
);
let state = &mut G_STATE;
state.nagare(play_log);
}
}

@kackyt kackyt merged commit f096bf3 into main Feb 16, 2024
1 check passed
@kackyt kackyt deleted the feature/riichi-play branch February 16, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant