Problem of the Day: Tic-Tac-Toe (update)

Whew. TicTacToe is quite the time suck. I made a new TicTacToe class to handle creating a board, adding moves, checking for a winner, and printing the results. The board is still pretty dumb; each move attempt is started by getting a random integer [0-3), checking that it’s a legal move, then making the move and switching players. The entire board is always filled up but only prints out if there is a winner. Because “X” gets to go first every time it also wins a large percentage of the time, I check for “X” winning first to avoid a board having two win-conditions.

I did re-learn the ternary operation and figuring out how to teach a computer to play TicTacToe was a useful thought exercise. I might spend some time making the board smarter as far as choosing positions and checking for wins. Maybe.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: