tictactoe lesson borrowed from https://developer.apple.com/library/safari/samplecode/TicTacToe