I made a self-learning AI to play Tic Tac Toe!

in #ai6 years ago

AI (Artificial Intelligence) and blockchain technology are in my opinion virtually indissoluble. I have already seen so many extraordinary projects that use machine learning and neural networks in order to achieve the biggest efficiency and performance, for instance NOIA or Golem.

Additionally, AI is widely used to improve the performance of devices surrounding us. Traffic lights, personal assistants, autonomous cars or recommendations are just some of the areas where we can meet AI every day.

Being fascinated about endless possibilities of this technology in revolutionizing everyday life and blockchain I decided to use my humble IT skills and develop my own AI. At the beginning of this exciting path I decided not to use complex mathematical formulas and algorithms (even though I am aware that they are the most efficient), but to do it on my own, not so complicated way.

tic tac toe.png

What was my goal?

I sometimes enjoy playing Tic Tac Toe, so I wanted to create a worthy opponent for me :) There are already plenty of algorithms that makes the Tic Tac Toe AI virtually unbeatable, for instance the Minimax algorithm. However, they are based on input provided by a human, which means there is said: "in this situation, this decision will have the best impact on your probability of the victory". I wanted to avoid such approach and create something similar to machine learning.

How can the program learn itself?

Firstly, as AI has no input provided by human basing on which it would be making decisions it needs to collect enough data about the opponent. AI has this advantage that it can learn itself virtually endlessly, as it does not get bored or exhausted. Therefore my idea was simple: let the AI play 10,000 times with itself using a random made decisions (it took about 30 minutes, even for a computer). Every time circles win, the state of board after every move in this particular game is saved to the file.

Thanks to this, AI has acquired a file with plenty of patterns that usually lead to the victory of circles. However, still the biggest challenge was to interpret these patterns properly as I have met several problems:

  • how to avoid repetitiousness in the game
  • what if there are more patterns that are matching current situation on the board
  • what if there are no patterns that are matching current situation on the board

My solution: every time program has to make a decision, it analyses every saved pattern and compares it to the current situation on the board. Usually there are several patterns with the same level of similarity, so one of them is chosen randomly. If none is applicable, the move is executed completely randomly.

Results

For me results are pretty satisfying as the probability of victory with the randomly choosing opponent has been increased by 100%. Here are some games that AI played with me (I play with lines):

I am sure that is not the end of my journey with AI as I am strongly determined to develop a true neural network and I will certainly share the results of my work with you. Additionally I am currently preparing an article about benefits and risks of AI, so stay tuned :)

Here is a Github repository with source code for anyone interested.

Sort:  

Actually my professional background is Biology.
Though I am interested to read/learn alot of things.

Your tic tac toe is a 9 sqaure position, exactly similar to what we are playing when we are a kid.

Isn't the first mover have the greater chance in winning in this game?

About AI
It is a great already for your tic tac toe ai game.
Hope you can contribute also to the development of the steem blockchain.

Thanks. and good morning.

PS. if you can send me links about AI it will be surely appreciated.

Hi @guruvaj

Isn't the first mover have the greater chance in winning in this game?

Indeed, according to my measurements the first mover has 66,6% probability of victory. My AI always starts as a second, so its chance was 33,3% before the learning process. After that it improved to 66,6% :)

if you can send me links about AI it will be surely appreciated.

I am glad you enjoyed it :) I will definitely notify you if I release a new article.

Good morning from the Philippines.
If I remember it right, the key to win the game is let your opponent to make two-parallel piece and block it your own piece, it was the only key in that puzzle, then, you can already nanipulate the game in your favor.

Posted using Partiko iOS

This comment is supported by $0.54 @tipU upvote funded by @crypto.piotr :)
@tipU voting service guide | For investors.

I am so impressed. What a great project. I am a trial lawyer. There is still no AI program that will analyze a personal injury case. While this area of law is one of the most complex, it will lend itself to pattern recognition, not unlike Tic Tac Toe or chess. While it is truly difficult, the value would be immense to the legal industry.

I am glad that you enjoyed my little project @clayrawlings. I have never thought about that before, but AI in the law area would be definitely useful. Current situation with law in my country (government tries to take over judiciary system) leads me to the conclusion that something has to be changed in this industry in the future.

However as you correctly noticed, the level of difficulty is significantly beyond current technical possibilities.

The impact of steemit is unlimited in my search for knowledge.
@neavvy this is incredibly good but I will love to know more about block chain technology.
Thanks
A²¹

Posted using Partiko Android

Hi @abidemiademok21

Steemit is definitely an incredible platform to improve our knowledge :)

I will love to know more about block chain technology.

I am very happy to hear that! You can definitely expect more about blockchain technology on my profile in the future :)

I will wait patiently till I become an expert

Posted using Partiko Android

Ironically, I was watching a video about the risks of AI on youtube when I received your memo. 🤯

Nicely done, I'm looking forward to seeing what you come up with in the future :)

Thank you for your nice words @futuremind

I was watching a video about the risks of AI on youtube when I received your memo

Haha, AI tries to draw your attention from learning about its potential risks :D

