我目前正在测试游戏项目。以下是有关我的项目的详细信息。
这是我的第一个Maven项目,我对它的工作方法真的不甚了解。请帮助我!
1] GameProject-是Eclipse中的Maven项目。该项目的主要目标是为第一人称射击游戏创建一个玩家(也称为机器人)。当您运行此Java应用程序时,它将与一个新玩家一起运行游戏,该玩家的动作将由我在该项目中编写的代码确定。
它具有许多Java文件和一个主类。有一个名为PlayerInfo.Java的类,其中包含用于确定玩家在玩游戏时应该做什么的代码。就像玩家的大脑。假设它有大约40个变量,这些变量决定了播放器的行为。
示例-类中的变量之一可能类似于Player_HEALTH_Level =50。这意味着Player应该拥有至少50%的生命值才能与其他玩家战斗。如果小于此值,则他/她应找到一个健康包并增加其价值。同样,我还有其他39个参数。
2]测试项目-这也是一个行家项目。旨在测试我的Player(bot)在游戏中的性能。例如,他赢得比赛的次数,他收集的武器数量等。
该项目的设计方式要求将GameProject的JAR文件的路径作为Main方法中的输入。然后,它运行给定JAR的机器人程序/播放器,并将游戏结果打印在一个单独的文件中。
范例-
在主要方法中,我指定类似这样的内容
字符串playerJAR_Path =“ C:\ Users \ Player \ Netbeans \ GameProject-one-SNAPSHOT-jar.jar”
注意:-以上是GameProject JAR文件夹的路径。基本上,我只是将GameProject构建为“ Maven Install”,它将为我创建一个JAR。然后在第二个项目上使用路径地址。
希望这能使您对我的项目结构有所了解。
问题
真正的问题是我必须将我的GameProject基本上运行500次并捕获结果。我正在使用遗传算法来演化玩家参数并随时间改进它们。
目前,我可以在我的TestingProject中有一个for循环,以循环500次迭代,并且它需要为我执行GameProject 500次。
为了应用遗传算法,在每次迭代结束之后,我都修改了Player / bot Behavior(特别是在PlayerInfo.Java文件中)中的参数。像这样,对于迭代2运行,我可以将Player_HEALTH_Level = 48的值更改为第三次运行,然后更改为56,依此类推。
为了执行此操作,我需要在FOR循环中的“测试项目”中达成共识。
也许可能是这样
*For int i=1 to 500 do ;
String playerJAR_Path = "C:\\Users\\Player\\Netbeans\\GameProject-one-SNAPSHOT-jar.jar";
Run the Testing();
Modify the parameters in PlayerInfo.Java (Inside GameProject)
Change the values of 40 Variables in that class.
Build the GameProject Project so that, it creates a UPDATED JAR File
End FOR;*
我真的很困惑,例如如何自动构建第一个项目,以及如何更改类变量的值。
任何人都可以帮我就如何实现这一点提供一些建议。我不介意以什么方式做到这一点。只需能够自动化整个测试过程即可。
其他详情:
1.系统-Windows 7,Intel Xeon 12核心处理器,24GB RAM,3 TB闪存驱动器。
2.对于For-Loop上的每个迭代,它将产生一百万条记录(因为Eclipse的控制台窗口中,对于for循环中的每个迭代,将包含一百万行)。我还需要知道如何将其写入文件,而不是泛洪控制台。
当我最初对此进行测试时,Eclipse会因“堆满内存错误”而挂断。然后,我在Eclipse INI文件中将所有RAM值增加到2GB。这样就设法避免因内存错误而使日食崩溃。
编辑-将代码添加到问题。
public class PlayerInfo {
public int minDistanceToFollowEnemy = 200; // This is in UT Units. If Bot sees an enemy over this distance
// He/she tries to follow him and attack.
public int probabilityToFollowEnemy = 50; // Distance between the bot and Enemy will be calculated in real time.
//If the distance is lower, chasing priority is Higher.
public int probabilityOfFlagHolderReturn = 50; // If the Bot holds the Enemy flag, what's the probability that he/she
//Runs to home base directly without being distracted to collect items, fight with enemies?
public int probabilityOfGettingEnemyFlag = 10; // If bot does not carries the enemy flag, it's probability to hunt for enemy flag.
public double maxDistanceToGetHealthPack = 1000 ; // If Bot finds a health pack within this distance && It needs a Health pack
// Then It searches one and grabs it.
public int minHealthLevel = 30; // Min Health level before bot starts looking for Health Pack
public int probabilityToGetHealthPack=80; // Probability that Bot will Pick one health pack if it sees on its path/view.
public int probabilityToSelectItem = 8 ; //Based on the current Bot's view, what's the probability that it will select to choose the item.
}
GameProject中的主要类PlayerBot.java
公共静态void main(String args [])引发PogamutException {
AddNativeBot addbot = new AddNativeBot();
//addbot.addNativeBots(4);
// starts 2 or 4 CTFBots at once
// note that this is the most easy way to get a bunch of bots running at the same time
new UT2004BotRunner<UT2004Bot, UT2004BotParameters>(CTFBot.class, "PlayerInfo").setMain(true)
.startAgents(
new CTFBotParams().setBotSkin("HumanMaleA.MercMaleC").setBotType(0).setSkillLevel(5).setTeam(0).setAgentId(new AgentId("Attacker 1"))
//,new CTFBotParams().setBotSkin("HumanFemaleA.MercFemaleA").setSkillLevel(5).setTeam(0).setAgentId(new AgentId("Attacker 2"))
//,new CTFBotParams().setBotSkin("HumanMaleA.MercMaleA") .setSkillLevel(5).setTeam(0).setAgentId(new AgentId("Attacker 3"))
//,new CTFBotParams().setBotSkin("HumanFemaleA.MercFemaleB").setSkillLevel(5).setTeam(0).setAgentId(new AgentId("Attacker 4"))
//,new CTFBotParams().setBotSkin("HumanFemaleA.MercFemaleB").setSkillLevel(5).setTeam(1).setAgentId(new AgentId("Attacker 5"))
//,new CTFBotParams().setBotSkin("HumanFemaleA.MercFemaleB").setSkillLevel(5).setTeam(1).setAgentId(new AgentId("Attacker 6"))
);
}
//项目2
public static String[] getArgs_CTF_2v2v1() {
return new String[] {
"-y", // MATCH TYPE
"CTF", // CAPTURE THE FALG
// GENERIC CONFIG
"-u",
"C:\\UT",
"-h", // human-like-log
"-r",
"./results",
"-n",
"Test-CTF-2v2v1", // MATCH NAME
"-s",
"CTFServer",
// CUSTOM BOTS CONFIG
"-a",
"C:\\Users\\Project\\Downloads\\CTFbot\\target\\mavenproject1-1.0-SNAPSHOT.one-jar.jar;C:\\Users\\Project\\Downloads\\CTFbot\\target\\mavenproject1-1.0-SNAPSHOT.one-jar.jar",
"-b",
"CTFBot1;CTFBot2",
"-l",
"1;2",
"-k",
"HumanFemaleA.NightFemaleA;HumanFemaleA.NightFemaleA",
"-i",
"0;1",
// NATIVE BOTS CONFIG
"-c", // NATIVE BOT COUNT
"2",
"-d", // NATIVE BOT NAME
"Native1;Native2",
"-e", // NATIVE BOT SKILL
"5;6",
"-g", // NATIVE BOT TEAMS
"0;1",
// HUMANS CONFIG
"-x",
"1", // HUMAN COUNT
"-z",
"1",
// CAPTURE THE FLAG SPECIFIC CONFIG
"-m",
"CTF-LostFaith",
"-f",
"1", // SCORE LIMIT
"-t",
"5", // TIME LIMIT
};
}
//主类
public static void main(String[] args) throws JSAPException {
// -----------
// FOR TESTING
// -----------
//args = getArgs_DM_2v2v1();
//args = getArgs_TDM_2v2v1();
args = getArgs_CTF_2v2v1();
// --------------
// IMPLEMENTATION
// --------------
initJSAP();
header();
readConfig(args);
sanityChecks();
switch (matchType) {
case DM:
executeDeathMatch();
break;
case TDM:
executeTeamDeathMatch();
break;
case CTF:
executeCaptureTheFlag();
break;
case DD:
executeDoubleDomination();
break;
default:
fail("Unsupported match type specified " + matchTypeName + " recognized as " + matchType.shortName + "[" + matchType.name + "].");
}
}
}
最佳答案
文本圣洁的墙。
好,几件事。仅仅因为Maven为您创建了一个jar,并不意味着您必须使用该jar。您可以直接致电课程。
因此,您的测试将实例化该类,而不是尝试从命令行运行该类。
第二。您不必直接修改变量的内部状态。我的建议是将更改保存到文件中,并让播放机读取该文件。对于下一次迭代,您可以修改文件并再次运行Player。
如果您有特定的问题,请告诉我,我会改善答案。
关于java - 通过代码动态在eclipse中创建一个JAR文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24919624/