Simple algorithm. It needs to go through all combinations though. If it takes the first move it might be laggy. Actually, this algorithm was used to beat Garry Kasparov in chess (DeepBlue). You can use alpha-beta pruning to speed up this algo if you care about optimization here :)