Fixed a bug in legalmove

Messy Code needs TLC