Phase 7 (Core): chemistry v2, expanded card pool & search filters
CI / Build, lint & test (push) Failing after 1m46s
CI / Build, lint & test (push) Failing after 1m46s
- Chemistry v2: FUT-style link scoring with per-player breakdown (club +3/link cap 6, league +1/link cap 4, nation +1/link cap 3; player cap 10, team cap 100); chemistry response now includes per-player breakdown with club/league/nation link counts and pts - Card pool: 34 new cards across Premier League, La Liga, Bundesliga with overlapping clubs/nations for meaningful chemistry testing - Card search: extended GET /cards with nation, league, club, min_overall, max_overall, limit query params; results sorted by overall descending - Match opponent: added "ultimate" difficulty band (85+ OVR); random formation selection from 6 tactical formations; falls back to lower OVR pool when not enough cards at the requested band - Tests: 9 new integration tests (28 total, all passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,73 +9,70 @@ use crate::{
|
||||
};
|
||||
use rand::{seq::SliceRandom, Rng};
|
||||
|
||||
const FORMATIONS: &[&str] = &[
|
||||
"4-3-3", "4-4-2", "4-2-3-1", "4-1-2-1-2", "3-5-2", "5-3-2",
|
||||
];
|
||||
|
||||
/// Generate a random AI opponent squad for Squad Battles.
|
||||
///
|
||||
/// Difficulty bands:
|
||||
/// beginner — overall 55+ (same as "any")
|
||||
/// professional — overall 70+
|
||||
/// world_class — overall 78+
|
||||
/// legendary — overall 85+
|
||||
/// ultimate — overall 90+
|
||||
pub fn generate_opponent(card_db: &CardDb, difficulty: &str) -> serde_json::Value {
|
||||
let (min_overall, names): (u8, &[&str]) = match difficulty {
|
||||
"professional" => (
|
||||
70,
|
||||
&[
|
||||
"Athletic CF",
|
||||
"City Wanderers",
|
||||
"The Rovers",
|
||||
"United Select",
|
||||
"Blue Stars FC",
|
||||
],
|
||||
&["Athletic CF", "City Wanderers", "The Rovers", "United Select", "Blue Stars FC"],
|
||||
),
|
||||
"world_class" => (
|
||||
78,
|
||||
&[
|
||||
"Elite Stars FC",
|
||||
"Champions Select",
|
||||
"Premier XI",
|
||||
"Galaxy United",
|
||||
"Titan FC",
|
||||
],
|
||||
&["Elite Stars FC", "Champions Select", "Premier XI", "Galaxy United", "Titan FC"],
|
||||
),
|
||||
"legendary" => (
|
||||
85,
|
||||
&[
|
||||
"Legends United",
|
||||
"Ultimate XI",
|
||||
"Gold Standard FC",
|
||||
"The Icons",
|
||||
"Heritage FC",
|
||||
],
|
||||
&["Legends United", "Ultimate XI", "Gold Standard FC", "The Icons", "Heritage FC"],
|
||||
),
|
||||
"ultimate" => (
|
||||
90,
|
||||
&["Apex XI", "Pantheon FC", "Gods of FUT", "Invincibles Select", "Eternal XI"],
|
||||
),
|
||||
_ => (
|
||||
58,
|
||||
&[
|
||||
"Amateur Town FC",
|
||||
"Sunday League XI",
|
||||
"Park FC",
|
||||
"Village Stars",
|
||||
"Reserve XI",
|
||||
],
|
||||
55,
|
||||
&["Amateur Town FC", "Sunday League XI", "Park FC", "Village Stars", "Reserve XI"],
|
||||
),
|
||||
};
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let all = card_db.by_min_overall(min_overall);
|
||||
let mut indices: Vec<usize> = (0..all.len()).collect();
|
||||
|
||||
// Fall back to lower overall band if not enough cards at this difficulty
|
||||
let pool: Vec<_> = if all.len() >= 11 {
|
||||
all
|
||||
} else {
|
||||
card_db.by_min_overall(55)
|
||||
};
|
||||
|
||||
let mut indices: Vec<usize> = (0..pool.len()).collect();
|
||||
indices.shuffle(&mut rng);
|
||||
let cards: Vec<_> = indices
|
||||
.into_iter()
|
||||
.take(11)
|
||||
.map(|i| all[i].clone())
|
||||
.collect();
|
||||
let cards: Vec<_> = indices.into_iter().take(11).map(|i| pool[i].clone()).collect();
|
||||
|
||||
let squad_rating = if cards.is_empty() {
|
||||
0
|
||||
} else {
|
||||
cards.iter().map(|c| c.overall as i64).sum::<i64>() / cards.len() as i64
|
||||
};
|
||||
|
||||
let name = names[rng.gen_range(0..names.len())];
|
||||
let formation = FORMATIONS[rng.gen_range(0..FORMATIONS.len())];
|
||||
|
||||
serde_json::json!({
|
||||
"opponent_name": name,
|
||||
"difficulty": difficulty,
|
||||
"squad_rating": squad_rating,
|
||||
"formation": "4-4-2",
|
||||
"formation": formation,
|
||||
"cards": cards,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user