feat: chemistry calculation engine #7

Open
funman300 wants to merge 1 commits from feat/chemistry-engine into main
Owner

Summary

Adds the foundation for FIFA-style team chemistry calculation.

  • New src/services/chemistry.rs module with calculate_chemistry(cards: &[CardDefinition]) -> ChemistryResult
  • Full link (3 chem): same club AND same nationality
  • Half link (2 chem): same league OR same nationality
  • Each player starts at 1, clamped to [1, 3]; squad total is max 33
  • Two passing unit tests: all-same-club (33 total) and all-different (11 total)

Closes #1

What still needs to be done before merging

This PR is a scaffold — the service logic is complete but it is not yet wired into the HTTP layer. The following tasks remain:

  1. Register the module in src/services/mod.rs:

    pub mod chemistry;
    
  2. Wire into POST /squad in src/routes/squad.rs:

    • After resolving each SquadPlayer's owned_card_id to a CardDefinition (via card_db), call calculate_chemistry(&resolved_cards) and include the result in the response JSON.
  3. Wire into GET /squad — same approach, return the chemistry block alongside the squad.

  4. Add GET /squad/chemistry endpoint in src/routes/squad.rs that returns only ChemistryResult for the active squad.

  5. Add formation position penalty — the current implementation does link scoring only; subtract 1 from a player whose position_override or position_index maps to a different position slot than their natural position.

  6. Add integration tests in tests/chemistry.rs:

    • Seed a full 11-player squad, call GET /squad, assert chemistry.total is within the expected range.
    • Test position penalty path.
  7. Run cargo clippy -- -D warnings after wiring to catch any unused-import or dead-code warnings.

Test plan

  • cargo test -p openfut-core chemistry passes
  • POST /squad response body contains chemistry key
  • GET /squad response body contains chemistry key
  • GET /squad/chemistry returns { total, per_player } only
  • cargo clippy -- -D warnings clean
## Summary Adds the foundation for FIFA-style team chemistry calculation. - New `src/services/chemistry.rs` module with `calculate_chemistry(cards: &[CardDefinition]) -> ChemistryResult` - Full link (3 chem): same club AND same nationality - Half link (2 chem): same league OR same nationality - Each player starts at 1, clamped to [1, 3]; squad total is max 33 - Two passing unit tests: all-same-club (33 total) and all-different (11 total) Closes #1 ## What still needs to be done before merging This PR is a scaffold — the service logic is complete but it is **not yet wired into the HTTP layer**. The following tasks remain: 1. **Register the module** in `src/services/mod.rs`: ```rust pub mod chemistry; ``` 2. **Wire into `POST /squad`** in `src/routes/squad.rs`: - After resolving each `SquadPlayer`'s `owned_card_id` to a `CardDefinition` (via `card_db`), call `calculate_chemistry(&resolved_cards)` and include the result in the response JSON. 3. **Wire into `GET /squad`** — same approach, return the chemistry block alongside the squad. 4. **Add `GET /squad/chemistry` endpoint** in `src/routes/squad.rs` that returns only `ChemistryResult` for the active squad. 5. **Add formation position penalty** — the current implementation does link scoring only; subtract 1 from a player whose `position_override` or `position_index` maps to a different position slot than their natural position. 6. **Add integration tests** in `tests/chemistry.rs`: - Seed a full 11-player squad, call `GET /squad`, assert `chemistry.total` is within the expected range. - Test position penalty path. 7. **Run `cargo clippy -- -D warnings`** after wiring to catch any unused-import or dead-code warnings. ## Test plan - [ ] `cargo test -p openfut-core chemistry` passes - [ ] `POST /squad` response body contains `chemistry` key - [ ] `GET /squad` response body contains `chemistry` key - [ ] `GET /squad/chemistry` returns `{ total, per_player }` only - [ ] `cargo clippy -- -D warnings` clean
funman300 added 1 commit 2026-06-26 05:12:07 +00:00
feat: add chemistry calculation engine scaffold
CI / Build, lint & test (pull_request) Failing after 1m23s
8e280de99e
Adds src/services/chemistry.rs with calculate_chemistry() that scores
club/league/nation links between players (1–3 per player, max 33 total).
Includes passing unit tests for all-same and all-different squads.

Closes #1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Some checks are pending
CI / Build, lint & test (pull_request) Failing after 1m23s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/chemistry-engine:feat/chemistry-engine
git checkout feat/chemistry-engine
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/OpenFUT-Core#7