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 09:30
Is a string of code written to hurt others by damaging or destroying
Answers: 1
question
Computers and Technology, 22.06.2019 10:30
Dave has to create animations for a game. which tool can dave use?
Answers: 3
question
Computers and Technology, 22.06.2019 21:00
Kirk found a local community college with a two-year program and he is comparing the cost with that of an out-of-state two-year school. what is the expected total cost for one year at the local community college if kirk lives at home? what is the expected total cost for one year at the out-of-state school if kirk lives on campus?
Answers: 2
question
Computers and Technology, 23.06.2019 14:00
Technician a says that with self-adjusting clutch systems, the release bearing constantly rotates. technician b says that the ball bearing portion of the release bearing should be lubricated with high-temperature grease during routine maintenance. which technician is correct?
Answers: 2
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
question
Mathematics, 11.06.2021 22:40
question
Mathematics, 11.06.2021 22:40
question
Chemistry, 11.06.2021 22:40
Questions on the website: 13722367