function to keep illegal moves