I made a Rock paper .... it works just fine but I want to see the computers choice.
I added an array but I dont know how to continue.
uint8_t computer[4] = { paper, rock, scissors, lizard, Spock};
char command[0x20];
void setup()
{
Serial.begin(115200);
pinMode(PIN_LED1, OUTPUT);
}
void loop()
{
if (receive_function(command, sizeof(command)))
{
uint8_t r = random(0, 5); // 0=rock, 1=paper 2=scissors 3=Lizard 4=Spock
uint8_t computer[4] = { paper, rock, scissors, lizard, Spock};
Serial.println("computer[4]"); //rock, paper, scissors. lizard,Spock
if (strcmp(command, "rock") == 0) //
{
if (r == 0) {
Serial.println("tie"); // if they match print out reply
}
else if (r == 1) {
Serial.println("you lose!"); // if they match print out reply
}
else if (r == 2) {
Serial.println("you win!"); // if they match print out reply
}
else if (r == 3) {
Serial.println("you win!"); // if they match print out reply
}
else if (r == 4) {
Serial.println("you lose!"); // if they match print out reply
}
}
if (strcmp(command, "paper") == 0) //
{
if (r == 0) {
Serial.println("you win!"); // if they match print out reply
}
else if (r == 1) {
Serial.println("tie"); // if they match print out reply
}
else if (r == 2) {
Serial.println("you lose"); // if they match print out reply
}
else if (r == 3) {
Serial.println("you lose!"); // if they match print out reply
}
else if (r == 4) {
Serial.println("you win!"); // if they match print out reply
}
}
if (strcmp(command, "scissors") == 0) //
{
if (r == 0) {
Serial.println("you lose"); // if they match print out reply
}
else if (r == 1) {
Serial.println("you win!"); // if they match print out reply
}
else if (r == 2) {
Serial.println("tie"); // if they match print out reply
}
else if (r == 3) {
Serial.println("you win!"); // if they match print out reply
}
else if (r == 4) {
Serial.println("you lose!"); // if they match print out reply
}
}
if (strcmp(command, "lizard") == 0) //
{
if (r == 0) {
Serial.println("you lose"); // if they match print out reply
}
else if (r == 1) {
Serial.println("you win!"); // if they match print out reply
}
else if (r == 2) {
Serial.println("you lose"); // if they match print out reply
}
else if (r == 3) {
Serial.println("tie!"); // if they match print out reply
}
else if (r == 4) {
Serial.println("you win!"); // if they match print out reply
}
}
if (strcmp(command, "Spock") == 0) //
{
if (r == 0) {
Serial.println("you win"); // if they match print out reply
}
else if (r == 1) {
Serial.println("you lose!"); // if they match print out reply
}
else if (r == 2) {
Serial.println("you win"); // if they match print out reply
}
else if (r == 3) {
Serial.println("you lose!"); // if they match print out reply
}
else if (r == 4) {
Serial.println("tie"); // if they match print out reply
}
}
else if (strcmp(command, "on") == 0) // compare to "on"
{
digitalWrite(PIN_LED1, HIGH); // if they match turn the led on
}
else if (strcmp(command, "off") == 0) // compare to "off"
{
digitalWrite(PIN_LED1, LOW); // if they match turn the led off
}
else // none of the ifs above were true
{
Serial.println("Rock, Paper, Scissors, Lizard, Spock");
}
}
}