Computer game programs work by evaluating the results of various possible moves, and then playing the move that leads to the best result. Often the programs can look ahead many moves.
One of the classic techniques for making computers play games is to use a "search tree". A search tree is like a map of all the possible moves in the game. A computer can look on the map to see which route might lead to it winning and then take that route.
You can see part of the search tree for a game of noughts and crosses above.