Improvement to getGridPosition and AI