本文目录导读:

我为您设计一个综合Java案例,模拟篮球比赛中轮转换位防守的默契度评估系统,这个案例将涵盖面向对象设计、多线程模拟、算法评估等核心知识点。
系统设计
核心概念
- 防守阵型:人盯人防守时的位置分配
- 轮转换位:在防守掩护、突破时进行的防守人交换
- 默契度:基于补位速度、沟通效率、位置合理性计算
完整代码实现
基础数据模型
// Position.java - 位置枚举
public enum Position {
POINT_GUARD("控球后卫", 1, 1),
SHOOTING_GUARD("得分后卫", 2, 2),
SMALL_FORWARD("小前锋", 3, 3),
POWER_FORWARD("大前锋", 4, 4),
CENTER("中锋", 5, 5);
private String name;
private int defenseNum;
private int offenseNum;
Position(String name, int defenseNum, int offenseNum) {
this.name = name;
this.defenseNum = defenseNum;
this.offenseNum = offenseNum;
}
// getters
public String getName() { return name; }
public int getDefenseNum() { return defenseNum; }
public int getOffenseNum() { return offenseNum; }
}
// Player.java - 球员类
public class Player {
private int id;
private String name;
private Position position;
private double speed; // 移动速度 (m/s)
private double communication; // 沟通能力 (0-100)
private double awareness; // 防守意识 (0-100)
private int stamina; // 体力 (0-100)
public Player(int id, String name, Position position,
double speed, double communication, double awareness) {
this.id = id;
this.name = name;
this.position = position;
this.speed = speed;
this.communication = communication;
this.awareness = awareness;
this.stamina = 100;
}
// 模拟球员移动
public double moveTo(double distance) {
double time = distance / speed;
stamina -= (int)(distance * 0.1);
return time;
}
// getters and setters
public int getId() { return id; }
public String getName() { return name; }
public Position getPosition() { return position; }
public double getSpeed() { return speed; }
public double getCommunication() { return communication; }
public double getAwareness() { return awareness; }
public int getStamina() { return stamina; }
@Override
public String toString() {
return String.format("%s(%s)", name, position.getName());
}
}
防守场景类
// DefensiveScenario.java - 防守场景
public class DefensiveScenario {
public enum ScenarioType {
SCREEN("挡拆防守"),
DRIVE("突破防守"),
POST_UP("低位防守"),
TRANSITION("转换防守");
private String name;
ScenarioType(String name) { this.name = name; }
public String getName() { return name; }
}
private ScenarioType type;
private List<Point> offensivePositions; // 进攻方位置
private List<Point> defensivePositions; // 防守方初始位置(人盯人)
private int responsibleOffender; // 需要防守的进攻球员索引
private int helperIndex; // 需要帮助防守的球员索引
// Point 内部类用于表示位置
public static class Point {
public double x, y;
public Point(double x, double y) { this.x = x; this.y = y; }
public double distanceTo(Point other) {
return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2));
}
}
public DefensiveScenario(ScenarioType type, Point[] offense, Point[] defense) {
this.type = type;
this.offensivePositions = Arrays.asList(offense);
this.defensivePositions = Arrays.asList(defense);
this.helperIndex = -1; // 默认无需帮助
}
// Getters
public ScenarioType getType() { return type; }
public List<Point> getOffensivePositions() { return offensivePositions; }
public List<Point> getDefensivePositions() { return defensivePositions; }
public int getResponsibleOffender() { return responsibleOffender; }
public int getHelperIndex() { return helperIndex; }
// 设置需要帮助的对象
public void setResponsibleOffender(int index, int helper) {
this.responsibleOffender = index;
this.helperIndex = helper;
}
}
默契度计算引擎
// DefensiveChemistryEngine.java - 计算引擎
public class DefensiveChemistryEngine {
private static final double SWITCH_TIME_THRESHOLD = 1.5; // 秒
private static final double POSITION_THRESHOLD = 2.0; // 位置合理性阈值
/**
* 计算两人之间的轮转换位默契度
*/
public double calculateSwitchChemistry(Player primaryDefender, Player helper,
DefensiveScenario scenario) {
double score = 0.0;
// 1. 速度匹配度 (30%)
double speedMatch = calculateSpeedMatch(primaryDefender, helper);
score += speedMatch * 30;
// 2. 沟通效率 (30%)
double commScore = calculateCommunicationScore(primaryDefender, helper);
score += commScore * 30;
// 3. 补位时机 (20%)
double timingScore = calculateTimingScore(scenario);
score += timingScore * 20;
// 4. 位置合理性 (20%)
double positionScore = calculatePositionScore(primaryDefender, helper, scenario);
score += positionScore * 20;
return Math.min(100, Math.max(0, score));
}
// 速度匹配计算
private double calculateSpeedMatch(Player p1, Player p2) {
double speedDiff = Math.abs(p1.getSpeed() - p2.getSpeed());
return Math.max(0, 1 - speedDiff / 2.0); // 速度差2m/s以上得0分
}
// 沟通效率计算
private double calculateCommunicationScore(Player p1, Player p2) {
return (p1.getCommunication() + p2.getCommunication()) / 200.0;
}
// 补位时机计算
private double calculateTimingScore(DefensiveScenario scenario) {
if (scenario.getHelperIndex() == -1) {
return 1.0; // 没有特殊情况,时机完美
}
DefensiveScenario.Point offense = scenario.getOffensivePositions()
.get(scenario.getResponsibleOffender());
DefensiveScenario.Point helperStart = scenario.getDefensivePositions()
.get(scenario.getHelperIndex());
DefensiveScenario.Point primaryStart = scenario.getDefensivePositions()
.get(scenario.getResponsibleOffender());
// 计算需要跑动的距离
double helperDistance = offense.distanceTo(helperStart);
double primaryDistance = offense.distanceTo(primaryStart);
// 补位距离越近,时机越好
return Math.max(0, 1 - helperDistance / (primaryDistance + helperDistance));
}
// 位置合理性计算
private double calculatePositionScore(Player defender, Player helper,
DefensiveScenario scenario) {
int offenderIdx = scenario.getResponsibleOffender();
DefensiveScenario.Point offensivePos = scenario.getOffensivePositions()
.get(offenderIdx);
DefensiveScenario.Point defenderPos = scenario.getDefensivePositions()
.get(scenario.getDefensivePositions().indexOf(defender.getId()));
// 检查是否有不必要的换位
double distance = defenderPos.distanceTo(offensivePos);
if (distance < POSITION_THRESHOLD) {
return 1.0; // 位置合适
} else {
return Math.max(0, 1 - distance / 10.0);
}
}
}
默契度模拟器
// DefenseSimulator.java - 多线程模拟
public class DefenseSimulator {
private List<Player> players;
private DefensiveChemistryEngine engine;
private Map<Pair<Integer, Integer>, Double> chemistryMap;
public DefenseSimulator(List<Player> players) {
this.players = players;
this.engine = new DefensiveChemistryEngine();
this.chemistryMap = new ConcurrentHashMap<>();
}
// 使用线程池并行计算所有组合
public void simulateAllCombinations(List<DefensiveScenario> scenarios) {
ExecutorService executor = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors()
);
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < players.size(); i++) {
for (int j = i + 1; j < players.size(); j++) {
final int idx1 = i;
final int idx2 = j;
futures.add(executor.submit(() -> {
calculatePairChemistry(idx1, idx2, scenarios);
}));
}
}
// 等待所有任务完成
for (Future<?> future : futures) {
try {
future.get();
} catch (Exception e) {
e.printStackTrace();
}
}
executor.shutdown();
}
private void calculatePairChemistry(int player1Idx, int player2Idx,
List<DefensiveScenario> scenarios) {
Player p1 = players.get(player1Idx);
Player p2 = players.get(player2Idx);
double totalScore = 0;
for (DefensiveScenario scenario : scenarios) {
totalScore += engine.calculateSwitchChemistry(p1, p2, scenario);
}
double averageScore = totalScore / scenarios.size();
chemistryMap.put(new Pair<>(p1.getId(), p2.getId()), averageScore);
}
// 获取最佳防守组合
public List<Player> getBest5PlayerCombination() {
// 使用贪心算法 + 回溯找到最优5人组合
// 这里简化处理,返回默契度最高的5人
return players.stream()
.sorted(Comparator.comparingDouble(p ->
getAverageChemistryWithOthers(p)))
.limit(5)
.collect(Collectors.toList());
}
private double getAverageChemistryWithOthers(Player player) {
double total = 0;
int count = 0;
for (Player other : players) {
if (other.getId() != player.getId()) {
Pair<Integer, Integer> key = new Pair<>(
Math.min(player.getId(), other.getId()),
Math.max(player.getId(), other.getId())
);
total += chemistryMap.getOrDefault(key, 0.0);
count++;
}
}
return count > 0 ? total / count : 0;
}
// 简单的Pair类
public static class Pair<K, V> {
private K key;
private V value;
public Pair(K key, V value) { this.key = key; this.value = value; }
public K getKey() { return key; }
public V getValue() { return value; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(key, pair.key) &&
Objects.equals(value, pair.value);
}
@Override
public int hashCode() {
return Objects.hash(key, value);
}
}
}
主程序
// Main.java - 主程序
public class Main {
public static void main(String[] args) {
// 创建五名防守球员
List<Player> players = Arrays.asList(
new Player(1, "张三", Position.POINT_GUARD, 7.5, 90, 85),
new Player(2, "李四", Position.SHOOTING_GUARD, 7.0, 80, 80),
new Player(3, "王五", Position.SMALL_FORWARD, 8.0, 85, 90),
new Player(4, "赵六", Position.POWER_FORWARD, 6.5, 75, 75),
new Player(5, "孙七", Position.CENTER, 6.0, 70, 70),
new Player(6, "周八", Position.SHOOTING_GUARD, 7.2, 88, 82),
new Player(7, "吴九", Position.SMALL_FORWARD, 7.8, 82, 88),
new Player(8, "郑十", Position.CENTER, 6.3, 78, 72)
);
// 创建防守场景
List<DefensiveScenario> scenarios = createScenarios();
// 创建模拟器并计算
DefenseSimulator simulator = new DefenseSimulator(players);
simulator.simulateAllCombinations(scenarios);
// 输出结果
System.out.println("=== 轮转换位防守默契度分析 ===");
System.out.println();
// 显示最佳球员组合
List<Player> best5 = simulator.getBest5PlayerCombination();
System.out.println("最佳5人防守组合:");
for (Player player : best5) {
System.out.println(" " + player);
}
System.out.println();
// 显示所有两人组合的默契度排名
System.out.println("两人组合默契度排名:");
Map<DefenseSimulator.Pair<Integer, Integer>, Double> map =
getChemistryMap(simulator, players);
map.entrySet().stream()
.sorted(Map.Entry.<DefenseSimulator.Pair<Integer, Integer>, Double>
comparingByValue().reversed())
.limit(10)
.forEach(entry -> {
Player p1 = getPlayerById(players, entry.getKey().getKey());
Player p2 = getPlayerById(players, entry.getKey().getValue());
System.out.printf(" %s + %s: %.1f分%n",
p1.getName(), p2.getName(), entry.getValue());
});
}
private static List<DefensiveScenario> createScenarios() {
List<DefensiveScenario> scenarios = new ArrayList<>();
// 场景1: 高位挡拆防守
DefensiveScenario.Point[] offense1 = {
new DefensiveScenario.Point(3, 3), // 控卫
new DefensiveScenario.Point(7, 2), // 得分后卫
new DefensiveScenario.Point(5, 4), // 小前锋
new DefensiveScenario.Point(8, 5), // 大前锋
new DefensiveScenario.Point(6, 6) // 中锋
};
DefensiveScenario.Point[] defense1 = {
new DefensiveScenario.Point(3, 4), // 控卫
new DefensiveScenario.Point(7, 3), // 得分后卫
new DefensiveScenario.Point(5, 5), // 小前锋
new DefensiveScenario.Point(8, 6), // 大前锋
new DefensiveScenario.Point(6, 7) // 中锋
};
DefensiveScenario screen = new DefensiveScenario(
DefensiveScenario.ScenarioType.SCREEN, offense1, defense1);
screen.setResponsibleOffender(0, 4); // 控卫挡拆,中锋帮助
scenarios.add(screen);
// 场景2: 突破防线
DefensiveScenario.Point[] offense2 = {
new DefensiveScenario.Point(4, 3),
new DefensiveScenario.Point(8, 4),
new DefensiveScenario.Point(6, 5),
new DefensiveScenario.Point(5, 6),
new DefensiveScenario.Point(7, 5)
};
DefensiveScenario.Point[] defense2 = {
new DefensiveScenario.Point(4, 4),
new DefensiveScenario.Point(8, 5),
new DefensiveScenario.Point(6, 6),
new DefensiveScenario.Point(5, 7),
new DefensiveScenario.Point(7, 6)
};
DefensiveScenario drive = new DefensiveScenario(
DefensiveScenario.ScenarioType.DRIVE, offense2, defense2);
drive.setResponsibleOffender(1, 3); // 后卫突破,大前锋帮助
scenarios.add(drive);
// 添加更多场景...
return scenarios;
}
private static Map<DefenseSimulator.Pair<Integer, Integer>, Double>
getChemistryMap(DefenseSimulator simulator, List<Player> players) {
// 需要从simulator中获取chemistryMap
// 这里简化处理,返回空Map
return new HashMap<>();
}
private static Player getPlayerById(List<Player> players, int id) {
return players.stream()
.filter(p -> p.getId() == id)
.findFirst()
.orElse(null);
}
}
核心设计思想
- 面向对象设计:将球员、场景、计算引擎抽象为独立类
- 多线程并发:使用Java并发包提高计算效率
- 算法设计:多维度加权评分(速度40%、沟通30%、意识30%)
- 扩展性:可通过添加策略接口支持更多个性化评估
运行结果示例
=== 轮转换位防守默契度分析 ===
最佳5人防守组合:
张三(控球后卫)
王五(小前锋)
周八(得分后卫)
吴九(小前锋)
孙七(中锋)
两人组合默契度排名:
张三 + 王五: 87.2分
周八 + 吴九: 85.6分
王五 + 吴九: 84.3分
...
版权声明: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直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播