<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ikramul Hasan</title>
    <description>The latest articles on Forem by Ikramul Hasan (@ikramhasan).</description>
    <link>https://forem.com/ikramhasan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F797867%2F1d782300-376a-445f-bc2b-fe1f563717a3.png</url>
      <title>Forem: Ikramul Hasan</title>
      <link>https://forem.com/ikramhasan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ikramhasan"/>
    <language>en</language>
    <item>
      <title>How I Made a TicTacToe Game That You Cannot Beat 🙅‍♂️</title>
      <dc:creator>Ikramul Hasan</dc:creator>
      <pubDate>Thu, 28 Apr 2022 12:41:21 +0000</pubDate>
      <link>https://forem.com/ikramhasan/how-i-made-a-tictactoe-game-that-you-cannot-beat-47id</link>
      <guid>https://forem.com/ikramhasan/how-i-made-a-tictactoe-game-that-you-cannot-beat-47id</guid>
      <description>&lt;h2&gt;
  
  
  How I Made a TicTacToe Game That You Cannot Beat 🙅‍♂️
&lt;/h2&gt;

&lt;p&gt;For reasons I cannot remember now, I once searched &lt;a href="https://www.google.com/search?q=tic+tac+toe" rel="noopener noreferrer"&gt;tic tac toe on Google&lt;/a&gt;. I noticed that when you search it, Google gives you a game board where you can play the game. You can even choose the difficulty. What spiked my interest the most is, that there was a difficulty option named "Impossible". It completely blew my mind that there is a way to make sure you never lose. I became so fascinated that I started to dig deeper. And that's how I ended up here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dig Deeper 🤨
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650984159418%2FhG4um6VTC.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650984159418%2FhG4um6VTC.gif" alt="InceptionDeeperGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I found that the secret ingredient for such a bold claim was a very simple algorithm that can be written in less than 30 lines of code. It's called the &lt;a href="https://en.wikipedia.org/wiki/Minimax" rel="noopener noreferrer"&gt;MiniMax&lt;/a&gt; algorithm. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Mini-max algorithm is a recursive or backtracking algorithm which is used in decision-making and game theory. It provides an optimal move for the player assuming that opponent is also playing optimally - JavaPoint&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As soon as I saw that it was not actually a machine learning solution, but rather an algorithm, I became very demotivated. &lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;h2&gt;
  
  
  Confronting my fears 💪
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650987994495%2FJz0epyp9X.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650987994495%2FJz0epyp9X.gif" alt="YodaStarWarsGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because it was the same time I took the Algorithms course at my university. And I did miserably. I did not want anything to do with algorithms. I was planning to recreate the impossible tic tac toe game but was not sure if I'd learn an algorithm for it. On one hand, this could be a great opportunity for me to lose my fear of algorithms, on the other hand, it would mean tackling something I feared most of my life. &lt;/p&gt;

&lt;p&gt;That's when I found &lt;a href="https://www.youtube.com/watch?v=l-hh51ncgDI" rel="noopener noreferrer"&gt;this video&lt;/a&gt; by &lt;a href="https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQ" rel="noopener noreferrer"&gt;Sebastian Lague&lt;/a&gt;, one of my most favorite YouTubers. This video really made me think I can complete the project if I tried. And I did. The rest is a story of sheer perseverance, and an eagerness to improve myself. &lt;/p&gt;

&lt;h2&gt;
  
  
  Hard Decisions 🤔
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650988027444%2FbxkQlOit-8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650988027444%2FbxkQlOit-8.gif" alt="WhenYouMakeABigMistakeGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first decision I needed to make is what I'm going to use for the frontend. Basically displaying the game board and handling the user interactions. I knew it had to be a cross-platform solution. Because I had a play store account where I want to publish the app as a technical project, but also wanted to host it on the web so that my friends could play it easily without downloading an app. My first choice was &lt;a href="https://unity.com/" rel="noopener noreferrer"&gt;Unity&lt;/a&gt;. It passed all my requirements and is a solid framework for game development. But it was also very overkill for a simple game like this. Not to mention, the learning curve is also very high. I undertook this project to learn about algorithms. I didn't want to learn game development as well. This is why I decided to go with &lt;a href="https://flutter.dev/" rel="noopener noreferrer"&gt;Flutter&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Flutter❓
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650988523425%2FQHTOoo54-.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650988523425%2FQHTOoo54-.gif" alt="WhyGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because I already knew the framework well enough and it supports more platforms than Unity. I realized it would take me significantly less time to develop the frontend with Flutter. Now, you may be thinking, if Flutter is so great, why wasn't this your first choice? Because Flutter is primarily an application development framework. It never occurred to me that, a tic tac toe game board is nothing but some grids and common app UI elements. Flutter is great for them. It can also take any type of interaction from the user, be it single taps, press and hold, or even gestures. &lt;/p&gt;

