The logic behind tic tac toe