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

in #ai5 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:  
There are 2 pages
Pages

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 :)

Wow!
AI "choosing" moves. A trailer of the things you are going to come up with, I think. A question for you to think about: since AI and automation are improving daily what will become of blue collar jobs? There are billions of people working at this level.

Heavy Thinking! And Happy Holidays!!

Well, that's really interesting question @sarez. In my opinion blue collar jobs will be still existing. I think that rather white collar jobs may be endangered, as AI will be able to perform operations as good as human's brain.

Coexisting AI and workplaces for humans are indeed very important issue nowadays, but I think that humanity has to adapt to the new circumstances. I am going to expand this issue in my upcoming article :)

I do have a casual interest in AI programming, thank you.

Hmm, if you go into further detail on your actual programming process (not necessarily in a single post) you could probably get an upvote from the #utopian-oi community too.

Posted using Partiko Android

Thank you for suggestion @eccles, I will consider contributing :)

Loading...

Done, i've resteemed this and voted...

Such an interesting article.

I appreciate your support @maikelblogo :)

Normally, I don't pay much attention to memos, but this one was worth the look. I am in the process of building something, do you use @partiko or discord?

Posted using Partiko Android

I am glad you enjoyed my little project @enginewitty :)

I use Discord, here is my name and tag: Neavvy#4212

Sent you a friend request buddy😎

Posted using Partiko Android

Was checking to see if you used @partiko so I could message you directly. I need a few devs that aren't already committed to something 😎

Posted using Partiko Messaging

I would be definitely interested @enginewitty :) I left my Discord address under your previous comment.

So if an Ai starts learning itself then we will have a robots that can teach themselves and beat our asses in the future!

that reminds me of Terminator!!

Yes, that's a bit frightening @soufiani, but in my opinion we must adapt to these changes and learn to live in symbiosis with AI. If you have any doubts I am going to expand my view on this issue in my upcoming article :)

This awesome. With this skill of yours, a greater tech is certain.

Thank you for your support and kind words @k-banti :)

Thanks for your memo. This is indeed interesting to me.

Posted using Partiko Android

I am glad you enjoyed it @bluerobo :)

oh nice project mate i have added this post to my favourites as i do not have enough data to view the videos and shall view them once i get some data and have you tried replika ai?

Posted using Partiko Android

Thank you for your support @khussan. I didn't know replika ai before but it seems really interesting :)

cool , i did try to build a ai bot myself using python and only managed to make a chat bot 😂😂😂

Posted using Partiko Android

Well, it is already a great beginning @khussan :)

This is super cool. I'm so interested in these things. I just checked out your GitHub repo and I can see a lot of .pde files. I just discovered that .pde is Java related. The code looks very much like Java also.

Did you write the code in Java? I never knew AI could be written in Java. I always thought Python.

Posted using Partiko Android

Hi @naijauser. The code is written in Processing, which is an open-source graphical library based on Java language. You are right, AI is very often written in Python, but that's not the rule. Languages such as Java or C++ are also sufficient for that purpose :)

)) I see you are bored) And they wanted to play with an artificial object)

Definitely yes @carbodexkim :)

Happy to receive your updates. Its something worth following. AI a help or hindrance to mankind?

Posted using Partiko Android

I am glad to hear that @andyjem :)

AI a help or hindrance to mankind?

Very good question, I am going to expand this issue in my next article. I will notify you for sure :)

Thank for the memo @neavvy. But I'm not a tech person though. I'm into Arts. Good job there.

Thank you @ogoowinner :)

You're welcome @neavvy.

I always like tic tac toe. This game is my favorite. I even defeated my teacher of Computer science thrice in a class.
It's good to see you working on this game.

Wow, congratulations @arslan786 :)

excellent work!
It's a great goal to carry out this kind of proyects, especially with an artificial intelligence that plays tic tac toe and can learn from itself, it migth sounds ridiculous but it doesn't, it's amazing.
Imagine all the possibilities that gives you to develop your own AI
I hope you continue with your project of making a real neural network and im waiting for that article. Also thanks for let me know your post in your memo
Good luck!

Thank you @globalnews.com

Imagine all the possibilities that gives you to develop your own AI

Indeed they are virtually unlimited :)

Yes, this is a simple method of using AI, sort of an after "Hello World" complexity.

Things begin to become interesting when you have to deal with Deep Learning... constantly adapting the algo to the objectives you need.

