Make valid moves function smarter