[Feature] Chemistry Calculation Engine #1

Open
opened 2026-06-26 05:05:25 +00:00 by funman300 · 0 comments
Owner

Overview

Implement FIFA-style team chemistry calculation for squads. Chemistry is a core FUT mechanic that rewards building squads around shared clubs, leagues, and nationalities.

Implementation Steps

1. Add chemistry types to src/models/chemistry.rs

pub struct ChemistryResult { pub total: u8, pub per_player: Vec<u8> }
pub struct ChemistryLink { pub a: usize, pub b: usize, pub strength: LinkStrength }
pub enum LinkStrength { Full, Half, None }

2. Implement link detection in src/services/chemistry.rs

pub fn calculate_chemistry(players: &[Player]) -> ChemistryResult

Rules:

  • Full link (3 chem): same club AND same nationality
  • Half link (2 chem): same league OR same nationality
  • No link (1 chem): no shared attribute
  • Each player starts at 1 chemistry; qualifying links add to it, clamped to max 3
  • Total team chemistry = sum of all player chem, max 33 (11 players × 3)
  • GK chemistry depends only on being in the GK slot

3. Add formation position bonus

  • Player in correct position (e.g. ST in ST slot): no penalty
  • Player in wrong position (e.g. CB in ST slot): −1 chemistry (min 1)

4. Wire into POST /squad response in src/routes/squad.rs

After saving the squad, compute chemistry and include it in the response:

{
  "squad": [...],
  "chemistry": {
    "total": 27,
    "per_player": [3, 3, 3, 2, 2, 3, 3, 3, 2, 1, 3]
  }
}

5. Wire into GET /squad response

Return the same chemistry block when reading the active squad.

6. Add GET /squad/chemistry convenience endpoint

Returns only the chemistry block without the full squad payload — useful for the bridge to call during squad edits.

7. Write tests in tests/chemistry.rs

  • 11 players same club → total chemistry 33
  • 11 players all different club/nation/league → total 11
  • Mixed squad with partial links → expected mid-range total
  • Player in wrong position slot → that player's chem reduced

Acceptance Criteria

  • calculate_chemistry function exists in src/services/chemistry.rs
  • POST /squad response includes chemistry block
  • GET /squad response includes chemistry block
  • GET /squad/chemistry endpoint returns chem-only payload
  • All chemistry tests pass
  • cargo clippy -- -D warnings passes
## Overview Implement FIFA-style team chemistry calculation for squads. Chemistry is a core FUT mechanic that rewards building squads around shared clubs, leagues, and nationalities. ## Implementation Steps ### 1. Add chemistry types to `src/models/chemistry.rs` ```rust pub struct ChemistryResult { pub total: u8, pub per_player: Vec<u8> } pub struct ChemistryLink { pub a: usize, pub b: usize, pub strength: LinkStrength } pub enum LinkStrength { Full, Half, None } ``` ### 2. Implement link detection in `src/services/chemistry.rs` ```rust pub fn calculate_chemistry(players: &[Player]) -> ChemistryResult ``` Rules: - **Full link** (3 chem): same club AND same nationality - **Half link** (2 chem): same league OR same nationality - **No link** (1 chem): no shared attribute - Each player starts at 1 chemistry; qualifying links add to it, clamped to max 3 - Total team chemistry = sum of all player chem, max 33 (11 players × 3) - GK chemistry depends only on being in the GK slot ### 3. Add formation position bonus - Player in correct position (e.g. ST in ST slot): no penalty - Player in wrong position (e.g. CB in ST slot): −1 chemistry (min 1) ### 4. Wire into `POST /squad` response in `src/routes/squad.rs` After saving the squad, compute chemistry and include it in the response: ```json { "squad": [...], "chemistry": { "total": 27, "per_player": [3, 3, 3, 2, 2, 3, 3, 3, 2, 1, 3] } } ``` ### 5. Wire into `GET /squad` response Return the same `chemistry` block when reading the active squad. ### 6. Add `GET /squad/chemistry` convenience endpoint Returns only the chemistry block without the full squad payload — useful for the bridge to call during squad edits. ### 7. Write tests in `tests/chemistry.rs` - 11 players same club → total chemistry 33 - 11 players all different club/nation/league → total 11 - Mixed squad with partial links → expected mid-range total - Player in wrong position slot → that player's chem reduced ## Acceptance Criteria - [ ] `calculate_chemistry` function exists in `src/services/chemistry.rs` - [ ] `POST /squad` response includes `chemistry` block - [ ] `GET /squad` response includes `chemistry` block - [ ] `GET /squad/chemistry` endpoint returns chem-only payload - [ ] All chemistry tests pass - [ ] `cargo clippy -- -D warnings` passes
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/OpenFUT-Core#1