email me at borlaj@portlandschools.org

Loading
notes previous (12/<12) submit the dump links  
 

Tic Tac Toe

Starter code

This project is split into 3 people

 

AI Class

  • Search through moves to make the best move

 

Board Class

  • In charge of printing the board with images (see images)

Tic Tac Toe Class

 

    public char gameStatus()
    {
         for (int i=0;i<3;i++)
        {
            for (int j=0;j<3;j++)
                if (theBoard[i][j]==' ')
                      return 'n';
        }
        if (Math.random()<.4)
            return 'w';
        if (Math.random()<.4)
            return 'l';
        return 't';
    }
    
    /**
     * its going to make a random move FOR TESTING PURPOSES ONLY
     */
    public boolean makeUserMove(int mouseX, int mouseY)
    {
       while (true)
       {
          int col=(int)(Math.random()*3);
          int row=(int)(Math.random()*3);
          if (theBoard[row][col]==' ')
          {
                theBoard[row][col]='X';
                return true;                        
          }           
       }
    }

    //in the Opponent - this will make a random move 
    public void makeMove(Board currentBoard)
    {
         while (true)
         {
              int col=(int)(Math.random()*3);
              int row=(int)(Math.random()*3);
              if (currentBoard.theBoard[row][col]==' ')
              {
                    currentBoard.theBoard[row][col]='0';
                    return;                        
              }           
          }
    }   				
			

Board Group

 

In the TicTacToe, replace paint below:

    public void paint(Graphics g)
{
Board b=new Board();
b.drawboard(g);
}