Found out that ai_play() should should not have had of a double loop. Fixed next_available_square(). Unlike the previous versions, this one is the result of many days of meticulous debugging. I still have not succeeded in creating a game that cannot be defeated. The flaw in this particular version is that it tries to avoid defeat, but neglects the weight of possible future wins and ties.