Fixed AI

It wasn't correctly counting in one direction.