This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-02 22:22:49

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Tic-Tac-Toe AI help

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:

Code:

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

 

#2 2012-12-03 04:21:03

Gravitation
New Scratcher
Registered: 2012-09-26
Posts: 500+

Re: Tic-Tac-Toe AI help

Maybe generate a game tree?

Offline

 

#3 2012-12-03 08:32:59

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Tic-Tac-Toe AI help

Gravitation wrote:

Maybe generate a game tree?

Yeah, but there are

9! (or something) individual loops you need to make.


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#4 2012-12-03 09:04:31

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Tic-Tac-Toe AI help

you can rotate the board and count duplicates, you get a maximum of ~20 *really* different situations

Offline

 

#5 2012-12-03 09:15:35

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Tic-Tac-Toe AI help

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...


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6 2012-12-03 09:17:17

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Tic-Tac-Toe AI help


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7 2012-12-03 09:20:28

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Tic-Tac-Toe AI help

cool


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#8 2012-12-03 18:38:13

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Tic-Tac-Toe AI help

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

 

#9 2012-12-13 01:36:16

throughthefire
Scratcher
Registered: 2009-07-09
Posts: 1000+

Re: Tic-Tac-Toe AI help

You could use fancy mathematics, but chances are that brute force will work just as well and require less headache.


Back. For now. Maybe.

Offline

 

Board footer