0
0
Unityframework~20 mins

Why AI makes games challenging in Unity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
AI Game Challenge Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Unity C# AI decision code?
Consider this simple AI decision code snippet in Unity C#. What will be printed when the AI's health is 30?
Unity
int health = 30;
string action;
switch (health) {
    case int h when (h > 50):
        action = "Attack";
        break;
    case int h when (h > 20):
        action = "Defend";
        break;
    default:
        action = "Retreat";
        break;
}
Debug.Log(action);
AAttack
BNo output (runtime error)
CRetreat
DDefend
Attempts:
2 left
💡 Hint
Think about which case matches when health is 30.
🧠 Conceptual
intermediate
1:30remaining
Why does AI unpredictability increase game challenge?
Which of these best explains why AI unpredictability makes games more challenging?
ABecause AI unpredictability makes the game graphics better.
BBecause predictable AI allows players to easily plan and win.
CBecause unpredictable AI always cheats to win.
DBecause AI unpredictability reduces game difficulty.
Attempts:
2 left
💡 Hint
Think about how players react to patterns.
🔧 Debug
advanced
2:30remaining
Find the error causing AI to always attack in Unity C#
This AI code is supposed to choose between attacking or retreating based on health, but it causes a compile error. What is the bug?
Unity
int health = 10;
string action;
if (health > 20)
    action = "Attack";
else if (health < 20)
    action = "Retreat";
Debug.Log(action);
AThe code is missing braces {} around if and else if blocks.
BThe variable 'action' is not initialized before use.
CThe else if condition should be 'health <= 20' to cover all cases.
DThe Debug.Log statement is outside the if-else blocks.
Attempts:
2 left
💡 Hint
Check if all health values are covered by conditions.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in Unity C# AI code?
Which of these AI code snippets will cause a syntax error when compiled?
Aif enemyDistance < 5 { action = "Attack"; } else { action = "Retreat"; }
Bif (enemyDistance < 5) { action = "Attack"; } else { action = "Retreat"; }
Caction = enemyDistance < 5 ? "Attack" : "Retreat";
Dswitch (enemyDistance) { case < 5: action = "Attack"; break; default: action = "Retreat"; break; }
Attempts:
2 left
💡 Hint
Check the syntax of the if statement.
🚀 Application
expert
3:00remaining
How many unique actions can this AI perform?
Given this Unity C# AI code, how many unique actions can the AI perform?
Unity
int health = 40;
int enemyDistance = 10;
string action;
if (health > 50 && enemyDistance < 5) {
    action = "Attack";
} else if (health > 20 || enemyDistance < 10) {
    action = "Defend";
} else {
    action = "Retreat";
}
Debug.Log(action);
A3
B1
C4
D2
Attempts:
2 left
💡 Hint
Count all possible distinct actions from the conditions.