subject

Need some help creating a tic tac toe math random AI that won't override buttons when that button already has an X or O in it. This is what I have so far:

public void CreateInfo(String ButtonNumber) {
if (XorO == true) {
if (ButtonNumber. equals("One") && B1 == true) {
One = "X";
XorO = false;
B1 = false;
}
if (ButtonNumber. equals("Two") && B2 == true) {
Two = "X";
XorO = false;
B2 = false;
}
if (ButtonNumber. equals("Three") && B3 == true) {
Three = "X";
XorO = false;
B3 = false;
}
if (ButtonNumber. equals("Four") && B4 == true) {
Four = "X";
XorO = false;
B4 = false;
}
if (ButtonNumber. equals("Five") && B5 == true) {
Five = "X";
XorO = false;
B5 = false;
}
if (ButtonNumber. equals("Six") && B6 == true) {
Six = "X";
XorO = false;
B6 = false;
}
if (ButtonNumber. equals("Seven") && B7 == true) {
Seven = "X";
XorO = false;
B7 = false;
}
if (ButtonNumber. equals("Eight") && B8 == true) {
Eight = "X";
XorO = false;
B8 = false;
}
if (ButtonNumber. equals("Nine") && B9 == true) {
Nine = "X";
XorO = false;
B9 = false;
}
}
int max = 9;
int min = 1;
int range = max - min + 1;
int rand = (int) (Math. random() * range) + min;
System. out. println(rand);
if (rand == 1 && BB1 == false) {
One = "O";
XorO = true;
BB1 = true;
}
if (rand == 2 && BB2 == false) {
Two = "O";
XorO = true;
BB2 = true;
}
if (rand == 3 && BB3 == false) {
Three = "O";
XorO = true;
BB3 = true;
}
if (rand == 4 && BB4 == false) {
Four = "O";
XorO = true;
BB4 = true;
}
if (rand == 5 && BB5 == false) {
Five = "O";
XorO = true;
BB5 = true;
}
if (rand == 6 && BB6 == false) {
Six = "O";
XorO = true;
BB6 = true;
}
if (rand == 7 && BB7 == false) {
Seven = "O";
XorO = true;
BB7 = true;
}
if (rand == 8 && BB8 == false) {
Eight = "O";
XorO = true;
BB8 = true;
}
if (rand == 9 && BB9 == false) {
Nine = "O";
XorO = true;
BB9 = true;
}
if (One == "X" && Two == "X" && Three == "X"
|| Four == "X" && Five == "X" && Six == "X"
|| Seven == "X" && Eight == "X" && Nine == "X"
|| One == "X" && Five == "X" && Nine == "X"
|| Three == "X" && Five == "X" && Seven == "X"
|| One == "X" && Four == "X" && Seven == "X"
|| Two == "X" && Five == "X" && Eight == "X"
|| Three == "X" && Six == "X" && Nine == "X") {
One = "X Wins!";
}
if (One == "O" && Two == "O" && Three == "O"
|| Four == "O" && Five == "O" && Six == "O"
|| Seven == "O" && Eight == "O" && Nine == "O"
|| One == "O" && Five == "O" && Nine == "O"
|| Three == "O" && Five == "O" && Seven == "O"
|| One == "O" && Four == "O" && Seven == "O"
|| Two == "O" && Five == "O" && Eight == "O"
|| Three == "O" && Six == "O" && Nine == "O") {
One = "O Wins!";
}
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:30
Primary tech skills are skills that are necessary for success in online education
Answers: 3
question
Computers and Technology, 23.06.2019 01:30
Which tab is used to change the theme of a photo album slide show? a. design b. view c. transitions d. home
Answers: 1
question
Computers and Technology, 24.06.2019 02:20
Peter is thinking of a number which isless than 50. the number has 9 factors.when he adds 4 to the number, itbecomes a multiple of 5. what is thenumber he is thinking of ?
Answers: 1
question
Computers and Technology, 24.06.2019 07:30
Aproject involves many computing systems working together on disjointed task towards a single goal what form of computing would the project be using
Answers: 3
You know the right answer?
Need some help creating a tic tac toe math random AI that won't override buttons when that button al...
Questions
Questions on the website: 13722363