Time for action – winning is everything
To determine the best course of action for the computer opponent, we need to create a prioritized list of rules for the computer to follow when deciding how to place a piece, which changes depending on the situation on the board. Let's pretend we are the computer, and we see this situation:
It wouldn't make sense to place an O anywhere but in X's way—otherwise, the computer loses. So we have our first rule:
Block opponent from winning
Now let's look at this situation:
Sure, X is about to win, but O also has an opportunity to win. Which is more important: for O to keep X from winning, or for O to win? Clearly, it's more important for O to claim victory and win the game. So we have our second rule:
Win
We just said that it's more important for O to claim victory than to block X, so we've also established a preferred order for these two rules:
Win
Block
Notice that our two statements are already written in pseudocode. Win()
and Block()
could just as easily be...