Research Article
Towards a Serious Game to Help Students Learn Computer Programming
Algorithm 3
“Search for opponent” algorithm.
program search-for-opponents | glossary | Position pos, map | Unit u | Boolean found | Counter c | begin | found ← FALSE | openGame() | map ← getMapSize() | while not found do | refreshGame() | // Check if an enemy is visible | if numberEnemies()
> 0 then | // stop all units | for c ←
1 to numberUnits() do | unitStop(getUnit(c)) | endFor | found ← TRUE | else | // give random target area to move for each unit | for c ← 1 to numberUnits() do | // choose a random target area | u ← getUnit(c) | if u.inactive then | // choose a random value between 0 and map.x | pos.x ← randomValue(map.x) | // choose a random value between 0 and map.y | pos.y ← randomValue(map.y) | giveOrder(u, MOVE, pos) | endIf | endFor | endIf | endWhile | closeGame() | end |
|