1
我想我可能是能夠計算減去輪的死亡人數贏得價值回合,但我的計數器不會遞增:Robocode - 如何計算在戰鬥結束時贏得的回合?
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
你期望它做什麼?你能發表一個[Minimal,Complete和Verifiable的例子嗎?](https://stackoverflow.com/help/mcve) – Koekje
我預計在每輪迴合結束後roundCount會遞增,而deathCount每次遞增機器人被殺害。當我進行100回合的戰鬥時,roundCount = 1和deathCount = 0。 – lepton
有可能每個方法都沒有被調用,這意味着問題在代碼中的其他地方。你可以請你做一些快速調試,並確認他們正在被調用?只需將System.out.println(「round ended」);和System.out.println(「死」);在每個方法的頂部。 –