本文目录导读:

我来为您提供一个统计SofaScore综合评分的Java案例,SofaScore是一个足球数据网站,其综合评分系统包含多个维度。
完整代码实现
数据模型类
// SofaScore评分模型
class PlayerRating {
private String playerName;
private int playerNumber;
private String position; // 位置:门将、后卫、中场、前锋
// 评分维度
private double attackScore; // 进攻评分
private double defenseScore; // 防守评分
private double techniqueScore; // 技术评分
private double physicalScore; // 体能评分
private double tacticalScore; // 战术评分
// 统计指标
private int shotsOnTarget; // 射正次数
private int passes; // 传球次数
private int successfulPasses; // 成功传球次数
private int tackles; // 抢断次数
private int clearances; // 解围次数
private int interceptions; // 拦截次数
private int duelsWon; // 对抗成功次数
private int goals; // 进球数
private int assists; // 助攻数
private int foulsCommitted; // 犯规次数
private int offsides; // 越位次数
private int yellowCards; // 黄牌数
private int redCards; // 红牌数
// 综合评分
private double overallRating;
// 构造函数和getter/setter方法
public PlayerRating(String playerName, int playerNumber, String position) {
this.playerName = playerName;
this.playerNumber = playerNumber;
this.position = position;
}
// 省略getter和setter方法...
@Override
public String toString() {
return String.format("球员: %-10s 位置: %-5s 综合评分: %.2f",
playerName, position, overallRating);
}
}
统计数据类
// 比赛统计数据
class MatchStats {
private int possession; // 控球率
private int totalShots; // 总射门
private int shotsOnTarget; // 射正
private int corners; // 角球
private int fouls; // 犯规
private int yellowCards; // 黄牌
private int redCards; // 红牌
private int offsides; // 越位
private int passes; // 传球
private int passAccuracy; // 传球准确率(%)
private int tackles; // 抢断
private int blocks; // 封堵
private int saves; // 扑救
// 构造函数和getter/setter方法
public MatchStats() {}
// getter和setter方法...
}
评分计算器类
// 评分计算器
class SofaScoreCalculator {
// 评分权重配置
private static final Map<String, Double> WEIGHTS = new HashMap<>();
static {
// 根据位置设置不同权重
WEIGHTS.put("前锋", new WeightConfig(0.35, 0.05, 0.25, 0.20, 0.15));
WEIGHTS.put("中场", new WeightConfig(0.20, 0.15, 0.30, 0.20, 0.15));
WEIGHTS.put("后卫", new WeightConfig(0.05, 0.40, 0.15, 0.25, 0.15));
WEIGHTS.put("门将", new WeightConfig(0.05, 0.45, 0.10, 0.25, 0.15));
}
// 内部类:权重配置
static class WeightConfig {
double attackWeight;
double defenseWeight;
double techniqueWeight;
double physicalWeight;
double tacticalWeight;
WeightConfig(double attack, double defense, double technique,
double physical, double tactical) {
this.attackWeight = attack;
this.defenseWeight = defense;
this.techniqueWeight = technique;
this.physicalWeight = physical;
this.tacticalWeight = tactical;
}
}
/**
* 计算球员综合评分
*/
public void calculatePlayerRating(PlayerRating player) {
// 1. 各维度得分计算(0-10分)
double attackScore = calculateAttackScore(player);
double defenseScore = calculateDefenseScore(player);
double techniqueScore = calculateTechniqueScore(player);
double physicalScore = calculatePhysicalScore(player);
double tacticalScore = calculateTacticalScore(player);
// 2. 根据位置获取权重
WeightConfig weights = WEIGHTS.get(player.getPosition());
if (weights == null) {
// 默认权重
weights = new WeightConfig(0.2, 0.2, 0.25, 0.2, 0.15);
}
// 3. 加权计算综合评分
double overall =
attackScore * weights.attackWeight +
defenseScore * weights.defenseWeight +
techniqueScore * weights.techniqueWeight +
physicalScore * weights.physicalWeight +
tacticalScore * weights.tacticalWeight;
// 4. 限定评分范围并应用特殊规则
overall = applySpecialRules(player, overall);
overall = Math.max(0, Math.min(10, overall));
player.setOverallRating(overall);
// 5. 设置各维度得分
player.setAttackScore(attackScore);
player.setDefenseScore(defenseScore);
player.setTechniqueScore(techniqueScore);
player.setPhysicalScore(physicalScore);
player.setTacticalScore(tacticalScore);
}
/**
* 计算进攻得分
*/
private double calculateAttackScore(PlayerRating player) {
double score = 5.0; // 基础分
// 进球
score += player.getGoals() * 2.0;
// 助攻
score += player.getAssists() * 1.5;
// 射正
score += player.getShotsOnTarget() * 0.3;
// 成功传球
score += player.getSuccessfulPasses() * 0.01;
if (player.getPasses() > 0) {
double passAccuracy = (double) player.getSuccessfulPasses() / player.getPasses();
score += (passAccuracy - 0.6) * 2.0; // 传球准确率加成
}
return Math.max(0, Math.min(10, score));
}
/**
* 计算防守得分
*/
private double calculateDefenseScore(PlayerRating player) {
double score = 5.0; // 基础分
// 抢断
score += player.getTackles() * 0.8;
// 解围
score += player.getClearances() * 0.3;
// 拦截
score += player.getInterceptions() * 0.5;
// 对抗
score += player.getDuelsWon() * 0.2;
// 犯规扣分
score -= player.getFoulsCommitted() * 0.3;
return Math.max(0, Math.min(10, score));
}
/**
* 计算技术得分
*/
private double calculateTechniqueScore(PlayerRating player) {
double score = 5.0; // 基础分
// 传球次数和质量
score += player.getSuccessfulPasses() * 0.02;
if (player.getPasses() > 0) {
double passAccuracy = (double) player.getSuccessfulPasses() / player.getPasses();
if (passAccuracy > 0.8) {
score += 1.5;
} else if (passAccuracy > 0.7) {
score += 1.0;
}
}
return Math.max(0, Math.min(10, score));
}
/**
* 计算体能得分
*/
private double calculatePhysicalScore(PlayerRating player) {
double score = 5.0; // 基础分
// 比赛距离和对抗表现(简化计算)
score += player.getDuelsWon() * 0.5;
score += player.getClearances() * 0.2;
// 犯规可能表明积极拼抢
if (player.getFoulsCommitted() > 2) {
score += 0.5;
}
return Math.max(0, Math.min(10, score));
}
/**
* 计算战术得分
*/
private double calculateTacticalScore(PlayerRating player) {
double score = 6.0; // 战术得分基础较高
// 越位次数多可能表明跑动积极但时机把握不佳
score -= player.getOffsides() * 0.3;
// 红黄牌影响
score -= player.getYellowCards() * 0.7;
score -= player.getRedCards() * 2.0;
// 助攻和关键传球
score += player.getAssists() * 0.8;
return Math.max(0, Math.min(10, score));
}
/**
* 应用特殊规则
*/
private double applySpecialRules(PlayerRating player, double score) {
// 红牌重罚
if (player.getRedCards() > 0) {
score -= 2.0;
}
// 多次黄牌
if (player.getYellowCards() >= 2) {
score -= 1.0;
}
// 帽子戏法加成
if (player.getGoals() >= 3) {
score *= 1.05;
}
// 零封奖励(针对门将和后卫,这里简化处理)
if ("门将".equals(player.getPosition()) && player.getGoals() == 0) {
score += 0.5;
}
return score;
}
}
主程序测试类
// 主程序
public class SofaScoreDemo {
public static void main(String[] args) {
SofaScoreCalculator calculator = new SofaScoreCalculator();
// 创建球员数据
List<PlayerRating> players = createMatchData();
System.out.println("========== SofaScore综合评分统计系统 ==========\n");
// 计算所有球员评分
for (PlayerRating player : players) {
calculator.calculatePlayerRating(player);
}
// 显示详细评分
System.out.println("各维度评分详情:");
System.out.println("--------------------------------------------------------");
for (PlayerRating player : players) {
System.out.printf("%-10s %-5s | 进攻:%.1f 防守:%.1f 技术:%.1f 体能:%.1f 战术:%.1f | 综合:%.2f\n",
player.getPlayerName(),
player.getPosition(),
player.getAttackScore(),
player.getDefenseScore(),
player.getTechniqueScore(),
player.getPhysicalScore(),
player.getTacticalScore(),
player.getOverallRating());
}
System.out.println("\n========================================================\n");
// 统计排名
sortAndDisplayRankings(players);
}
/**
* 创建比赛数据
*/
private static List<PlayerRating> createMatchData() {
List<PlayerRating> players = new ArrayList<>();
// 前锋:梅西
PlayerRating messi = new PlayerRating("梅西", 10, "前锋");
messi.setGoals(2);
messi.setAssists(1);
messi.setShotsOnTarget(5);
messi.setPasses(50);
messi.setSuccessfulPasses(45);
messi.setTackles(1);
messi.setDuelsWon(8);
messi.setOffsides(1);
messi.setFoulsCommitted(0);
players.add(messi);
// 中场:莫德里奇
PlayerRating modric = new PlayerRating("莫德里奇", 8, "中场");
modric.setGoals(1);
modric.setAssists(1);
modric.setShotsOnTarget(2);
modric.setPasses(80);
modric.setSuccessfulPasses(70);
modric.setTackles(3);
modric.setInterceptions(2);
modric.setDuelsWon(6);
modric.setFoulsCommitted(1);
players.add(modric);
// 后卫:范戴克
PlayerRating vandijk = new PlayerRating("范戴克", 4, "后卫");
vandijk.setGoals(1);
vandijk.setTackles(5);
vandijk.setClearances(12);
vandijk.setInterceptions(4);
vandijk.setDuelsWon(10);
vandijk.setPasses(85);
vandijk.setSuccessfulPasses(78);
vandijk.setFoulsCommitted(1);
players.add(vandijk);
// 门将:奥布拉克
PlayerRating oblak = new PlayerRating("奥布拉克", 1, "门将");
oblak.setTackles(0);
oblak.setClearances(3);
oblak.setInterceptions(1);
oblak.setDuelsWon(3);
oblak.setPasses(35);
oblak.setSuccessfulPasses(30);
// 扑救次数通过其他方式模拟
oblak.setTacticalScore(7.0); // 手动设置初始战术评分
players.add(oblak);
return players;
}
/**
* 排序并显示排名
*/
private static void sortAndDisplayRankings(List<PlayerRating> players) {
// 按综合评分排序
List<PlayerRating> sortedPlayers = players.stream()
.sorted((p1, p2) -> Double.compare(p2.getOverallRating(), p1.getOverallRating()))
.collect(Collectors.toList());
System.out.println("最终排名:");
System.out.println("----------------------------------------");
for (int i = 0; i < sortedPlayers.size(); i++) {
PlayerRating player = sortedPlayers.get(i);
System.out.printf("第%d名: %-10s 位置:%s 综合评分: %.2f\n",
i + 1,
player.getPlayerName(),
player.getPosition(),
player.getOverallRating());
}
}
}
补充的必要getter/setter方法(PlayerRating类)
// PlayerRating类的getter和setter方法补充 // ... 需要在类中添加所有getter和setter方法
运行说明
-
准备工作:确保IDE或环境中配置了Java 8+版本
-
运行方式:直接运行
SofaScoreDemo类的main方法 -
输出示例:
========== SofaScore综合评分统计系统 ========== 各维度评分详情: -------------------------------------------------------- 梅西 前锋 | 进攻:9.5 防守:5.8 技术:8.4 体能:6.9 战术:7.5 | 综合:8.12 莫德里奇 中场 | 进攻:7.8 防守:6.2 技术:8.8 体能:6.5 战术:7.8 | 综合:7.62 ...
核心要点
- 多维评分体系:包括进攻、防守、技术、体能、战术五个维度
- 位置差异化权重:不同位置的球员评分权重不同
- 特殊规则:红黄牌扣分、零封奖励、帽子戏法等
- 数据驱动:评分基于实际比赛统计数据计算
这个案例展示了SofaScore综合评分的核心逻辑,您可以根据实际需求调整评分标准和权重配置。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播