I'm making a tic-tac-toe game in javascript, and I need help with the AI. Right now I'm doing it sort of like this:
if (board==something){board=newthing} else if(board==something){board=newthing} ...
I'm wondering if there's a more efficient way of doing this, that will take less time (it's tic-tac-toe, I have about 200 if elses to go).
Offline
Maybe generate a game tree?
Offline
Gravitation wrote:
Maybe generate a game tree?
Yeah, but there are
9! (or something) individual loops you need to make.
Offline
mythbusteranimator wrote:
Gravitation wrote:
Maybe generate a game tree?
Yeah, but there are
9! (or something) individual loops you need to make.
So? JS is pretty fast. I wrote a TTT ai in JS, lemme dig it out...
Offline
Offline
Hardmath123 wrote:
how did you do that?
The article in the wiki doesn't really explain it that good, I'd appreciate it if you tell me how you did it in a different manner.
Last edited by TorbyFork234 (2012-12-03 18:38:50)
Offline
You could use fancy mathematics, but chances are that brute force will work just as well and require less headache.
Offline