You might noticed that even tho you code is good your wizard doesn't shoot sometimes when it sees another wizard.
The apples are basically the ammo. If you didn't collect any apple it won't shoot. One apple = shoot.