Tic Tac Toe - AI (efficient algorithm?)
Posted: Wed May 09, 2012 1:47 pm
Hi,
I'm interested in the AI programming (learning, efficient, fast, intelligent).
I want to understand and write fast and memory saving functions (not 1001 if-statements...).
At the moment, I'm trying to program a little AI for Tic Tac Toe.
I cover the "AI has won/Player has won"-story with 16 ifs (certainly a low solution, but hey, we all began one time. )
But now to the point...
I haven't enough mathematical and logical thinking (yet) to see a fast method (function) in this game structur (fields and their ID):
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
Facts:
+1 every field horizontally
+4 every field diagonal
+3 every field vertical
Is there a calculation/formula to do a fast AI?
Also, every field has an OWNER property (nil = nobody, 1 = player, 2 = AI), it's possibile to sort them before compare them?
(table.sort? - You know, I and tables, we aren't friends (yet))
Like in MySQL:
So you could work only with those, who have an owner?
Or how would you solve my situation? With a totaly other AI?
Greets
I'm interested in the AI programming (learning, efficient, fast, intelligent).
I want to understand and write fast and memory saving functions (not 1001 if-statements...).
At the moment, I'm trying to program a little AI for Tic Tac Toe.
I cover the "AI has won/Player has won"-story with 16 ifs (certainly a low solution, but hey, we all began one time. )
But now to the point...
I haven't enough mathematical and logical thinking (yet) to see a fast method (function) in this game structur (fields and their ID):
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
Facts:
+1 every field horizontally
+4 every field diagonal
+3 every field vertical
Is there a calculation/formula to do a fast AI?
Also, every field has an OWNER property (nil = nobody, 1 = player, 2 = AI), it's possibile to sort them before compare them?
(table.sort? - You know, I and tables, we aren't friends (yet))
Like in MySQL:
Code: Select all
SELECT *(all) WHERE OWNER ~= nil
Or how would you solve my situation? With a totaly other AI?
Greets