Hi @futuremind

Any interesting video you would like to share? I also wonder what are REAL risks of AI.

Yours
Piotr

Oh I think there are some very real associated risks @crypto.piotr. Some of them will be outlined in this video I'll share with you.

This video was amongst one of the first I saw regarding AI, and it was the spark that fueled the fire in terms of my interest. This is a clip to a TED talk with Sam Harris.

Thanks for the response friend :)

Dear @futuremind

Thank you for sharing this video with me and being so supportive. Seriously. BIG THX! :)

Yours
Piotr

Your balance is below $0.3. Your account is running low and should be replenished. You have roughly 10 more @dustsweeper votes. Check out the Dustsweeper FAQ here: https://steemit.com/dustsweeper/@dustsweeper/dustsweeper-faq

Be cool to be able to play for STEEM ? :D Interesting to see what you work on next! Thanks for posting & for the memo

Playing for Steem is an interesting concept @dynamicrypto :) Thank you and I will definitely notify you!

This is amazing, it must have taken you quite some time to fully develop this program. I myself am studying IT, next year Application Development... This is one of the fields I would love to branch into... As well as VR or Robotics, even cyber security since that will be in high demand.

I love the way you had to implement the self learning aspect through saved data that have already been played... This was done quite exquisitely, well done bro :)

The only thing that you can improve is the graphics behind the game and it will be absolutely perfect... This was done really well and I am sure it must have taken a really long time to sort out bugs, troubleshoot and think of new ways to implement ideas into a better working system. Great work, hope to see some more projects, because this is getting me a little excited to start developing something soon... Can't wait for Uni next year, will definitely have the encouragement to start learning new languages and keeping up the A aggregate.

Is you code open source or private :D
I would love to see it if it is open source :)
If not, that's ohk... The methodology that is behind it seems sound and I would love to actually play the game, is it hosted online or and app, or is it just a local side game that is on your computer?

Anyway, this was a great project and well done on your completion of it :)

Thank you for your amazing comment @shadown99

I myself am studying IT, next year Application Development...

Wow, that's my dream... Where do you study?

The only thing that you can improve is the graphics behind the game

Thank you for suggestion, I will consider that.

it must have taken a really long time to sort out bugs, troubleshoot and think of new ways to implement ideas

Indeed, that was long but so exciting journey :)

this is getting me a little excited to start developing something soon...

I am glad to hear that and looking forward to your projects!

My code is fully open source :) Here is a GitHub repository: https://github.com/jankulik/AI-Tic-Tac-Toe. The code is written in Processing, which an open-source graphical library based on Java language.

Hey, sorry for the late reply... Days have been a bit hectic recently :(

I am studying at Durban University of Technology (DUT), in South Africa...

I am glad it was exciting, having fun is the best part of programming... Well for me :D

Will definitely share any new projects i may develop in the future... I would love to get feedback :)

Thanx for sharing the link... will have a look, I did Java in school. In Uni, I have learnt HTML, CSS, JavaScript and PHP this year. It was really difficult, but I really want to learn all I can to become a good Software developer, Cyber security wiz, Work in AI or in Robotics... Can't wait for next year to begin :)

Is 3D Tic Tac Toe on the roadmap? :P

As @eccles stated, you may want to look into submitting this kind of post to utopian-io under development.

They reward open source contributions with upvotes. To learn more about how to contribute, here is a link

Also, good idea to acquaint yourself with the questions for the respective category.

https://review.utopian.io

Let me know if you have any questions.

Posted using Partiko Android

3D Tic Tac Toe would be an amazing challenge @anthonyadavisii :)

I am already contributor to utopian community in a tutorial category, so I know this platform pretty well. I was wondering about submitting this post under development, but I was afraid my project is not sophisticated enough to be considered for a reward. What do you think?

I think @void and the team have developed it on STEEM, their project https://www.steeve.app, and I don't really understand AI problems, thank you for contacting me.

owh my friend @crypto.piotr he was interested in AI discussions, don't forget to invite him to get involved 😊

Wow @ziapase, I wasn't aware of the existence of Steeve, but it seems to be very interesting and useful Steemit interface. Thank you for informing me and I am definitely going to check it out :)

Yeah okay 😊😊

I like this. Have you set the difficulty settings or is this something that is negated once the AI starts "learning"?

Thanks @ulqu3. I haven't set anything, all of this is a pure effect of the learning process.

AWESOME!!!

It's great! I love programming too. I have never done an AI but it must feel great to have created life! Hahaha

I can ask you what language you used, I would like to try it with php or c #. I have never programmed in python. Is it python?

I'm glad to know that there is another who shares my passion for programming.

Btw, let me know when you develop a neural network

Happy Holidays!

Hi @jadams2k18

it must feel great to have created life

Indeed, it is really exciting that your program can make decisions without your interference :)

This is Processing, an open-source graphical library based on Java language. I think that C# or php will be good as well :)

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.029
BTC 56583.42
ETH 2984.52
USDT 1.00
SBD 2.15