Absolutely agree with you @forykw

I strongly believe that people like @neavvy will build our future. He is just 17. When i was his age ... lol :) I dont even want to continue.

Cheers,
Piotr

That's right @forykw.

Things begin to become interesting when you have to deal with Deep Learning

Hopefully that's my next step :)

Well, congratulations on your success.

As a chess player, I'm really quite unhappy about the advent of AI's like Stockfish and AlphaZero. I am inclined to agree with the warning left to us by Stephen Hawking, and echoed by Elon Musk. I do very much fear this will be the death of us all.

Not that I think your little tic tac toe routine is going to light up Skynet and start building Terminators ;)

Hi @redpossum. Hawking and Musk have definitely something to say in terms of AI, so I also take their words very seriously. I am going to take this issue under advisement in my next article, so I will definitely notify you :)

Not that I think your little tic tac toe routine is going to light up Skynet and start building Terminators

Haha :)

Nice read and videos. How do you actually get the program to learn? And which platform do you use to develop the AI?

Posted using Partiko Android

Thanks @questionthetrend. I used Processing, which an open-source graphical library based on Java language.

I am very interested in knowing the commercial applications of ai and not much into the technical aspects as my professional background is in the legal field.

I believe ai will revolutionize many industries in the very near future. In the field of blockchain, I follow the singularitynet and matrix ai projects and I have invested a little in the singularitynet project.

I admire those, like you, who are involved in the technical side of ai. You are at the forefront of the ai vanguard. Keep it up, @neavvy.

Thank you @devann. Wow, I didn't know about singularitynet project, but after short research I have to admit that it is indeed amazing. You may be also interested in a Golem project.

I did a check on Golem before I invested in Singularitynet. Although I liked Golem, because of lack of funds, I had to choose between Golem and Singularitynet. I chose Singularitynet.

I must say I was a bit biased towards Singularitynet because I had spent quite some time on researching it and liked it so much that when I briefly checked out Golem, I felt as if, Singularitynet has an edge against Golem. Not fair, but I am alright with it!!

Yes, I don't know much of this AI, but your post awesome to knock in my interest on AI

Posted using Partiko Android

I am glad to hear that @bbbbtt55 :)

I guess tic tac toe is the simplest application of AI. tic tac toe is only 9 move game and I do not think it might be having billions of possibilities and I guess all result set can be stored.

Well, i have to probably surprise you @r1s2g3, but there are actually 255168 possible games :) (not taking into account symmetry in the game)

Hi @neavvy. Thanks for sharing your knowledge. You did well explaining your aproach in a step by step way. I'm not skilled with IT topics, however is interesting the idea of generating random data when you don't have "big data" to feed your AI. Sometimes there is not big data available and collecting it may become expensive. Random generated data could be a solution for that. Another aproach i have heard about is "model free methods". It seems that it doesn't require big data allthoug I could be wrong. I just have an overall idea about AI:
https://www.quora.com/What-skills-and-or-maths-are-needed-to-study-artificial-intelligence

Posted using Partiko Android

Wow, thank you @caribehub for this amazing comment and sharing the article. Random data is indeed sometimes a great solution :)

@neavvy ,
using Ai is a great idea but what about the interest of the player?
I suggest if you put a Difficulty option so that a player well not complain that they can not win. hahhaha :P

"The Better the Graphics and the Features, the greater the player will entertain to play more"

Thank you for suggestion @junnel123. This was rather a kind of experiment but maybe you are right :)

Funny you have invited me to see this article, I have actually worked for a company helping AI become more efficient, such as, those self driving cars.

Posted using Partiko iOS

Wow @coquiunlimited, for which company have you worked? Self driving cars are so exciting, I hope to have one in the future ;)

This puzzle is about strategy in a variant of Tic-Tac-Toe. The game is a normal game.... I mean 9 positions .... what about if the puzzle differs from the usual version in the following ways:

The board could be 16x16

The two players could have different goals

Your only goal is to get as long a line of pieces in-a-row as possible (horizontal, vertical, or diagonal)

Your opponent's only goal is to limit the line of pieces you can get in-a-row (it does not matter how many pieces in a row the opponent gets)

One final twist: for every move you make, your opponent gets to move twice with perfect play, could you get four in-a-row? Or can you prove that it is not possible? I mean in my suggestion ...

I´m just asking you @neavvy for a more difficult job...!!!

