我来为您创建一个统计犯规战术阻止反击次数的Java案例,这个程序将模拟足球比赛中防守方通过战术犯规阻止对方快速反击的场景。

import java.util.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 足球比赛犯规战术统计系统
* 用于统计比赛中通过战术犯规阻止反击的次数
*/
public class FoulTacticsCounter {
// 比赛信息
private static class Match {
String homeTeam;
String awayTeam;
LocalDateTime matchTime;
List<FoulEvent> fouls;
Match(String home, String away) {
this.homeTeam = home;
this.awayTeam = away;
this.matchTime = LocalDateTime.now();
this.fouls = new ArrayList<>();
}
}
// 犯规事件
private static class FoulEvent {
String playerName;
String team;
int minute;
String opponentPlayer;
String description;
boolean tacticalFoul; // 是否是战术犯规
boolean stoppedCounter; // 是否阻止了反击
FoulEvent(String player, String teamName, int min, String opp, String desc) {
this.playerName = player;
this.team = teamName;
this.minute = min;
this.opponentPlayer = opp;
this.description = desc;
}
}
// 统计结果类
private static class Statistics {
int totalFouls;
int tacticalFouls;
int counterStopped;
int counterNotStopped;
Map<String, Integer> playerTacticalFouls;
Map<Integer, Integer> minuteDistribution;
Statistics() {
playerTacticalFouls = new HashMap<>();
minuteDistribution = new TreeMap<>();
}
void printReport() {
System.out.println("\n=============== 战术犯规统计报告 ===============");
System.out.println("总犯规次数: " + totalFouls);
System.out.println("战术犯规次数: " + tacticalFouls);
System.out.println("成功阻止反击次数: " + counterStopped);
System.out.println("未成功阻止反击次数: " + counterNotStopped);
System.out.println("阻止反击成功率: " +
(tacticalFouls > 0 ? (counterStopped * 100.0 / tacticalFouls) : 0) + "%");
System.out.println("\n--- 球员战术犯规统计 ---");
playerTacticalFouls.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
.forEach(entry ->
System.out.println(entry.getKey() + ": " + entry.getValue() + "次"));
System.out.println("\n--- 时间分布(按15分钟分段) ---");
minuteDistribution.forEach((period, count) ->
System.out.println(getPeriodName(period) + ": " + count + "次"));
System.out.println("=============================================");
}
private String getPeriodName(int period) {
String[] periods = {"0-15分", "16-30分", "31-45分", "46-60分",
"61-75分", "76-90分", "加时赛"};
return periods[Math.min(period, 6)];
}
}
private Match match;
private Statistics stats;
private Random random;
public FoulTacticsCounter() {
this.stats = new Statistics();
this.random = new Random();
}
/**
* 模拟一场比赛
*/
public void simulateMatch(String homeTeam, String awayTeam) {
match = new Match(homeTeam, awayTeam);
System.out.println("比赛开始: " + homeTeam + " vs " + awayTeam);
System.out.println("比赛时间: " +
match.matchTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
// 模拟90分钟的比赛
for (int minute = 1; minute <= 90; minute++) {
// 随机生成犯规事件(约每2分钟可能有一次)
if (random.nextInt(100) < 15) { // 15%的概率每分钟发生犯规
generateFoul(minute);
}
}
// 生成统计数据
calculateStatistics();
// 输出报告
stats.printReport();
}
/**
* 生成一次犯规事件
*/
private void generateFoul(int minute) {
String[] homePlayers = {"张伟", "李强", "王磊", "赵明", "刘洋", "陈杰"};
String[] awayPlayers = {"John", "Mike", "David", "Chris", "Kevin", "Tom"};
boolean isHomeTeam = random.nextBoolean();
String foulingPlayer = isHomeTeam ?
homePlayers[random.nextInt(homePlayers.length)] :
awayPlayers[random.nextInt(awayPlayers.length)];
String fouledPlayer = isHomeTeam ?
awayPlayers[random.nextInt(awayPlayers.length)] :
homePlayers[random.nextInt(homePlayers.length)];
String teamName = isHomeTeam ? match.homeTeam : match.awayTeam;
// 创建犯规事件
FoulEvent foul = new FoulEvent(
foulingPlayer,
teamName,
minute,
fouledPlayer,
generateFoulDescription()
);
// 判断是否战术犯规(约60%的犯规是战术犯规)
foul.tacticalFoul = random.nextDouble() < 0.6;
if (foul.tacticalFoul) {
// 判断是否成功阻止反击(约75%的战术犯规能成功阻止)
foul.stoppedCounter = random.nextDouble() < 0.75;
System.out.printf("第%d分钟 - [战术犯规] %s的《%s》对《%s》犯规!%s%n",
minute, teamName, foulingPlayer, fouledPlayer,
foul.stoppedCounter ? "成功阻止反击!" : "未能阻止反击,被对手继续进攻!");
} else {
foul.stoppedCounter = false;
System.out.printf("第%d分钟 - [普通犯规] %s的《%s》对《%s》犯规。%n",
minute, teamName, foulingPlayer, fouledPlayer);
}
match.fouls.add(foul);
}
/**
* 生成犯规描述
*/
private String generateFoulDescription() {
String[] descriptions = {
"拉拽球衣", "阻挡跑动路线", "从背后铲球", "手部推搡",
"张开手臂阻挡", "战术性绊倒", "身体冲撞"
};
return descriptions[random.nextInt(descriptions.length)];
}
/**
* 统计比赛数据
*/
private void calculateStatistics() {
stats.totalFouls = match.fouls.size();
for (FoulEvent foul : match.fouls) {
if (foul.tacticalFoul) {
stats.tacticalFouls++;
if (foul.stoppedCounter) {
stats.counterStopped++;
} else {
stats.counterNotStopped++;
}
// 统计球员数据
String playerKey = foul.playerName + "(" + foul.team + ")";
stats.playerTacticalFouls.merge(playerKey, 1, Integer::sum);
// 统计时间段
int period = Math.min((foul.minute - 1) / 15, 6);
stats.minuteDistribution.merge(period, 1, Integer::sum);
}
}
}
/**
* 主函数 - 运行模拟
*/
public static void main(String[] args) {
FoulTacticsCounter counter = new FoulTacticsCounter();
// 模拟一场英超风格的高强度比赛
counter.simulateMatch("曼联", "利物浦");
// 运行多次模拟以对比
System.out.println("\n\n=============== 对比分析:多场比赛统计 ===============");
runMultipleSimulations(3);
}
/**
* 运行多场比赛进行对比
*/
private static void runMultipleSimulations(int times) {
String[][] matches = {
{"曼城", "切尔西"},
{"巴萨", "皇马"},
{"拜仁", "多特蒙德"}
};
for (int i = 0; i < Math.min(times, matches.length); i++) {
System.out.println("\n--- 第" + (i+1) + "场比赛 ---");
FoulTacticsCounter counter = new FoulTacticsCounter();
counter.simulateMatch(matches[i][0], matches[i][1]);
}
}
/**
* 手动添加一场真实比赛的犯规记录
*/
public void addManualFoul(String player, String team, int minute,
String opponent, boolean tactical, boolean stoppedCounter) {
FoulEvent foul = new FoulEvent(player, team, minute, opponent, "手动录入");
foul.tacticalFoul = tactical;
foul.stoppedCounter = stoppedCounter;
if (match == null) {
match = new Match("主队", "客队");
}
match.fouls.add(foul);
}
}
核心功能说明:
- 实时统计:每场比赛自动记录每次犯规
- 智能识别:区分普通犯规和战术犯规
- 效果评估:判断战术犯规是否成功阻止了反击
- 详细报告:生成多维度的统计数据
使用方法:
public class TestFoulCounter {
public static void main(String[] args) {
FoulTacticsCounter counter = new FoulTacticsCounter();
// 方式1:自动模拟比赛
counter.simulateMatch("巴塞罗那", "皇家马德里");
// 方式2:手动添加数据
counter.addManualFoul("卡塞米罗", "皇家马德里", 63, "梅西", true, true);
counter.addManualFoul("佩佩", "皇家马德里", 78, "内马尔", true, false);
// 生成统计报告
counter.generateReport();
}
}
输出示例:
比赛开始: 曼联 vs 利物浦
第12分钟 - [战术犯规] 曼联的《李强》对《David》犯规!成功阻止反击!
第25分钟 - [普通犯规] 利物浦的《Mike》对《张伟》犯规。
...
=============== 战术犯规统计报告 ===============
总犯规次数: 14
战术犯规次数: 8
成功阻止反击次数: 6
未成功阻止反击次数: 2
阻止反击成功率: 75.0%
--- 球员战术犯规统计 ---
李强(曼联): 2次
Mike(利物浦): 2次
...
这个统计系统能够帮助教练组分析:
- 球队的战术纪律性
- 关键球员的防守习惯
- 比赛关键时刻的战术决策
- 战术犯规的性价比评估
版权声明: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直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播