Program. Battle. Iterate.
A real-time tank battle game where students program autonomous tanks using Python. Control movement with differential drive, aim an independent turret, and allocate stat points to customize your tank's strengths.
Includes game executable, Python library, and example bots
Read the Student GuideDistribute 100 points across armor, firepower, sensors, and ballistics to create your perfect tank build.
Program tank movement with differential drive (left/right tracks), aim the turret independently, and decide when to fire.
Your code runs autonomously. Watch the battle unfold, analyze what went wrong, and iterate on your strategy.
Test against practice bots, then face off against classmates in tournaments.
import codetank
tank = codetank.connect()
tank.set_name("My Tank")
tank.set_stats(armor=25, firepower=25, sensors=25, ballistics=25)
def brain(tank):
enemy = tank.scan()
if enemy:
# Aim turret at enemy (clamp to -100 to 100)
turret_power = max(-100, min(100, enemy.direction * 4))
tank.set_turret_power(turret_power)
# Fire when aimed and in range
if tank.is_aimed_at(enemy) and tank.is_in_range(enemy) and tank.can_fire():
tank.fire()
# Move toward enemy
tank.set_tracks(80, 80)
else:
# Search for enemy
tank.set_turret_power(60)
tank.set_tracks(50, 50)
tank.run(brain)