CuriousTacToe - Devlog


Hey guys! Thanks for checking out my version of the simple ‘tic-tac-toe’ game.
This is the first app I’ve ever made in Kotlin (Android Studio)  and would like to tell you a little bit about how it works. 
Just incase you didn't land up here after trying the app, you can download the apk here.

So, how does it work?

To start with, each time the player clicks on the box, the computer plays a move according to a sweet tiny algorithm, that makes the computer play the almost-best-possible move.

This is how the 'sweet tiny algorithm' thinks-

  1. Oh okay, the player has played his chance, now its my chance.
  2. Let’s see if I can win the game in the next move, if yes, I must play that move.
  3. If not, let me check if the player can win in the next move, if yes, then I’ll block it.
'o' is the computer. The computer blocks the player's winning move.
And surprisingly, that's all that the comp does to defeat a human opponent in almost every match!

As you may notice, The last two points are practically useless for the first move, since no one can win in just two moves.

But after playing my app a couple of times I realised its pretty easy to defeat the computer unless you are playing with your eyes closed. So, after a little brainstorming with my mom, I came up with certain best moves for the computer to play in the first few chances, like-




  • If the player marks a corner in the first move then the computer must mark the centre.


    1. Over time I’ve come up with a few more of such ideas which make the computer almost invincible.

      If you are able to repeatedly defeat the computer using the same strategy, and know what can make the computer immune to it, please do tell me !

      I do plan to share the entire code, but since there are a whole-lot of codes better and simpler than mine on the internet, I’d have to clean my code to make more readable before sharing it to the internet.




      All in all, its fun making games and apps using Google’s legendary software- Android Studio. I'd love to get some feedback on the app, there's a comments box just below!😃

                      Cheers!
      Siddharth

      Comments

      Popular Posts