Valid move function

Checks if moves are valid