我想我也许可以通过从回合数中减去死亡人数来计算获胜回合的值(value),但我的计数器没有增加:
public void onRoundEnded(RoundEndedEvent event)
{
roundCount++;
}
public void onDeath(DeathEvent event)
{
deathCount++;
}
日志中没有收到任何编译错误或任何其他错误。当我在 onBattleEnded 事件中将变量输出到日志时,输出(100 回合后)为:
roundCount=1
deathCount=0
完整代码如下:
public class AB extends AdvancedRobot
{
private int deathCount;
private int roundCount;
public void run()
{
while(true)
{
ahead(100);
turnGunRight(360);
back(100);
turnGunRight(360);
}
}
public void onScannedRobot(ScannedRobotEvent e)
{
fire(1);
}
public void onHitByBullet(HitByBulletEvent e)
{
back(10);
}
public void onHitWall(HitWallEvent e)
{
back(20);
}
public void onRoundEnded(RoundEndedEvent event)
{
roundCount++;
}
public void onDeath(DeathEvent event)
{
deathCount++;
}
public void onBattleEnded(BattleEndedEvent event)
{
System.out.println("roundCount=" + roundCount);
System.out.println("deathCount=" + deathCount);
}
}
使用的Robocode版本是1.9.2.6
最佳答案
因此,每轮都会创建一个新实例。将字段设为静态使其成为类变量,该变量也由每个实例共享。您可以找到更多信息here .
关于java - Robocode - 如何计算战斗结束时赢得的回合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43356973/