Fixed draw by three fold repetition bugs.

AI now detects 3 fold repetition correctly and will avoid it in a winning position, as well as stalemate.

AI does still miss some obvious checkmates, that's next on the list.