I know your work is really perfect and I´m really impressed with your presentation ....

Amazing...!!!

I appreciate your support @edgarare1 :)

your opponent gets to move twice with perfect play, could you get four in-a-row?

You mean that after my every move, my opponent has two moves? Well, that's really interesting idea for a completely new game. Maybe in the future... ;)

Thank you so much @neavvy for your incredible job...!!! And thanks a lot for share it with me...!!! Your work is completely amazing...!!!

Thank you for sharing @neavvy, but I don't like this kind of game. but I salit with your talent ...

I appreciate your support @sudutpandang ;)

Okay... 😎👍

Posted using Partiko Android

AI is composed of masters.
I also learned BASIC 20 years ago.
At that time, I wrote poker cards.
But now it’s not working.
BASIC is out of date,
The new programming software is something I can't learn.
blessing you succeed.

Hi @cloudblade, interesting story. In which programming language have you learned basic of AI?

Apoyado

Does it mean "supported" in Spanish @sacra97? At least my translator says so :)

it means read and that I liked the content @neavvy

I appreciate that @sacra97 :)

Amazing didn't know you can create an AI on such a simple game.

And also I Dont mind the memo @neavvy feel free to send whenever you feel you want to.

Wanted to send you private message but you haven't downloaded the update for partiko.

Anyway can't wait for another great content from you.

Posted using Partiko Android

Thank you very much @ragnarhewins90. I am afraid that I don't have Partiko on my phone :/ Maybe we will contact on Discord?

@neavvy sure we can contact in discord.

Posted using Partiko Android

@ragnarhewins90 My Discord name and tag: Neavvy#4212

Added you @neavvy on discord. It's an honor to know you brother.

Posted using Partiko Android

Congratulations, you have just taken a big step. The first time when I read about the IA I suffered from panic. I was not being controlled by machines je,je,je. I understand more about the intention of the IA. Thank you for recommending your article.

Thank you @belkisa758. Yes, the vision of AI taking control is indeed frightening, but in my opinion this is not going to happen. We just must stay careful and wary and AI will do plenty of useful things for us :)

I enjoyed with yout tic tac toe. And it is a very interestingo post. I would like to know some other articles in this way you could do.
you got my little upvote
and thanks for memo to me

I appreciate your support @mllg. I will definitely notify you once my new article is published :)

Thanks @neavvy!
Upvoted and followed

Thx for sharing that link with me @neavvy :)

Oh man! I was waiting for my evening to come, when I knew that I will have some time to catch up with reading.

Any sort of subjects related to AI fascinates me. Especially if people share their own views, and those views are not to far away from current technology.

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.

Most people seem to imagine that AI will be ONE. ONE that control all the others. Like some sort of "lord of the rings'.

And why wouldnt we see future with AI's everywhere around us? Our iphones have already quite advanced AI supporting users operations.

Thx for sharing your little experiment with us :) You have some potential Janku :) Pozdrawiam
Yours
Piotr

Thanks for your amazing comment @crypto.piotr. I am glad you enjoyed my little project :)

Our iphones have already quite advanced AI supporting users operations.

Indeed, and it is incredible how fast this technology develops. Not so long ago Google announced that its personal assistant will be able to make phone calls instead of us. For example if you want to book a table in a restaurant, you can just ask your google assistant to do that and it will call to this restaurant and have a conversation with a waiter.

AI of the assistant will implement every hesitations to imitate process of making decision, in order to make converser think he is talking to a real human. In my opinion it is an incredible breakthrough! Check this out:

I wonder if people will trust Google / facebook / amazon "asistants". Right now trust it's at it's lowest and we all know, that by buying those products we're giving away our privacy.

Thx for that link :)

Merry Christmas dear @neavvy
I'm still fascinated with your initiative.

All best, Piotr.

Thank you @crypto.piotr, the same to you :)

And happy new year for you, Keisha and your little puppy!

Interesting that you have these skills! Good flex of the IT skills into AI. Good luck euthanasia your future creations , looking forward to see what you create next

Posted using Partiko iOS

Thank you very much @dmilliz :)

Thanks for the memo, I was expecting you to use #utopian-io in your tag for more visibility. Am not that techy of a guy but I love it whenever I see one. Job well done. Expecting to see more of this.

Posted using Partiko Android

Thank you @botefarm. I will probably use the utopian-io tag in the future :)

There are 2 pages
Pages