simulator 相关问题

模拟器是一种自动化模型,可捕获特定对象的基本逻辑和行为。一个好的模拟器允许调查对象的属性,探索“假设”场景,或将对象合并到景观交互对象中。模拟器设计通常涉及在已知或估计的分布,时间分片和状态机上运行概率引擎。实现通常是面向对象的。

我正在尝试创建一个足球联赛模拟器[关闭]

这是我的 Java 代码 包 com.alviss.football.sim; 导入 java.util.*; 公开课 LeagueSimulator { 私有 List 团队; 私有 int numMatches; 私人地图 这是我的 Java 代码 package com.alviss.football.sim; import java.util.*; public class LeagueSimulator { private List<String> teams; private int numMatches; private Map<String, Integer> matchesPlayedTable; private Map<String, Integer> matchesWonTable; private Map<String, Integer> matchesLostTable; private Map<String, Integer> matchesDrawnTable; private Map<String, Integer> goalsScoredTable; private Map<String, Integer> goalsConcededTable; private Map<String, Integer> goalDiffTable; private Map<String, Integer> pointsTable; public LeagueSimulator(List<String> teams, int numMatches) { this.teams = teams; this.numMatches = numMatches; this.matchesPlayedTable = new HashMap<String, Integer>(); this.matchesWonTable = new HashMap<String, Integer>(); this.matchesLostTable = new HashMap<String, Integer>(); this.matchesDrawnTable = new HashMap<String, Integer>(); this.goalsScoredTable = new HashMap<String, Integer>(); this.goalsConcededTable = new HashMap<String, Integer>(); this.goalDiffTable = new HashMap<String, Integer>(); this.pointsTable = new HashMap<String, Integer>(); // Initialize points, goals scored, and goals conceded for each team for (String team : teams) { matchesPlayedTable.put(team, 0); matchesWonTable.put(team, 0); matchesLostTable.put(team, 0); matchesDrawnTable.put(team, 0); goalsScoredTable.put(team, 0); goalsConcededTable.put(team, 0); goalDiffTable.put(team, 0); pointsTable.put(team, 0); } } public void simulateMatches() { int numRounds = numMatches / 2; List<String> playedFixtures = new ArrayList<String>(); Random random = new Random(); Scanner scanner = new Scanner(System.in); // Simulate matches for each round for (int round = 1; round <= numRounds; round++) { System.out.println("Matchday " + round + " Fixtures:"); // Shuffle the teams to randomize the fixtures Collections.shuffle(teams); // Play the fixtures for this round for (int i = 0; i < teams.size(); i += 2) { String homeTeam = teams.get(i); String awayTeam = teams.get(i + 1); // Check if this fixture has already been played String fixture = homeTeam + " vs " + awayTeam; if (playedFixtures.contains(fixture)) { continue; } // Print the fixture and get the user input for the score System.out.print(homeTeam + " vs " + awayTeam + ": "); int homeGoals = scanner.nextInt();int awayGoals = scanner.nextInt(); // Update the matches played, won, lost, drawn , goals scored & conceded, goal difference & points for each team matchesPlayedTable.put(homeTeam, matchesPlayedTable.get(homeTeam) + homeGoals); matchesPlayedTable.put(awayTeam, matchesPlayedTable.get(awayTeam) + awayGoals); matchesWonTable.put(homeTeam, matchesWonTable.get(homeTeam) + homeGoals); matchesWonTable.put(awayTeam, matchesWonTable.get(awayTeam) + awayGoals); matchesLostTable.put(homeTeam, matchesLostTable.get(homeTeam) + homeGoals); matchesLostTable.put(awayTeam, matchesLostTable.get(awayTeam) + awayGoals); matchesDrawnTable.put(homeTeam, matchesDrawnTable.get(homeTeam) + homeGoals); matchesDrawnTable.put(awayTeam, matchesDrawnTable.get(awayTeam) + awayGoals); goalsScoredTable.put(homeTeam, goalsScoredTable.get(homeTeam) + homeGoals); goalsScoredTable.put(awayTeam, goalsScoredTable.get(awayTeam) + awayGoals); goalsConcededTable.put(homeTeam, goalsConcededTable.get(homeTeam) + awayGoals); goalsConcededTable.put(awayTeam, goalsConcededTable.get(awayTeam) + homeGoals); goalDiffTable.put(homeTeam, goalDiffTable.get(homeTeam) + homeGoals); goalDiffTable.put(awayTeam, goalDiffTable.get(awayTeam) + awayGoals); pointsTable.put(homeTeam, pointsTable.get(homeTeam) + (homeGoals > awayGoals ? 3 : (homeGoals == awayGoals ? 1 : 0))); pointsTable.put(awayTeam, pointsTable.get(awayTeam) + (awayGoals > homeGoals ? 3 : (awayGoals == homeGoals ? 1 : 0))); // Add the fixture to the list of played fixtures playedFixtures.add(fixture); } } // Close the scanner scanner.close(); } public void printTable() { // Sort the teams by matches played, won, lost drawn, goals scored, goals conceded, goal difference & points List<String> sortedTeams = new ArrayList<String>(teams); Collections.sort(sortedTeams, (a, b) -> { int matchesPlayedCompare = Integer.compare(matchesPlayedTable.get(b), matchesPlayedTable.get(a)); if (matchesPlayedCompare != 0) { return matchesPlayedCompare; } int matchesWonCompare = Integer.compare(matchesWonTable.get(b), matchesWonTable.get(a)); if (matchesWonCompare != 0) { return matchesWonCompare; } int matchesLostCompare = Integer.compare(matchesLostTable.get(b), matchesLostTable.get(a)); if (matchesLostCompare != 0) { return matchesLostCompare; } int matchesDrawnCompare = Integer.compare(matchesDrawnTable.get(b), matchesDrawnTable.get(a)); if (matchesDrawnCompare != 0) { return matchesDrawnCompare; } int goalsScoredCompare = Integer.compare(goalsScoredTable.get(b), goalsScoredTable.get(a)); if (goalsScoredCompare != 0) { return goalsScoredCompare; } int goalsConcededCompare = Integer.compare(goalsConcededTable.get(b), goalsConcededTable.get(a)); if (goalsConcededCompare != 0) { return goalsConcededCompare; } int goalDifferenceCompare = Integer.compare((goalsScoredTable.get(b) - goalsConcededTable.get(b)), (goalsScoredTable.get(a) - goalsConcededTable.get(a))); if (goalDifferenceCompare != 0) { return goalDifferenceCompare; } int pointsCompare = Integer.compare(pointsTable.get(b), pointsTable.get(a)); if (pointsCompare != 0) { return pointsCompare; } return a.compareTo(b); }); // Print the table header System.out.println("Team\tP\tW\tL\tD\tGF\tGA\tGD\tPTS"); // Print each team's stats for (String team : sortedTeams) { System.out.println(team + "\t" + matchesPlayedTable.get(team) + "\t" + matchesWonTable.get(team) + "\t" + matchesLostTable.get(team) + "\t" + matchesDrawnTable.get(team) + goalsScoredTable.get(team) + + goalsConcededTable.get(team) + "\t\t" + goalDiffTable.get(team) + "\t" + pointsTable.get(team) + "\t"); } } public static void main(String[] args) { List<String> teams = new ArrayList<String>(); teams.add("Team A"); teams.add("Team B"); teams.add("Team C"); teams.add("Team D"); teams.add("Team E"); teams.add("Team F"); teams.add("Team G"); teams.add("Team H"); teams.add("Team I"); teams.add("Team J"); int numMatches = teams.size() * 2; LeagueSimulator simulator = new LeagueSimulator(teams, numMatches); simulator.simulateMatches(); simulator.printTable(); } } 一切似乎都运行良好,代码运行除了计算错误。 程序错误地打印了联赛的最终排名。 应该有18场比赛,因此每支球队应该打18场比赛。 总积分计算如下:胜=3分,平=1分,负=0分。 净胜球的计算方式为:进球数-失球数。 进球数是球队在整个赛季的进球数。 失球数是一支球队整个赛季失球数。 赢得的比赛是一支球队在整个赛季中赢得的比赛数量。 输掉的比赛是球队整个赛季输掉的比赛数量。 平局数是一支球队整个赛季平局的比赛数。 我还希望在每个比赛日回合结束时根据之前的比赛日结果打印并显示最终表格,然后用户才能开始输入下一个比赛日回合的结果 当我运行程序时,它错误地打印了决赛桌,我不知道如何根据之前的比赛日结果在每轮比赛后打印决赛桌。

回答 0 投票 0

为我的 flutter 应用程序运行 IOS 模拟器的问题

我正在尝试在 IOS 模拟器上运行我的 flutter 应用程序,但它无法正常工作。所以尝试了最基本的 flutter 应用程序(创建 my_app 然后尝试运行它)但似乎没有任何效果! 一切似乎...

回答 12 投票 0

罗技 G Pro 飞行方向舵踏板与 Windows 11 不兼容

简单的问题,我想购买 Logitech G Pro Flight Rudder Pedals 但是,我注意到它们与 Windows 11 不兼容,它仍然可以在 X-Plane 12 中使用吗?

回答 0 投票 0

如何修改缓存模拟器的 FIFO 实现中的读取函数

我有一个缓存模拟器,它实现了缓存的FIFO方法,这里是我的结构变量供参考: #include #include #define DRAM_SIZE 1048576 类型定义...

回答 1 投票 0

如何在 Python 中克隆我的精灵?

我正在尝试用 Python 制作一个类似生态系统的模拟器,我的问题是我不知道如何制作它的克隆。 这是我的代码: 导入操作系统 随机导入 导入pygame 导入数学 导入系统 宽度 =

回答 0 投票 0

我怎样才能完成我的写函数来模拟所有缓存级别的写请求?

我有一些函数可以处理来自具有这些规范的缓存的读取请求: 缓存有两个级别: 一个缓存块是 16 字节。 每个地址访问 1 个字节的数据。 L1 ...

回答 0 投票 0

我更新了我的销售脚本以包含双倍现金游戏通行证,但现在它不起作用,有人可以尝试修复它吗?

我有一个可以工作的销售平台,但现在没有错误消息,但不卖我的鱼。 本地部分 = script.Parent 本地id =158043842 Part.Touched:连接(功能(命中) 本地 H =...

回答 0 投票 0

如何为ios模拟器设置代理?

作为主题。 我在我的 macbook pro iOS 模拟器中运行一个应用程序,我想通过我的 http 中间件配置我的应用程序的请求。 那么,如何设置iOS模拟器的http代理呢? 我打开我的系统偏好设置,然后

回答 1 投票 0

Flutter 应用程序没有在我的模拟器中启动

我想在模拟器上启动我的 flutter 应用程序,但我遇到了一些问题。我在构建项目时没有问题,但它会在模拟器上创建一个应用程序图标并启动一秒钟,...

回答 0 投票 0

npx react-native run-ios 失败

我正在尝试帮助一位新团队成员通过 CLI 或 Xcode 让我们的 RN 应用程序在他的模拟器上运行。 从 CLI,我们收到以下错误: Ld /Users/USERNAME/Library/Developer/Xcode/

回答 1 投票 0

是否有任何版本的 minecraft(如 Blockcraft 3D else,或 mods 如 Redstone)但具有更多块属性?

我想在类似 Minecraft 的环境中模拟真实的制造周期(工厂建设的东西)。 Restone 很好,但我不能移动方块和移动连接的方块,所以没有足够的物理...

回答 1 投票 0

当从 node.js 源重新连接 mqtt 连接时,mqtt 订阅不会发生

设备断开后,尝试重新连接,但是所有的mqtt连接都是正常的,但是有一个现象,就是不进行mqtt订阅。 请帮我。 当 mqtt 断开连接时...

回答 0 投票 0

expo 安装或运行应用程序时出错

当我尝试在 iOS 模拟器上运行我的应用程序时,出现错误: 运行 xcrun simctl openurl 时出错 booted exp://localhost:19000: 处理命令时遇到错误 (domain=

回答 6 投票 0

CARLA 模拟器中的警车或救护车选项

我打算在我的项目中使用 CARLA 模拟器,我需要紧急车辆警报器的视觉信息,开/关。 我想检测/分类警车或救护车的{ON siren / OFF siren}...

回答 0 投票 0

如何在本机设备上使用 Xcode 打印机模拟器?

我正在开发一个应用程序,可以让你拍照然后直接打印出来。有没有办法让打印机模拟器在本地 wifi 上公开?因为相机只能在本机设备上使用...

回答 0 投票 0

如何创建将飞行模拟器 (FSX/P3D) 连接到我的云存储 (Onedrive) 的程序?

大家好,我正在进行一个项目,为我的飞行模拟器 (FSX/P3D) 制作逼真的风景。不幸的是,由于数据量非常大(将近 1TB 的风景大小),我无法...

回答 0 投票 0

如何解决 "dyld.库未加载:"的错误。库未加载。当在Xcode中从物理设备中模拟应用程序时,如何解决 "dyld: Library not loaded: @rpathRealm.frameworkRealm "错误。

当我通过虚拟模拟器运行应用程序时,我可以很好地运行它,但当我试图通过物理设备运行它时,我看到这个错误,应用程序无法运行。我如何才能解决这个问题?这个...

回答 1 投票 1

如何在ONE模拟器上使用外部节点移动模型?

我想问一下如何在default_settings.txt上运行外部节点移动。例如,我使用的节点运动模型从http:/crawdad.org(cambridgehaggle数据集),其中包含5个文件......

回答 2 投票 0

Gradle构建问题:无法获得Caffeine Simulator中的未知属性 "库"。

我曾经使用Eclipse在我的Caffeine's Simulator的分叉上工作,项目编译和构建都很正常。突然间,我在运行Gradle构建时开始得到以下错误。Could not get ...

回答 1 投票 0

在mac设备上运行一个新的应用程序,我们在上面编写代码。

是否有可能开发一个应用程序,并运行在同一物理设备?我在swift UI中开发了一个相机应用程序,是否有可能在我开发的同一台macbook中运行和测试代码... ...

回答 1 投票 -1

© www.soinside.com 2019 - 2024. All rights reserved.