Refactor img_filename() function
Move AI next player check to a function