Java Tic-Tac-Toe AI Implementation
Java Tic-Tac-Toe AI Implementation
--------------------------------------------------------------------------------------------------------------------------------------
[Link]
Roll No:80
Batch:B4
Program
[Link]
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
public class Cell
{
int row, col;
}
[Link]
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
public class Computer {
else if (b[0][col]==opponent)
return -10;
}
}
return 0;
}
if(score == 10)
return score-depth;
if(score == -10)
return score+depth;
if(isMax)
{
if([Link](1))
{
for(int i = 0; i < 3; i ++)
{
for(int j = 0; j < 3; j ++)
{
if(mat[i][j] == -1)
{
[Link] = i;
[Link] = j;
break;
}
}
}
mat[i][j] = 1;
mat[[Link]][[Link]] = -1;
}
}
}
}
else
{
for(int i = 0; i < 3; i ++)
{
for(int j = 0; j < 3; j ++)
{
if(mat[i][j] == -1)
{
mat[i][j] = 1;
mat[i][j] = -1;
}
}
}
}
return best;
}
else
{
if([Link](0))
{
for(int i = 0; i < 3; i ++)
{
for(int j = 0; j < 3; j ++)
{
if(mat[i][j] == -1)
{
[Link] = i;
[Link] = j;
break;
}
}
}
mat[i][j] = 0;
mat[[Link]][[Link]] = -1;
}
}
}
}
else
{
for(int i = 0; i < 3; i ++)
{
for(int j = 0; j < 3; j ++)
{
if(mat[i][j] == -1)
{
mat[i][j] = 0;
best = [Link](best, minimax(mat, depth+1, !isMax));
mat[i][j] = -1;
}
}
}
}
return best;
}
}
if([Link](1))
{
Cell empty = new Cell();
for(int i = 0; i < 3; i ++)
{
for(int j = 0; j < 3; j ++)
{
if(mat[i][j] == -1)
{
[Link] = i;
[Link] = j;
break;
}
}
}
mat[i][j] = 1;
mat[[Link]][[Link]] = -1;
mat[i][j] = -1;
if(bestVal!= 10)
{
boolean mid = [Link]();
boolean corner;
if(!mid)
{
corner = [Link]();
if(corner)
return null;
}
else
return null;
}
return bestMove;
}
}
[Link]
import [Link];
import [Link];
/*
* To change this license header, choose License Headers in Project Properties.
* To change+6 this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
public class TheFrame extends [Link] {
/**
* Creates new form TheFrame
*/
static int chance = 1;
static int win = -1;
static int selected = 0;
static int selectedBut = 0;
Color bgcolor;
static Computer c = new Computer();
public TheFrame() {
initComponents();
bgcolor = [Link]();
if(chance == 1)
{
Cell bestm = [Link](getBoard());
makeMove([Link], [Link]);
chance = 0;
}
}
return res;
}
}
}
if(val == 1)
{
for(String st : ar)
{
if([Link]("Computer"))
noval++;
}
}
else if(val == 0)
{
for(String st : ar)
{
if([Link]("Human"))
noval++;
}
}
return noval == 4;
}
return ar;
}
return mat;
}
//[Link](this, st);
if(flag == false)
{
if(win == -1)
[Link]("No winner found. Game Over");
}
}
/*String st = "";
for(int i = 0; i < 3; i ++)
{
for(int j = 0; j < 3; j ++)
{
st = st + ""+mat[i][j] + "\t";
}
st = st + "\n";
}
[Link](this, st);*/
return false;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation([Link].EXIT_ON_CLOSE);
getContentPane().setLayout(new [Link](2, 0));
getContentPane().add(jPanel1);
[Link]("RESET");
[Link](new [Link]() {
public void actionPerformed([Link] evt) {
resetActionPerformed(evt);
}
});
getContentPane().add(jPanel2);
pack();
}// </editor-fold>
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 1;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
//if(chance == 1)
//{
// if(checkFour(1))
// {
// switch ([Link]()) {
// case "":
// [Link](this, "Only four X allowed. Select an X
to move");
// return;
// case "Computer":
// [Link]([Link]);
// selected = 1;
// selectedBut = 1;
// break;
// case "Human":
// [Link](this, "You can select only X tile");
// return;
// default:
// break;
// }
// }
// else
// {
// if([Link]().equals(""))
// {
// [Link]("Computer");
// chance = 0;
// }
// else
// {
// [Link](this, "This box cannot be edited",
"Invalid box", JOptionPane.ERROR_MESSAGE);
// }
// }
//}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 2;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}*/
if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 2;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/* if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}
*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 3;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}*/
if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 3;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/* if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 4;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
else*/ if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 4;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 5;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
else */if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 5;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 6;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
else */if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 6;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 7;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
else*/ if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 7;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
} if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 8;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
else*/ if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 8;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
}
if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
if([Link]() == [Link])
{
[Link](bgcolor);
selected = 0;
return;
}
if(selected != 1)
{
/*if(chance == 1)
{
if(checkFour(1))
{
switch ([Link]()) {
case "":
[Link](this, "Only four X allowed. Select an X
to move");
return;
case "Computer":
[Link]([Link]);
selected = 1;
selectedBut = 9;
break;
case "Human":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Computer");
chance = 0;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
else*/ if(chance == 0)
{
if(checkFour(0))
{
switch ([Link]()) {
case "":
[Link](this, "Only four O allowed. Select an O
to move");
return;
case "Human":
[Link]([Link]);
selected = 1;
selectedBut = 9;
break;
case "Computer":
[Link](this, "You can select only X tile");
return;
default:
break;
}
}
else
{
if([Link]().equals(""))
{
[Link]("Human");
chance = 1;
}
else
{
[Link](this, "This box cannot be edited", "Invalid
box", JOptionPane.ERROR_MESSAGE);
}
}
}
}
else
{
switch ([Link]()) {
case "Computer":
[Link](this, "Select a blank tile");
return;
case "Human":
[Link](this, "Select a blank tile");
return;
case "":
switch(selectedBut)
{
case 1:
[Link]("");
[Link](bgcolor);
break;
case 2:
[Link]("");
[Link](bgcolor);
break;
case 3:
[Link]("");
[Link](bgcolor);
break;
case 4:
[Link]("");
[Link](bgcolor);
break;
case 5:
[Link]("");
[Link](bgcolor);
break;
case 6:
[Link]("");
[Link](bgcolor);
break;
case 7:
[Link]("");
[Link](bgcolor);
break;
case 8:
[Link]("");
[Link](bgcolor);
break;
case 9:
[Link]("");
[Link](bgcolor);
break;
}if(chance == 0)
{
[Link]("Human");
chance = 1;
} selected = 0;
break;
default:
break;
}
}
if(checkWinner())
return;
//checkAllDone();
if(chance == 1)
{
/*if(checkMid())
{
chance = 0;
checkWinner();
return;
}
if(checkCorner())
{
checkWinner();
return;
}*/
[Link]("hi");
Cell bestm = [Link](getBoard());
if(bestm!=null)
{
makeMove([Link], [Link]);
}
chance = 0;
}
checkWinner();
}
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
[Link](bgcolor);
chance = 1;
setAllButVal(true);
[Link]("");
if(chance == 1)
{
Cell bestm = [Link](getBoard());
makeMove([Link], [Link]);
chance = 0;
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
[Link]
*/
try {
for ([Link] info :
[Link]()) {
if ("Nimbus".equals([Link]())) {
[Link]([Link]());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
[Link] ex) {
[Link]([Link]()).log([Link].S
EVERE, null, ex);
}
//</editor-fold>
//</editor-fold>