First of all, do not be disappointed. This is arguably the hardest puzzle in the whole game, since it pits a human against a computer in a game where computers have the advantage. This means there are quite a lot of players who searched for methods to solve this puzzle and some of them actually managed to find viable strategies.
It seems that the creators have changed the AI in different editions. In most versions the following strategy (Lamkin's Gambit) will work:
The X denotes the first piece placed by your opponent, and the numbers indicate your moves in order.
However, there were a few reports from users who said that for them this technique did not work. This indicates that Amanita Design have changed the AI. If you happen to have this newer (or older? anyways, different) AI, and this method doesn't work, you can still try pitting another AI against your opponent by opening up a web based 5-in-a-row simulator with a strong AI, setting up the board to be 10×10, just like the one in Machinarium and feeding the AI the moves your opponent makes and vica versa.