Nick Koumaris
Published © GPL3+

Arduino Touch Tic-Tac-Toe Game

Here you make an artifically intelligent game opponent.

EasyFull instructions provided1 hour13,161
Arduino Touch Tic-Tac-Toe Game

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
<p>int firstMoves[]={0,2,6,8}; // will use these positions first</p><p>  for(counter=0;counter<4;counter++) //Count first moves played
  {
    if(board[firstMoves[counter]]!=0) // First move is played by someone
    {
      movesPlayed++;
    }
  }  
  do{
    if(moves<=2)
    {
      int randomMove =random(4); 
      int c=firstMoves[randomMove];
      
      if (board[c]==0)
      {  
        delay(1000);
        board[c]=2;
        Serial.print(firstMoves[randomMove]);
        Serial.println();
        drawCpuMove(firstMoves[randomMove]);
        b=1;
      }   
        
    }</p>

Code snippet #2

Plain text
<p>int checkOpponent()<br>{
  if(board[0]==1 && board[1]==1 && board[2]==0)
  return 2;
  else if(board[0]==1 && board[1]==0 && board[2]==1)
  return 1;
  else if (board[1]==1 && board [2]==1 && board[0]==0)
  return 0;
  else if (board[3]==1 && board[4]==1 && board[5]==0)
  return 5;
  else if (board[4]==1 && board[5]==1&& board[3]==0)
  return 3;
  else if (board[3]==1 && board[4]==0&& board[5]==1)
  return 4;
  else if (board[1]==0 && board[4]==1&& board[7]==1)
  return 1;
  else
  return 100;
}</p>

Github

https://github.com/adafruit/Adafruit-GFX-Library

Github

https://github.com/adafruit/Touch-Screen-Library

Credits

Nick Koumaris

Nick Koumaris

7 projects • 87 followers
My name is Nick Koumaris and I am a software engineer from Sparta, Greece. I love building projects and share them with the world!
Contact

Comments