in reply to Is this a good way to implement a Battleship game?

how large is your "move space", that means how many possible moves are there? normally, you give moves a score and choose then the best one. if the move spaces is small enough, you can evaluate all. then you can choose a optimization strategy, e.g. choose the n best moves and evaluate all (or good) opponents moves. and you should write
if ($i == 1)
for numbers.
if ($i eq '1')
for strings.