title: How to go through the maximum amount of Tic Tac Toe possibilities?
body: <p>I wanted to know how many amounts of Tic Tac Toes possibilities there is, so I searched the web and found an mathematical theorem which says that there is <strong>255168</strong> possible games in Tic Tac Toe.</p>
  
  <p>Website: <a href="http://www.se16.info/hgb/tictactoe.htm" rel="nofollow">http://www.se16.info/hgb/tictactoe.htm</a></p>
  
  <p>So I wonder, I can make an program and see how fast can the computer go through each and every one of those possibilities, then I made this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;time.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  
  typedef int TTTField[9];
  
  bool checkIfWon(TTTField j){
      if(j[0]==1&amp;&amp;j[1]==1&amp;&amp;j[2]==1) return true;
      if(j[0]==2&amp;&amp;j[1]==2&amp;&amp;j[2]==2) return true;
      if(j[3]==1&amp;&amp;j[4]==1&amp;&amp;j[5]==1) return true;
      if(j[3]==2&amp;&amp;j[4]==2&amp;&amp;j[5]==2) return true;
      if(j[6]==1&amp;&amp;j[7]==1&amp;&amp;j[8]==1) return true;
      if(j[6]==2&amp;&amp;j[7]==2&amp;&amp;j[8]==2) return true;
      if(j[0]==1&amp;&amp;j[3]==1&amp;&amp;j[6]==1) return true;
      if(j[0]==2&amp;&amp;j[3]==2&amp;&amp;j[6]==2) return true;
      if(j[1]==1&amp;&amp;j[4]==1&amp;&amp;j[7]==1) return true;
      if(j[1]==2&amp;&amp;j[4]==2&amp;&amp;j[7]==2) return true;
      if(j[2]==1&amp;&amp;j[5]==1&amp;&amp;j[8]==1) return true;
      if(j[2]==2&amp;&amp;j[5]==2&amp;&amp;j[8]==2) return true;
      if(j[0]==1&amp;&amp;j[4]==1&amp;&amp;j[8]==1) return true;
      if(j[0]==2&amp;&amp;j[4]==2&amp;&amp;j[8]==2) return true;
      if(j[2]==1&amp;&amp;j[4]==1&amp;&amp;j[6]==1) return true;
      if(j[2]==2&amp;&amp;j[4]==2&amp;&amp;j[6]==2) return true;
      return false;
  }
  
  bool checkIfItsOver(TTTField j){
      for(int i=0;i&lt;9;i++){
          if(j[i]==0){
              return false;
          }
      }
      return true;
  }
  
  bool checkListOfFields(TTTField game, TTTField listOfFields[], int amountAdded){
      int i,j;
      for(j=0;j&lt;amountAdded;j++){
          int temporaryField=0;
          for(i=0;i&lt;9;i++){
              if(game[i]==listOfFields[j][i]) temporaryField++;
          }
          if(temporaryField==9)return true;
      }
      return false;
  }
  
  void clearField(TTTField game){
      int i;
      for(i=0;i&lt;9;i++) game[i]=0;
  }
  
  void addlistOfFields(TTTField game, TTTField listOfFields[], int amountAdded){
      for(int i=0;i&lt;9;i++) listOfFields[amountAdded][i]=game[i];
  }
  
  int main(){
      TTTField listOfFields[50000];
      TTTField temporaryField;
      int amountAdded=0,randA,round=1,roundCounter=0,amountPassed=0,amountOfWins=0,amountOfDraws=0,winWith5=0,winWith6=0,winWith7=0,winWith8=0,winWith9=0,roundAmountFinished=0;
      for(int i=0;roundCounter&lt;100000;i++){
          clearField(temporaryField);
          roundAmountFinished=0;
          do{
              do{
                  randA=rand()%9;
              }while(temporaryField[randA]!=0);
              temporaryField[randA]=round;
              if(checkIfWon(temporaryField)){
                  break;
              }
              if(checkIfItsOver(temporaryField)){
                  break;
              }
              round=round==1?2:1;
              roundAmountFinished++;
          }while(1);
          if(!checkListOfFields(temporaryField,listOfFields,amountAdded)){
              addlistOfFields(temporaryField,listOfFields,amountAdded);
              amountAdded++;
              if(checkIfWon(temporaryField)){
                  amountOfWins++;
              }
              if(checkIfItsOver(temporaryField)){
                  amountOfDraws++;
              }
              switch(roundAmountFinished){
                  case 4:
                      winWith5++;
                      break;
                  case 5:
                      winWith6++;
                      break;
                  case 6:
                      winWith7++;
                      break;
                  case 7:
                      winWith8++;
                      break;
                  case 8:
                      winWith9++;
                      break;
              }
          }
          if(amountPassed==amountAdded){
              roundCounter++;
          }else roundCounter=0;
          amountPassed=amountAdded;
      }
      system("cls");
      printf("Total: %d, roundCounter: %d\nWins with 5 rounds:%d\nWins with 6 rounds:%d\nWins with 7 rounds:%d\nWins with 8 rounds:%d\nWins with 9 rounds:%d\namountOfWins: %d, amountOfDraws: %d",amountAdded,roundCounter,winWith5,winWith6,winWith7,winWith8,winWith9,amountOfWins,amountOfDraws);
  
      return 0;
  }
  </code></pre>
  
  <p>But it returns me an total amount of: <strong>1916</strong>, which is different from the one in the website, and I wonder what is wrong with my code.</p>
  
  <p>Some information about the code:</p>
  
  <ul>
  <li>The field is a array of integer with 9 indexes in which 1 represents crosses and 2 represents circles, also 0 is for null field.</li>
  <li>It generates an random value from 0~9 (if it hasn't been picked before) than it puts an 1 or 2 (depending whom round it is) always checking if someone won or the game has resulted in a draw.</li>
  <li>After finishing the game it will check if that possibility is already on the list, if it is it will do nothing and proceed to another one.</li>
  <li>It will finish when it went through 100k of possibilities without adding a single one to the list.</li>
  </ul>
  
  <p>Where is the problem?</p>