Buckle up for 3 - Truth Tables 😎

πŸ“Š Building Truth Tables

Truth tables show how boolean expressions evaluate. They help predict what an if statement will do. This is useful when you’re combining checks like energy level, enemy count, or gun readiness.


βœ… Table Example

A (Gun Ready?)B (Low Energy?)A && B`AB`
truetruetruetrue
truefalsefalsetrue
falsetruefalsetrue
falsefalsefalsefalse

🧠 Real-World Robocode Check

boolean gunReady = getGunHeat() == 0;
boolean lowEnergy = getEnergy() < 20;
 
if (gunReady && !lowEnergy) {
    fire(2);  // Only shoot if gun is ready AND we have energy
}

πŸ’‘ Notes

  • && means and β€” both sides must be true.
  • || means or β€” either side can be true.
  • ! means not β€” flips a boolean value.

Understanding truth tables will help you build smarter conditions and avoid mistakes like always firing even when your bot is in danger.


⬅️ Back: If Statements ➑️ Next: Loops