Fixed a bug where the next move could be out of bounds