you'd want to rewrite this section, with vector calculation.

right now we only have 4 directions to deal with. what if in the future we want to implement hex grid? or better, free movement?

here's what you should do.
implement the following function:

function getDirection()
 -- this function returns the direction in form of x,y. e.g.
 return 0,1 -- x=0, y = 1
end

and you can do

dx, dy = getDirection()

and you can do testMap(player,x*2,y*2), etc.

similarly, define a directional vector for moveBox.