Tic Tac Toe - AI (efficient algorithm?)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Roland_Yonaba »

Petunien wrote: But it's a good feel, that I could come back with more questions. :)
(I'm sure.)
No problem.
Petunien wrote:Yeah, exactly how I meant it. This would be possible with a few of variables and values. Sounds easy. ^^
Well, I'm not that sure. But at first, try to focus on writing the game itself. Once done, you can come back to the network support.
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Petunien »

According to my knowledge, network works basically like:

1) Player X choose a field. The new values (selected field and maybe other values like gametime) will be sent.
2) Player Y receive the new values, the program works accordingly and waits for Player Y's selection.

And so on, or?

Basically...
"Docendo discimus" - Lucius Annaeus Seneca
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Xgoff »

Roland_Yonaba wrote:Check for Minimax algorithm, it can be used for AI in a Tic Tac Toe game.
But it'll need some skills to be implemented in Lua, though.
minimax can't be that hard to implement in lua, considering there's an implementation of it on that wiki page
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Robin »

So to add to what Roland said:
Petunien wrote:2) Robin, you wrote it in Python, is it difficult to "translate" it bzw. write it in Lua/LÖVE?
It is not really difficult, but it will take certainly more effort than just writing it again for your specific purpose.

Minimax isn't complicated: you either choose the highest value or the lowest value, and that for every option you have.
Petunien wrote:3) Are all 255,168 (Wikipedia) game-situations covered with Minimax?
Yes. Minimax finds all possible games and evaluates them. That's why you shouldn't use Minimax for chess, which has something like 10^70 possible games...
Petunien wrote:4) How does it work with network?
Are there "normal" values like numbers, true/false and so on, that can be sent and further processed to/by another PC as well?
Not sure what you mean here, Roland probably wrote a better answer than I would write here.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Jasoco »

Man, I wish I still had the code for the TTT game I built in Visual Basic way back in the day. I was extremely proud of the AI system I built in. I had three skills. Easy, which just picked random blocks. Hard, which actually used the most logical move to block your move. And Medium which was a hybrid and randomly chose between random and logical. I can't remember how I made it so smart. I was new to programming so for me back then figuring out how to do it by myself was pretty big. So sad that back then we didn't have the luxury of cheap USB backup hard drives or Internet cloud-based file hosting sites. I lost so much cool stuff I wish I had at least copied to a floppy disk or something.
User avatar
Adamantos
Prole
Posts: 27
Joined: Sun May 16, 2010 10:47 pm

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Adamantos »

Here is the optimal solution for this game :)
http://xkcd.com/832/
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Roland_Yonaba »

Adamantos wrote:Here is the optimal solution for this game :)
http://xkcd.com/832/
Lol. :awesome:
I had a clue when I first saw "xkcd" in the url...

EDIT:
Another algorithm that can be used for solving a Tic-Tac-Toe is Backtracking.
Useful resources can be found on SiteExperts, csStanford and Duke.
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: Tic Tac Toe - AI (efficient algorithm?)

Post by Petunien »

I'm trying and reading a lot of stuff. Only so you don't think I gave up. :)
But many of the examples are written in Java, so I have to understand the basic of that language before I can understand anything.
Bad.

@Roland
Thanks for the other links, I saw them just now.
It looks easier than Minimax, at least in my opinion.
"Docendo discimus" - Lucius Annaeus Seneca
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests