Fixed a bug in the calculation of valid moves.