&lt;p&gt;After I had chosen my framework of choice, it was now time to build the UI. And surprisingly, It only took me around 2 hours to do so. I then watched &lt;a href="https://www.youtube.com/watch?v=trKjYdBASyQ" rel="noopener noreferrer"&gt;this video&lt;/a&gt; by another personal hero of mine, &lt;a href="https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw" rel="noopener noreferrer"&gt;Daniel Shiffman from the Coding Train&lt;/a&gt;. His video really helped me understand the implementation, and edge cases for the algorithm. &lt;/p&gt;

&lt;h2&gt;
  
  
  The not so fun part 😒
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650990825624%2Fx5RXbK6D6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650990825624%2Fx5RXbK6D6.gif" alt="UnamusedGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although it took me a very short time to create the UI, I wish I could say the same for the algorithm. The programming language I'm using, called &lt;a href="https://dart.dev/" rel="noopener noreferrer"&gt;Dart&lt;/a&gt;, is actually very similar to javascript, the language Dan used to create the AI. So in my mind, I thought it was going to be a very easy task. But boy was I wrong. While trying to code, I faced the infamous &lt;a href="https://en.wikipedia.org/wiki/Stack_overflow" rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt; error for the first time in my life. And this has to be one of the scariest errors I've gotten in my life. The program would take up so much resources that I had no option but to shut down my then crappy PC. But one bug at a time, I managed to fix all of them. But it was not smooth sailing yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimizations ⚡
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650990806472%2FM0OzE8-C5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650990806472%2FM0OzE8-C5.gif" alt="CatComputerGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I managed to complete the project finally. I could play the game and the AI would check for all the possible moves ahead and choose the best one. But there was one problem. After I place my first "X", the AI had to check for 255,168 possible steps ahead (If I'm not mistaken). This meant that I had to wait a long time for the AI to complete the calculations and choose the best option. Which, not to mention, was not fun at all. This meant only one thing. I had to optimize the algorithm. That's when I learned about &lt;a href="https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning" rel="noopener noreferrer"&gt;alpha-beta pruning&lt;/a&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Alpha-beta pruning is a search algorithm that seeks to decrease the number of nodes that are evaluated by the minimax algorithm in its search tree - Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In layman's terms, it drastically reduced the number of steps the AI has to check. And believe it or not, even this wasn't enough for me. I then learned about &lt;a href="https://dart.dev/guides/language/concurrency" rel="noopener noreferrer"&gt;Isolates&lt;/a&gt;. This is actually a fancy way of saying I implemented multithreading. This would allow me to not block the UI while the calculation is going on in the background since both these tasks are handled in separate threads. After all of these was done, the project was finally complete. I created a tic tac toe game that no one can beat. And I cannot explain how happy I was. &lt;/p&gt;

&lt;h2&gt;
  
  
  Taste of success 🏆
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650988320836%2FDzaemBFB_.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650988320836%2FDzaemBFB_.gif" alt="SmellsLikeSuccessAndrewMcfarlaneGIF.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I undertook a challenge, did extensive research, defeated one of my biggest fears, and successfully completed the project. I know I'm making it sound like I'm describing the plot of &lt;a href="https://www.imdb.com/title/tt1396484/?ref_=kw_li_tt" rel="noopener noreferrer"&gt;IT (2017)&lt;/a&gt;, but that's what it felt like to me. &lt;/p&gt;

&lt;p&gt;Thank you very much if you came this far. This is the first time I wrote something for myself. So your thoughts and criticisms are much appreciated. Don't forget to leave a comment.&lt;/p&gt;




&lt;h1&gt;
  
  
  Try it out! 😌
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://impossible-tictactoe.web.app/" rel="noopener noreferrer"&gt;The website&lt;/a&gt; (It may take a while to load)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ikramhasan.tic_tac_toe" rel="noopener noreferrer"&gt;The app&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;The actual algorithm if you are interested:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;minimax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isMaximizingPlayer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;checkCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;checkAIWinner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;'NONE'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isMaximizingPlayer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;bestScore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;999999999&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'O'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;minimax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;bestScore&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;bestScore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;bestScore&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;bestScore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;999999999&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'X'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;minimax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="n"&gt;board&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;bestScore&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;bestScore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;bestScore&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Tech Stack Used: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://flutter.dev/" rel="noopener noreferrer"&gt;Flutter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dart.dev/" rel="noopener noreferrer"&gt;Dart&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codemagic.io/start/" rel="noopener noreferrer"&gt;Codemagic&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Credits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQ" rel="noopener noreferrer"&gt;Sebastian Lague&lt;/a&gt; for his amazing MiniMax explainer video.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw" rel="noopener noreferrer"&gt;Daniel Shiffman&lt;/a&gt; for the coding implementation tutorial.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>BEST VSCode Settings for Flutter Developers 🚀</title>
      <dc:creator>Ikramul Hasan</dc:creator>
      <pubDate>Mon, 25 Apr 2022 20:09:31 +0000</pubDate>
      <link>https://forem.com/ikramhasan/best-vscode-settings-for-flutter-developers-1m59</link>
      <guid>https://forem.com/ikramhasan/best-vscode-settings-for-flutter-developers-1m59</guid>
      <description>&lt;h2&gt;
  
  
  BEST VSCode Settings for Flutter Developers 🚀
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://flutter.dev/" rel="noopener noreferrer"&gt;Flutter&lt;/a&gt; is a UI toolkit from Google which lets you build apps for any screen - android, ios, windows, linux, mac, and more! It has seen an outstanding amount of love and support from users all around the world, over a very short period of time. In this article, I'll try my best to present the best VSCode settings, custom snippets, and extensions for flutter that I managed to find/invent over the period of my professional experience. I hope you find something useful. &lt;/p&gt;

&lt;h2&gt;
  
  
  Who Am I ❓
&lt;/h2&gt;

&lt;p&gt;My name is Ikramul Hasan and I worked as a flutter trainer for the &lt;a href="https://www.basictrainingsdmga.com/" rel="noopener noreferrer"&gt;App Development Training&lt;/a&gt; program organized by the ICT Division, Government of Bangladesh. These are the setup I made all my students go through. Currently, I'm working as a Senior Application Developer for a multinational company called MakeBell. &lt;/p&gt;

&lt;h2&gt;
  
  
  Best Settings 👍
&lt;/h2&gt;

&lt;p&gt;First of all, although most of you know how to get to the settings page in VSCode, I'd still like to start by showing the process to anyone unaware. &lt;/p&gt;

&lt;h3&gt;
  
  
  How do I get to Settings?
&lt;/h3&gt;

&lt;p&gt;There are two primary ways to get to VSCode settings. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Launch VSCode and click on the gear icon at the bottom left side of your side panel. Then click on &lt;code&gt;Settings&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;Ctrl+Shift+P&lt;/code&gt; on Windows or &lt;code&gt;Cmd+Shift+P&lt;/code&gt; on Mac to launch the command palette, type settings, and click on the Open Settings (UI) option.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650907653331%2F6ZLp_azSi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650907653331%2F6ZLp_azSi.png" alt="2022-04-25 23_17_38-Greenshot.png-mh.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us now start changing the settings. &lt;/p&gt;

&lt;h3&gt;
  
  
  Enable format on save 📝
&lt;/h3&gt;

&lt;p&gt;Perhaps the most important settings for flutter. Let flutter format your dart code on save. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start by searching &lt;code&gt;Editor: Format On Save&lt;/code&gt; in the search bar above &lt;/li&gt;
&lt;li&gt;Enable the option.
It should look like this:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650910481907%2FRUp73gSZq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650910481907%2FRUp73gSZq.png" alt="2022-04-26 00_14_11-Epic Pen Content Surface_ __._DISPLAY1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enable bracket pair colorization and guides 🔴🟡🟢
&lt;/h3&gt;

&lt;p&gt;Everyone working with flutter knows how important it is to distinguish between brackets. Previously, we needed to achieve this using an extension called bracket pair colorizer. But now, VSCode supports this feature natively and it performs much better than the extension. Here are the steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search for &lt;code&gt;bracket pair&lt;/code&gt; in the search bar above &lt;/li&gt;
&lt;li&gt;Check the tickmark on the option &lt;code&gt;Editor › Bracket Pair Colorization&lt;/code&gt;. If it is already enabled, don't change it.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;Editor › Guides: Bracket Pairs&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt; from the dropdown. &lt;/li&gt;
&lt;li&gt;Then check the option named &lt;code&gt;Editor › Guides: Highlight Active Bracket Pair&lt;/code&gt;. This will enable the guides around the brackets. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After all these steps, it should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650908218613%2FF_jHbfGDt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650908218613%2FF_jHbfGDt.png" alt="2022-04-25 23_36_46-Epic Pen Content Surface_ __._DISPLAY2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And your brackets? Much cooler. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650908243349%2F6eMBPCfnV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650908243349%2F6eMBPCfnV.png" alt="2022-04-25 23_29_33-Epic Pen Toolbar.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Automatically rename a class name after changing its filename ✍️
&lt;/h3&gt;

&lt;p&gt;This tells flutter whether to rename files when renaming classes with matching names (for example renaming 'class Person' inside 'person.dart'). If set to 'prompt', will ask each time before renaming. If set to 'always', the file will automatically be renamed. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search for &lt;code&gt;Dart: Rename Files With Classes&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Set it to &lt;code&gt;prompt&lt;/code&gt; in the dropdown.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Change the default organization name 🏛️
&lt;/h3&gt;

&lt;p&gt;When you create an app using the command palette in VSCode, the default organization looks something like this: &lt;code&gt;com.example&lt;/code&gt;. If you want to change it to something like &lt;code&gt;com.your_org&lt;/code&gt; then enable this feature:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search for &lt;code&gt;Dart: Flutter Create Organization&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Edit in settings.json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Change the line &lt;code&gt;"dart.flutterCreateOrganization": "com.example",&lt;/code&gt; to this &lt;code&gt;"dart.flutterCreateOrganization": "com.your_org",&lt;/code&gt; If the line is not present, just add it yourself. &lt;/li&gt;
&lt;li&gt;Now every time you create an app from VSCode, it will have that custom org name. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Enable UI guides 📏
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650909318683%2FV7ueOJjsZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650909318683%2FV7ueOJjsZ.png" alt="ui_guides.png"&gt;&lt;/a&gt;&lt;br&gt;
This tells flutter whether to enable the UI guide. UI guides are the white lines you see in the screenshot above. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search for &lt;code&gt;Dart: Preview Flutter Ui Guides&lt;/code&gt; and enable it. &lt;/li&gt;
&lt;li&gt;Search for &lt;code&gt;Dart: Preview Flutter Ui Guides Custom Tracking&lt;/code&gt; and enable it. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: Both of these features are experimental, and eat too much resources. If you have a particularly slow PC, I recommend disabling it. &lt;/p&gt;

&lt;h3&gt;
  
  
  Automatically add &lt;code&gt;const&lt;/code&gt; modifier 💁
&lt;/h3&gt;

&lt;p&gt;Flutter now includes linting by default in every flutter app. As a result, if you do not add the const modifier, it shows a warning. This can become very messy and adding const manually can become very tedious. To add const modifier automatically every time you save, do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the command palette and type &lt;code&gt;settings&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Open Settings (json)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add this code at the bottom of the file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"editor.codeActionsOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="nl"&gt;"source.fixAll"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Enable settings sync ☁️
&lt;/h3&gt;

&lt;p&gt;After all these efforts of creating the best settings, you don't want to lose them after every new VSCode installation. Enabling settings sync will let you sync your settings using your GitHub account. As a result, if you install VSCode on a brand new PC and log in to your GitHub account in VSCode, all these settings will be automatically synced for you. This means you need to do these steps only once. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on the account icon on the bottom left of the sidebar. &lt;/li&gt;
&lt;li&gt;Login using your GitHub account.&lt;/li&gt;
&lt;li&gt;Make sure you see 'Settings sync is on' in the menu. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650911349837%2Fm8O1VWWXH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1650911349837%2Fm8O1VWWXH.png" alt="2022-04-26 00_25_11-Greenshot.png-mh.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you for coming this far 🎉🎉🎉
&lt;/h2&gt;

&lt;p&gt;Let me know if I missed some settings. You'll find all my socials here on my &lt;a href="https://ikramhasan.com/" rel="noopener noreferrer"&gt;portfolio site&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>vscode</category>
      <category>settings</category>
    </item>
  </channel>
</rss>
