Tic tac toe machine
in
Programming Questions
•
2 years ago
hi, im 14 and have recently got involved in processing.
I started with processing by messing around and creating stupid interactive games where you draw circles and they get bigger or other stupid things like that, but a few days ago i started on a big project. To make a tic tac toe machine, payer vs computer. After reading some of "Learning Processing" by Daniel Shiffman i knew the basics of Case and Swich so i thought it was going to be pretty much easy. However i realized that my method of writing down every possible combination of a tic tac toe game was way too long and that their must be a better way to do it.
So ive come to ask help on my tic tac toe game. Ive already done alot of the work and would appreciate any help even if it means starting all over again.
I will copy and paste some of the logic of the first square to give you an idea of how it works.
-
//0 = empty square//1= player square//2 = computer square
void s1 () {
if(s1 ==1) {s5 = 2;}
//first layer//
//s2//if (s1 == 1) {if (s2 == 1) {if (s5 == 2) {if (s3 == 0) {if (s4 == 0) {if (s6 == 0) {if (s7 == 0) {if (s8 == 0) {if (s9 == 0) {s3 = 2;}}}}}}}}}//s3//if (s1 == 1) {if (s3 == 1) {if (s5 == 2) {if (s2 == 0) {if (s4 == 0) {if (s6 == 0) {if (s7 == 0) {if (s8 == 0) {if (s9 == 0) {s2 = 2;}}}}}}}}}//s4//if (s1 == 1) {if (s4 == 1) {if (s5 == 2) {if (s2 == 0) {if (s3 == 0) {if (s6 == 0) {if (s7 == 0) {if (s8 == 0) {if (s9 == 0) {s7 = 2;}}}}}}}}}//s6//if (s1 == 1) {if (s6 == 1) {if (s5 == 2) {if (s2 == 0) {if (s3 == 0) {if (s4 == 0) {if (s7 == 0) {if (s8 == 0) {if (s9 == 0) {s7 = 2;}}}}}}}}}//s7//if (s1 == 1) {if (s7 == 1) {if (s5 == 2) {if (s2 == 0) {if (s3 == 0) {if (s4 == 0) {if (s6 == 0) {if (s8 == 0) {if (s9 == 0) {s4 = 2;}}}}}}}}}//s8//if (s1 == 1) {if (s8 == 1) {if (s5 == 2) {if (s2 == 0) {if (s3 == 0) {if (s4 == 0) {if (s6 == 0) {if (s7 == 0) {if (s9 == 0) {s7 = 2;}}}}}}}}}
//s9//if (s1 == 1) {if (s9 == 1) {if (s5 == 2) {if (s3 == 0) {if (s4 == 0) {if (s6 == 0) {if (s7 == 0) {if (s8 == 0) {
s6 = 2;}}}}}}}}
1