Skip to content

feat: ルール細則に基づく順位計算モジュールの実装 - #25

Open
arumino-om wants to merge 3 commits into
developfrom
feature/#19_ranking_calculation
Open

feat: ルール細則に基づく順位計算モジュールの実装#25
arumino-om wants to merge 3 commits into
developfrom
feature/#19_ranking_calculation

Conversation

@arumino-om

@arumino-om arumino-om commented Aug 12, 2026

Copy link
Copy Markdown
Member

概要

chros-score に、ルール細則に従って順位を計算するモジュールを追加しました。

対戦結果の配列を受け取り、試合の勝敗判定と順位表を返します。

  • src/score_api/ranking/models.py — 入出力モデルと勝因の定義
  • src/score_api/ranking/calculator.py — 試合判定と順位表の組み立て
  • POST /ranking — APIエンドポイント

入力

[
  { "hot": "player1", "cool": "player2", "winner": "hot",  "reason": "put" },
  { "hot": "player2", "cool": "player1", "winner": "cool", "reason": "item" }
]
フィールド 内容
hot / cool 各サイドのユーザー名(リクエスト内で一意なID)
winner hot / cool / draw
reason self_destruct / put / itemdraw のときは省略

reasonLostConnecttimeoutアイテム数優勢 などの表記ゆれも受け付けます。

判定ロジック

  1. 試合の組み立て — 「試合=先攻後攻を入れ替えて1度ずつ対戦」(0. 用語集)に従い、同じ組み合わせの対戦が2つ揃った時点で1試合として確定します。
  2. 勝敗 — 1-3 の重みづけ(自滅 > Put勝ち > アイテム数優勢)順の辞書式比較で判定します。「Put勝ち1つ」は「アイテム数優勢2つ」に優先します。
  3. 再試合 — 並んだ場合は引き分けとし rematch_required を立てます。同じ組み合わせの試合が後続にあればそれを再試合とみなし、前の引き分け試合を voided にして集計から除外します(1-4)。
  4. 順位 — 決着した試合のみを集計し、①試合勝利数 ②勝因の重み順の辞書式比較 で比較します。並べば同順位(1, 1, 3 方式)。

出力

standings(順位表)と matches(試合ごとの判定結果)を返します。判定の補足は自然言語ではなくコードで返すため、呼び出し側でそのまま分岐できます。

code rule 意味
score_tied 1-3 2対戦の対戦スコアが並んだ
rematch_held 1-4 再試合が行われたためこの試合結果は無効
bouts_missing 0 試合を構成する対戦が不足している
sides_not_swapped 0 2対戦で先攻・後攻が入れ替わっていない

細則に無いため補った点(要確認)

  • 再試合かどうかは配列の順序から判断するため、入力配列は試合の実施順である必要があります。
  • 未消化の再試合は勝敗に算入せず、pending_rematches として別途カウントします。

テスト

chros-scorepytest(13件パス)。pytest / httpx はランタイム依存に含めていないため、poetry.lock は変更していません。

Refs #19

🤖 Generated with Claude Code

arumino-om and others added 3 commits August 12, 2026 22:18
対戦結果の配列から試合の勝敗を判定し、順位表を返す。
先攻・後攻を入れ替えた2対戦を1試合として扱い、勝因の重み
(自滅 > Put勝ち > アイテム数優勢) 順の辞書式比較で勝敗を決める。
引き分けは再試合が必要な試合として印を付け、同じ組み合わせの
後続試合が再試合として行われていれば元の結果を無効にする。

POST /ranking で順位表を取得できる。

Refs #19

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
順位計算の仕様と、ルール細則に無いため補った点を記載した。
あわせて .gitignore の __pycache__ のタイポを修正した。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@arumino-om arumino-om self-assigned this Aug 12, 2026

@amemya amemya left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

頓珍漢なこと言っていたらごめんなさい

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
[tool.poetry.group.dev.dependencies]
pytest = ">=8.0,<9.0"
httpx = ">=0.28.0,<0.29.0"

テスト関連はdevグループの依存関係に追加するのがスムーズになるかなと思います

Comment thread chros-score/README.md
Comment on lines +146 to +151
pytest と httpx はランタイム依存に含めていないため、個別に入れる。

```bash
pip install pytest httpx
pytest
```

@amemya amemya Aug 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
pytest と httpx はランタイム依存に含めていないため、個別に入れる。
```bash
pip install pytest httpx
pytest
```
```bash
poetry run pytest
```

Poetryを利用しているのであればPoetryが管理するvenvに対して直接pip installするのは本来避けるべきパターンです
前述した変更を取り入れる場合はこちらも要修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants