Paso 3: código
int computerArray [10] = {2,3,4,5,6,7,8,9,10};
typedef enum {}
ABIERTO,
CLOSED_C,
CLOSED_P
}
BoxState;
int vuelta = 0;
int switchArray [10] = {}
11,12,13,14,15,16,17,18,19};
int switchArray2 [10] = {}
2,3,4,5,6,7,8,9,10};
void setup() {}
int i;
int e;
Serial.Begin(9600);
randomSeed(analogRead(0));
para (i = 0; i < 9; i += 1) {}
pinMode (switchArray [i], entrada);
}
para (e = 0; e < 9; e += 1) {}
pinMode (switchArray2 [e], salida);
}
}
BoxState box1 = abierto;
BoxState box2 = abierto;
Caja3 BoxState = abierto;
BoxState box4 = abierto;
Box5 BoxState = abierto;
BoxState box6 = abierto;
BoxState box7 = abierto;
BoxState box8 = abierto;
BoxState box9 = abierto;
juego int = 1;
int matriz1 [9] = {13,19,16,13,12,11,13,11};
int matriz2 [9] = {12,14,17,19,14,15,14,14};
int Array3 [9] = {11,15,18,16,17,18,18,16};
void checkGame() {}
q int;
para (q = 0; q < 8; q += 1) {}
if(digitalRead(Array1[q]) == alto & & digitalRead(Array2[q]) & & {digitalRead(Array3[q]))}
juego = 2;
}
}
}
void checkComputerWin() {}
Si (girar a %2 == 1) {}
Si (box1 == CLOSED_C & & box2 == CLOSED_C & & Caja3 == abierto) {}
Caja3 = CLOSED_C;
digitalWrite(7,HIGH);
juego = 0;
Gire a += 1;
}
else if (box1 == CLOSED_C & & Caja3 == CLOSED_C & & box2 == abierto) {}
box2 = CLOSED_C;
digitalWrite(8,HIGH);
juego = 0;
Gire a += 1;
}
else if (Caja3 == CLOSED_C & & box2 == CLOSED_C & & box1 == abierto) {}
BOX1 = CLOSED_C;
digitalWrite(9,HIGH);
juego = 0;
Gire a += 1;
}
else if (box4 == CLOSED_C & & box5 == CLOSED_C & & box6 == abierto) {}
box6 = CLOSED_C;
digitalWrite(4,HIGH);
juego = 0;
Gire a += 1;
}
else if (box5 == CLOSED_C & & box6 == CLOSED_C & & box4 == abierto) {}
Box4 = CLOSED_C;
digitalWrite(6,HIGH);
juego = 0;
Gire a += 1;
}
else if (box4 == CLOSED_C & & box6 == CLOSED_C & & box5 == abierto) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
juego = 0;
Gire a += 1;
}
else if (box7 == CLOSED_C & & box8 == CLOSED_C & & box9 == abierto) {}
box9 = CLOSED_C;
digitalWrite(10,HIGH);
juego = 0;
Gire a += 1;
}
else if (box8 == CLOSED_C & & box9 == CLOSED_C & & box7 == abierto) {}
box7 = CLOSED_C;
digitalWrite(3,HIGH);
juego = 0;
Gire a += 1;
}
else if (box7 == CLOSED_C & & box9 == CLOSED_C & & box8 == abierto) {}
box8 = CLOSED_C;
digitalWrite(2,HIGH);
juego = 0;
Gire a += 1;
}
else if (box1 == CLOSED_C & & box4 == CLOSED_C & & box7 == abierto) {}
box7 = CLOSED_C;
digitalWrite(3,HIGH);
juego = 0;
Gire a += 1;
}
else if (box1 == CLOSED_C & & box7 == CLOSED_C & & box4 == abierto) {}
Box4 = CLOSED_C;
digitalWrite(6,HIGH);
juego = 0;
Gire a += 1;
}
else if (box4 == CLOSED_C & & box7 == CLOSED_C & & box1 == abierto) {}
BOX1 = CLOSED_C;
digitalWrite(9,HIGH);
juego = 0;
Gire a += 1;
}
else if (box5 == CLOSED_C & & box2 == CLOSED_C & & box8 == abierto) {}
box8 = CLOSED_C;
digitalWrite(2,HIGH);
juego = 0;
Gire a += 1;
}
else if (box8 == CLOSED_C & & box2 == CLOSED_C & & box5 == abierto) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
juego = 0;
Gire a += 1;
}
else if (box5 == CLOSED_C & & box8 == CLOSED_C & & box2 == abierto) {}
box2 = CLOSED_C;
digitalWrite(8,HIGH);
juego = 0;
Gire a += 1;
}
else if (Caja3 == CLOSED_C & & box6 == CLOSED_C & & box9 == abierto) {}
box9 = CLOSED_C;
digitalWrite(10,HIGH);
juego = 0;
Gire a += 1;
}
else if (box6 == CLOSED_C & & box9 == CLOSED_C & & Caja3 == abierto) {}
Caja3 = CLOSED_C;
digitalWrite(7,HIGH);
juego = 0;
Gire a += 1;
}
else if (Caja3 == CLOSED_C & & box9 == CLOSED_C & & box6 == abierto) {}
box6 = CLOSED_C;
digitalWrite(4,HIGH);
juego = 0;
Gire a += 1;
}
else if (box1 == CLOSED_C & & box5 == CLOSED_C & & box9 == abierto) {}
box9 = CLOSED_C;
digitalWrite(10,HIGH);
juego = 0;
Gire a += 1;
}
else if (box5 == CLOSED_C & & box9 == CLOSED_C & & box1 == abierto) {}
BOX1 = CLOSED_C;
digitalWrite(9,HIGH);
juego = 0;
Gire a += 1;
}
else if (box9 == CLOSED_C & & box1 == CLOSED_C & & box5 == abierto) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
juego = 0;
Gire a += 1;
}
else if (Caja3 == CLOSED_C & & box5 == CLOSED_C & & box7 == abierto) {}
box7 = CLOSED_C;
digitalWrite(3,HIGH);
juego = 0;
Gire a += 1;
}
else if (box7 == CLOSED_C & & box5 == CLOSED_C & & Caja3 == abierto) {}
Caja3 = CLOSED_C;
digitalWrite(7,HIGH);
juego = 0;
Gire a += 1;
}
else if (Caja3 == CLOSED_C & & box7 == CLOSED_C & & box5 == abierto) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
juego = 0;
Gire a += 1;
}
}
}
void checkPlayerWin() {}
Si (box1 == CLOSED_P & & box2 == CLOSED_P & & Caja3 == abra & y vuelta %2 == 1) {}
Caja3 = CLOSED_C;
digitalWrite(7,HIGH);
Gire a += 1;
}
Si (box1 == CLOSED_P & & Caja3 == CLOSED_P & & box2 == abra & y vuelta %2 == 1) {}
box2 = CLOSED_C;
digitalWrite(8,HIGH);
Gire a += 1;
}
Si (Caja3 == CLOSED_P & & box2 == CLOSED_P & & box1 == abra & y vuelta %2 == 1) {}
BOX1 = CLOSED_C;
digitalWrite(9,HIGH);
Gire a += 1;
}
Si (box4 == CLOSED_P & & box5 == CLOSED_P & & box6 == abra & y vuelta %2 == 1) {}
box6 = CLOSED_C;
digitalWrite(4,HIGH);
Gire a += 1;
}
Si (box5 == CLOSED_P & & box6 == CLOSED_P & & box4 == abra & y vuelta %2 == 1) {}
Box4 = CLOSED_C;
digitalWrite(6,HIGH);
Gire a += 1;
}
Si (box4 == CLOSED_P & & box6 == CLOSED_P & & box5 == abra & y vuelta %2 == 1) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
Gire a += 1;
}
Si (box7 == CLOSED_P & & box8 == CLOSED_P & & box9 == abra & y vuelta %2 == 1) {}
box9 = CLOSED_C;
digitalWrite(10,HIGH);
Gire a += 1;
}
Si (box8 == CLOSED_P & & box9 == CLOSED_P & & box7 == abra & y vuelta %2 == 1) {}
box7 = CLOSED_C;
digitalWrite(3,HIGH);
Gire a += 1;
}
Si (box7 == CLOSED_P & & box9 == CLOSED_P & & box8 == abra & y vuelta %2 == 1) {}
box8 = CLOSED_C;
digitalWrite(2,HIGH);
Gire a += 1;
}
Si (box1 == CLOSED_P & & box4 == CLOSED_P & & box7 == abra & y vuelta %2 == 1) {}
box7 = CLOSED_C;
digitalWrite(3,HIGH);
Gire a += 1;
}
Si (box1 == CLOSED_P & & box7 == CLOSED_P & & box4 == abra & y vuelta %2 == 1) {}
Box4 = CLOSED_C;
digitalWrite(6,HIGH);
Gire a += 1;
}
Si (box4 == CLOSED_P & & box7 == CLOSED_P & & box1 == abra & y vuelta %2 == 1) {}
BOX1 = CLOSED_C;
digitalWrite(9,HIGH);
Gire a += 1;
}
Si (box5 == CLOSED_P & & box2 == CLOSED_P & & box8 == abra & y vuelta %2 == 1) {}
box8 = CLOSED_C;
digitalWrite(2,HIGH);
Gire a += 1;
}
Si (box8 == CLOSED_P & & box2 == CLOSED_P & & box4 == abra & y vuelta %2 == 1) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
Gire a += 1;
}
Si (box5 == CLOSED_P & & box8 == CLOSED_P & & box2 == abra & y vuelta %2 == 1) {}
box2 = CLOSED_C;
digitalWrite(8,HIGH);
Gire a += 1;
}
Si (Caja3 == CLOSED_P & & box6 == CLOSED_P & & box9 == abra & y vuelta %2 == 1) {}
box9 = CLOSED_C;
digitalWrite(10,HIGH);
Gire a += 1;
}
Si (box6 == CLOSED_P & & box9 == CLOSED_P & & Caja3 == abra & y vuelta %2 == 1) {}
Caja3 = CLOSED_C;
digitalWrite(7,HIGH);
Gire a += 1;
}
Si (Caja3 == CLOSED_P & & box9 == CLOSED_P & & box6 == abra & y vuelta %2 == 1) {}
box6 = CLOSED_C;
digitalWrite(4,HIGH);
Gire a += 1;
}
Si (box1 == CLOSED_P & & box5 == CLOSED_P & & box9 == abra & y vuelta %2 == 1) {}
box9 = CLOSED_C;
digitalWrite(10,HIGH);
Gire a += 1;
}
Si (box5 == CLOSED_P & & box9 == CLOSED_P & & box1 == abra & y vuelta %2 == 1) {}
BOX1 = CLOSED_C;
digitalWrite(9,HIGH);
Gire a += 1;
}
Si (box9 == CLOSED_P & & box1 == CLOSED_P & & box5 == abra & y vuelta %2 == 1) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
Gire a += 1;
}
Si (Caja3 == CLOSED_P & & box5 == CLOSED_P & & box7 == abra & y vuelta %2 == 1) {}
box7 = CLOSED_C;
digitalWrite(3,HIGH);
Gire a += 1;
}
Si (box7 == CLOSED_P & & box5 == CLOSED_P & & Caja3 == abra & y vuelta %2 == 1) {}
Caja3 = CLOSED_C;
digitalWrite(7,HIGH);
Gire a += 1;
}
Si (Caja3 == CLOSED_P & & box7 == CLOSED_P & & box5 == abra & y vuelta %2 == 1) {}
Box5 = CLOSED_C;
digitalWrite(5,HIGH);
Gire a += 1;
}
}
void playRandom() {}
funcionó de int = random(0,90);
Si (funcionó < = 10 & & box1 == abra & y vuelta %2 == 1) {}
BOX1 = CLOSED_C;
Gire a += 1;
digitalWrite(9,HIGH);
}
Si (funcionó < = 20 & & ran > 10 & & box2 == abierto & & turn %2 == 1) {}
box2 = CLOSED_C;
Gire a += 1;
digitalWrite(8,HIGH);
}
Si (funcionó < = 30 & & ran > 20 & & Caja3 == abierto & & turn %2 == 1) {}
Caja3 = CLOSED_C;
Gire a += 1;
digitalWrite(7,HIGH);
}
Si (funcionó < = 40 & & ran > 30 & & box4 == abierto & & turn %2 == 1) {}
Box4 = CLOSED_C;
Gire a += 1;
digitalWrite(6,HIGH);
}
Si (funcionó < = 50 & & ran > 40 & & box5 == abierto & & turn %2 == 1) {}
Box5 = CLOSED_C;
Gire a += 1;
digitalWrite(5,HIGH);
}
Si (funcionó < = 60 & & ran > 50 & & box6 == abierto & & turn %2 == 1) {}
box6 = CLOSED_C;
Gire a += 1;
digitalWrite(4,HIGH);
}
Si (funcionó < = 70 & & ran > 60 & & box7 == abierto & & turn %2 == 1) {}
box7 = CLOSED_C;
Gire a += 1;
digitalWrite(3,HIGH);
}
Si (funcionó < = 80 & & ran > 70 & & box8 == abierto & & turn %2 == 1) {}
box8 = CLOSED_C;
Gire a += 1;
digitalWrite(2,HIGH);
}
Si (funcionó < = 90 & & ran > 80 & & box9 == abierto & & turn %2 == 1) {}
box9 = CLOSED_C;
Gire a += 1;
digitalWrite(10,HIGH);
}
}
void loop() {}
Si (girar a %2 == 0) {}
if(digitalRead(19) == alto & & box4 == abierto) {}
Box4 = CLOSED_P;
Gire a += 1;
}
Si (digitalRead (11) == alto & & Caja3 == abierto) {}
Caja3 = CLOSED_P;
Gire a += 1;
}
Si (digitalRead (12) == alto & & box2 == abierto) {}
box2 = CLOSED_P;
Gire a += 1;
}
if(digitalRead(13) == alto & & box1 == abierto) {}
BOX1 = CLOSED_P;
Gire a += 1;
}
if(digitalRead(14) == alto & & box5 == abierto) {}
Box5 = CLOSED_P;
Gire a += 1;
}
if(digitalRead(15) == alto & & box6 == abierto) {}
box6 = CLOSED_P;
Gire a += 1;
}
if(digitalRead(16) == alto & & box7 == abierto) {}
box7 = CLOSED_P;
Gire a += 1;
}
if(digitalRead(17) == alto & & box8 == abierto) {}
box8 = CLOSED_P;
Gire a += 1;
}
if(digitalRead(18) == alto & & box9 == abierto) {}
box9 = CLOSED_P;
Gire a += 1;
}
}
Si (girar a %2 == 1) {}
checkComputerWin();
checkPlayerWin();
playRandom();
}
checkGame();
Si (juego == 0 || juego == 2) {}
Delay(2000);
int t;
para (t = 0; t < 9; t += 1) {}
digitalWrite(computerArray[t],HIGH);
}
}
}