Implements moveIsValid function