Computers and Technology
Computers and Technology, 12.02.2020 23:08, epmeche05

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!";
}
}
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:10, AdoNice
How can i delete permalinks from a word press site?
Answers: 1
image
Computers and Technology, 23.06.2019 09:30, jason9394
Facial expressions and gestures are examples of messages.
Answers: 3
image
Computers and Technology, 23.06.2019 14:30, bernicewhite156
Select the correct answer. what does it indicate when a website displays https instead of http? a. the website is secure. b. there is no secure sockets layer. c. the secure sockets layer is hidden. d. the website is not secure.
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, lopez7512
What is the total resistance in a circuit that contains three 60 ohm resistors connected in a series? a. 20 ohms b. 120 ohms c. 60 ohms d. 180 ohms
Answers: 2
Do you know the correct answer?
Need some help creating a tic tac toe math random AI that won't override buttons when that button al...

Questions in other subjects: