2 large if statements firing at the same time

Hey Guys, I am new to arduino and I have a problem. I am trying to programm a Tic Tac Toe game in the serial Monitor. 2 Players for now so no fancy algorythm stuff going on. My Problem is that when I try to set the position for the X player, the Board prints the grid twice, once properly and the second time the same grid with the Message “Already taken” which is only supposed to print when you try to place something on an already fille square. I have tried about every debugging method I can think of and nothing so far, so maybe you guys can find something

Sorry if I used the wrong tags or cateogries

Thanks

int i;
int j;
int k;
int l;
int x;
int p;
char f1;
char f2;
char f3;
char f4;
char f5;
char f6;
char f7;
char f8;
char f9;
int b1;
int b2;
int b3;
int b4;
int b5;
int b6;
int b7;
int b8;
int b9;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
pinMode(11,INPUT_PULLUP);

Serial.println("Begin");
delay(100);

f1 = '1';
f2 = '2';
f3 = '3';
f4 = '4';
f5 = '5';
f6 = '6';
f7 = '7';
f8 = '8';
f9 = '9';


Serial.print("|");
Serial.print(f1);
Serial.print("|");
Serial.print(f2);
Serial.print("|");
Serial.print(f3);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f4);
Serial.print("|");
Serial.print(f5);
Serial.print("|");
Serial.print(f6);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f7);
Serial.print("|");
Serial.print(f8);
Serial.print("|");
Serial.print(f9);
Serial.println("|");

delay(5);

f1 = ' ';
f2 = ' ';
f3 = ' ';
f4 = ' ';
f5 = ' ';
f6 = ' ';
f7 = ' ';
f8 = ' ';
f9 = ' ';
b1 = 0;
b2 = 0;
b3 = 0;
b4 = 0;
b5 = 0;
b6 = 0;
b7 = 0;
b8 = 0;
b9 = 0;
x  = 1;
p  = 1;
if(x==100){
Serial.println(b1);
Serial.println(b2);
Serial.println(b3);
Serial.println(b4);
Serial.println(b5);
Serial.println(b6);
Serial.println(b7);
Serial.println(b8);
Serial.println(b9);
}
}
void(* resetFunc) (void) = 0;//declare reset function at address 0
void loop() {
  // put your main code here, to run repeatedly:


i =digitalRead(13);
j =digitalRead(12);
k =digitalRead(11);
l =digitalRead(11);


if(i<=0){
x= x + 1;
 if(x<=0){
  x = 9;
 }
 if(x>=10){
  x = 1;
 }


Serial.println(x);
delay(300);
}

if(j<=0){
x= x - 1;
 if(x<=0){
  x = 9;
 }
 if(x>=10){
  x = 1;
 }

Serial.println(x);
delay(300);
}

if(p==1){

if(k<=0){

if(x==1){
  if(b1==0){
    f1 = 'x';
    b1 = 1;
    p = 2;
  }else{Serial.println("Already taken1");}
}else{

if(x==2){
  if(b2==0){
    f2 = 'x';
    b2 = 1;
    p = 2;
 
}else{Serial.println("Already taken2");}
}else{

if(x==3){
  if(b3==0){
    f3 = 'x';
    b3 = 1;
    p = 2;
  }else{Serial.println("Already taken3");}
}else{

if(x==4){
  if(b4==0){
    f4 = 'x';
    b4 = 1;
    p = 2;
  }else{Serial.println("Already taken4");}
}else{

if(x==5){
  if(b5==0){
    f5 = 'x';
    b5 = 1;
    p = 2;
  }else{Serial.println("Already taken5");}
}else{

if(x==6){
  if(b6==0){
    f6 = 'x';
    b6 = 1;
    p = 2;
  }else{Serial.println("Already taken6");}
}else{


if(x==7){
  if(b7==0){
    f7 = 'x';
    b7 = 1;
    p = 2;
  }else{Serial.println("Already taken7");}
}else{


if(x==8){
  if(b8==0){
    f8 = 'x';
    b8 = 1;
    p = 2;
  }else{Serial.println("Already taken8");}
}else{

if(x==9){
 if(b9==0){
    f9 = 'x';
    b9 = 1;
    p = 2;
  }else{Serial.println("Already taken9");}
} else{Serial.println("err");}
}
}
}
}
}
}
}
}



  delay(10);

  
Serial.print("|");
Serial.print(f1);
Serial.print("|");
Serial.print(f2);
Serial.print("|");
Serial.print(f3);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f4);
Serial.print("|");
Serial.print(f5);
Serial.print("|");
Serial.print(f6);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f7);
Serial.print("|");
Serial.print(f8);
Serial.print("|");
Serial.print(f9);
Serial.println("|");

delay(300);



}
}


if(p==2){
  
if(k<=0){

if(x==1){
  if(b1==0){
    f1 = 'O';
    b1 = 1;
    p = 1;
  }else{Serial.println("Already taken1");}
}else{

if(x==2){
  if(b2==0){
    f2 = 'O';
    b2 = 1;
    p = 1;
 
}else{Serial.println("Already taken2");}
}else{

if(x==3){
  if(b3==0){
    f3 = 'O';
    b3 = 1;
    p = 1;
  }else{Serial.println("Already taken3");}
}else{

if(x==4){
  if(b4==0){
    f4 = 'O';
    b4 = 1;
    p = 1;
  }else{Serial.println("Already taken4");}
}else{

if(x==5){
  if(b5==0){
    f5 = 'O';
    b5 = 1;
    p = 1;
  }else{Serial.println("Already taken5");}
}else{

if(x==6){
  if(b6==0){
    f6 = 'O';
    b6 = 1;
    p = 1;
  }else{Serial.println("Already taken6");}
}else{


if(x==7){
  if(b7==0){
    f7 = 'O';
    b7 = 1;
    p = 1;
  }else{Serial.println("Already taken7");}
}else{


if(x==8){
  if(b8==0){
    f8 = 'O';
    b8 = 1;
    p = 1;
  }else{Serial.println("Already taken8");}
}else{

if(x==9){
 if(b9==0){
    f9 = 'O';
    b9 = 1;
    p = 1;
  }else{Serial.println("Already taken9");}
} else{Serial.println("err");}
}
}
}
}
}
}
}
}



  delay(10);

  
Serial.print("|");
Serial.print(f1);
Serial.print("|");
Serial.print(f2);
Serial.print("|");
Serial.print(f3);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f4);
Serial.print("|");
Serial.print(f5);
Serial.print("|");
Serial.print(f6);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f7);
Serial.print("|");
Serial.print(f8);
Serial.print("|");
Serial.print(f9);
Serial.println("|");

delay(270);



Serial.println(p);
}
}






if(f1=='x' || f1=='O'){
if(f1==f2 && f1==f3){
  
Serial.print(f1);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call reset 
}
}
if(f1=='x' || f1=='O'){
if(f1==f5 && f1==f9){

Serial.print(f1);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f1=='x' || f1=='O'){
if(f1==f4 && f1==f7){
  
Serial.print(f1);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f5=='x' || f5=='O'){
if(f5==f2 && f5==f8){
 
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f5=='x' || f5=='O'){
if(f5==f4 && f5==f6){
  
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f5=='x' || f5=='O'){
if(f5==f1 && f5==f9){
  
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f5=='x' || f5=='O'){
if(f5==f3 && f5==f7){
  
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f3=='x' || f3=='O'){
if(f3==f6 && f3==f9){
  
Serial.print(f3);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f7=='x' || f7=='O'){
if(f7==f8 && f7==f9){
  
Serial.print(f7);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f3=='x' || f3=='O'){
if(f3==f6 && f3==f9){
  
Serial.print(f3);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}
if(f1=='x' || f1=='O'){
if(b1==b2 && b1==b3 && b1== b4 && b1== b5 && b1== b6 && b1== b7 && b1== b8 && b1== b9){
  Serial.println("draw");
  delay(500);
  Serial.println("resetting");
  delay(100);

  resetFunc(); //call rese

}
} 

}
int i;
int j;
int k;
int l;
int x;
int p;
char f1;
char f2;
char f3;
char f4;
char f5;
char f6;
char f7;
char f8;
char f9;
int b1;
int b2;
int b3;
int b4;
int b5;
int b6;
int b7;
int b8;
int b9;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
pinMode(11,INPUT_PULLUP);

Serial.println("Begin");
delay(100);

f1 = '1';
f2 = '2';
f3 = '3';
f4 = '4';
f5 = '5';
f6 = '6';
f7 = '7';
f8 = '8';
f9 = '9';


Serial.print("|");
Serial.print(f1);
Serial.print("|");
Serial.print(f2);
Serial.print("|");
Serial.print(f3);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f4);
Serial.print("|");
Serial.print(f5);
Serial.print("|");
Serial.print(f6);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f7);
Serial.print("|");
Serial.print(f8);
Serial.print("|");
Serial.print(f9);
Serial.println("|");

delay(5);

f1 = ' ';
f2 = ' ';
f3 = ' ';
f4 = ' ';
f5 = ' ';
f6 = ' ';
f7 = ' ';
f8 = ' ';
f9 = ' ';
b1 = 0;
b2 = 0;
b3 = 0;
b4 = 0;
b5 = 0;
b6 = 0;
b7 = 0;
b8 = 0;
b9 = 0;
x  = 1;
p  = 1;
if(x==100){
Serial.println(b1);
Serial.println(b2);
Serial.println(b3);
Serial.println(b4);
Serial.println(b5);
Serial.println(b6);
Serial.println(b7);
Serial.println(b8);
Serial.println(b9);
}
}
void(* resetFunc) (void) = 0;//declare reset function at address 0
void loop() {
  // put your main code here, to run repeatedly:


i =digitalRead(13);
j =digitalRead(12);
k =digitalRead(11);
l =digitalRead(11);


if(i<=0){
x= x + 1;
 if(x<=0){
  x = 9;
 }
 if(x>=10){
  x = 1;
 }


Serial.println(x);
delay(300);
}

if(j<=0){
x= x - 1;
 if(x<=0){
  x = 9;
 }
 if(x>=10){
  x = 1;
 }

Serial.println(x);
delay(300);
}

if(p==1){

if(k<=0){

if(x==1){
  if(b1==0){
    f1 = 'x';
    b1 = 1;
    p = 2;
  }else{Serial.println("Already taken1");}
}else{

if(x==2){
  if(b2==0){
    f2 = 'x';
    b2 = 1;
    p = 2;
 
}else{Serial.println("Already taken2");}
}else{

if(x==3){
  if(b3==0){
    f3 = 'x';
    b3 = 1;
    p = 2;
  }else{Serial.println("Already taken3");}
}else{

if(x==4){
  if(b4==0){
    f4 = 'x';
    b4 = 1;
    p = 2;
  }else{Serial.println("Already taken4");}
}else{

if(x==5){
  if(b5==0){
    f5 = 'x';
    b5 = 1;
    p = 2;
  }else{Serial.println("Already taken5");}
}else{

if(x==6){
  if(b6==0){
    f6 = 'x';
    b6 = 1;
    p = 2;
  }else{Serial.println("Already taken6");}
}else{


if(x==7){
  if(b7==0){
    f7 = 'x';
    b7 = 1;
    p = 2;
  }else{Serial.println("Already taken7");}
}else{


if(x==8){
  if(b8==0){
    f8 = 'x';
    b8 = 1;
    p = 2;
  }else{Serial.println("Already taken8");}
}else{

if(x==9){
 if(b9==0){
    f9 = 'x';
    b9 = 1;
    p = 2;
  }else{Serial.println("Already taken9");}
} else{Serial.println("err");}
}
}
}
}
}
}
}
}



  delay(10);

  
Serial.print("|");
Serial.print(f1);
Serial.print("|");
Serial.print(f2);
Serial.print("|");
Serial.print(f3);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f4);
Serial.print("|");
Serial.print(f5);
Serial.print("|");
Serial.print(f6);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f7);
Serial.print("|");
Serial.print(f8);
Serial.print("|");
Serial.print(f9);
Serial.println("|");

delay(300);



}
}


if(p==2){
  
if(k<=0){

if(x==1){
  if(b1==0){
    f1 = 'O';
    b1 = 1;
   
  }else{Serial.println("Already taken1");}
}else{

if(x==2){
  if(b2==0){
    f2 = 'O';
    b2 = 1;
   
 
}else{Serial.println("Already taken2");}
}else{

if(x==3){
  if(b3==0){
    f3 = 'O';
    b3 = 1;
    p = 1;
  }else{Serial.println("Already taken3");}
}else{

if(x==4){
  if(b4==0){
    f4 = 'O';
    b4 = 1;
    p = 1;
  }else{Serial.println("Already taken4");}
}else{

if(x==5){
  if(b5==0){
    f5 = 'O';
    b5 = 1;
    p = 1;
  }else{Serial.println("Already taken5");}
}else{

if(x==6){
  if(b6==0){
    f6 = 'O';
    b6 = 1;
    p = 1;
  }else{Serial.println("Already taken6");}
}else{


if(x==7){
  if(b7==0){
    f7 = 'O';
    b7 = 1;
    p = 1;
  }else{Serial.println("Already taken7");}
}else{


if(x==8){
  if(b8==0){
    f8 = 'O';
    b8 = 1;
    p = 1;
  }else{Serial.println("Already taken8");}
}else{

if(x==9){
 if(b9==0){
    f9 = 'O';
    b9 = 1;
    p = 1;
  }else{Serial.println("Already taken9");}
} else{Serial.println("err");}
}
}
}
}
}
}
}
}



  delay(10);

  
Serial.print("|");
Serial.print(f1);
Serial.print("|");
Serial.print(f2);
Serial.print("|");
Serial.print(f3);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f4);
Serial.print("|");
Serial.print(f5);
Serial.print("|");
Serial.print(f6);
Serial.println("|");
Serial.println("|-|-|-|");
Serial.print("|");
Serial.print(f7);
Serial.print("|");
Serial.print(f8);
Serial.print("|");
Serial.print(f9);
Serial.println("|");

delay(270);



Serial.println(p);
}
}






if(f1=='x' || f1=='O'){
if(f1==f2 && f1==f3){
  
Serial.print(f1);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call reset 
}
}
if(f1=='x' || f1=='O'){
if(f1==f5 && f1==f9){

Serial.print(f1);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f1=='x' || f1=='O'){
if(f1==f4 && f1==f7){
  
Serial.print(f1);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f5=='x' || f5=='O'){
if(f5==f2 && f5==f8){
 
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f5=='x' || f5=='O'){
if(f5==f4 && f5==f6){
  
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f5=='x' || f5=='O'){
if(f5==f1 && f5==f9){
  
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f5=='x' || f5=='O'){
if(f5==f3 && f5==f7){
  
Serial.print(f5);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}


if(f3=='x' || f3=='O'){
if(f3==f6 && f3==f9){
  
Serial.print(f3);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f7=='x' || f7=='O'){
if(f7==f8 && f7==f9){
  
Serial.print(f7);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}

if(f3=='x' || f3=='O'){
if(f3==f6 && f3==f9){
  
Serial.print(f3);
Serial.println("wins");
delay(500);
Serial.println("resetting");
delay(100);

resetFunc(); //call rese
}
}
if(f1=='x' || f1=='O'){
if(b1==b2 && b1==b3 && b1== b4 && b1== b5 && b1== b6 && b1== b7 && b1== b8 && b1== b9){
  Serial.println("draw");
  delay(500);
  Serial.println("resetting");
  delay(100);

  resetFunc(); //call rese

}
} 


Please post code like above, using code tags. Most forum members use phones & tablets much of the time and can’t open a .ino file.

Can you please click Tools–>Auto format, then post the code again. It could be you have a } in the wrong place somewhere, but is very hard to spot that if the indentation is not right.

Thanks, didn’t know where to find the option

I have checked for every sort of bracket placement already multiple times and didn’t find anything. I’m gonna go hav a look again but I am not sure much will come of it.
Thanks anyways ^^

is this formatting (indentation) correct ??

int i;
int j;
int k;
int l;
int x;
int p;
char f1;
char f2;
char f3;
char f4;
char f5;
char f6;
char f7;
char f8;
char f9;
int b1;
int b2;
int b3;
int b4;
int b5;
int b6;
int b7;
int b8;
int b9;
void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(13,INPUT_PULLUP);
    pinMode(12,INPUT_PULLUP);
    pinMode(11,INPUT_PULLUP);
    Serial.println("Begin");
    delay(100);
    f1 = '1';
    f2 = '2';
    f3 = '3';
    f4 = '4';
    f5 = '5';
    f6 = '6';
    f7 = '7';
    f8 = '8';
    f9 = '9';
    Serial.print("|");
    Serial.print(f1);
    Serial.print("|");
    Serial.print(f2);
    Serial.print("|");
    Serial.print(f3);
    Serial.println("|");
    Serial.println("|-|-|-|");
    Serial.print("|");
    Serial.print(f4);
    Serial.print("|");
    Serial.print(f5);
    Serial.print("|");
    Serial.print(f6);
    Serial.println("|");
    Serial.println("|-|-|-|");
    Serial.print("|");
    Serial.print(f7);
    Serial.print("|");
    Serial.print(f8);
    Serial.print("|");
    Serial.print(f9);
    Serial.println("|");
    delay(5);
    f1 = ' ';
    f2 = ' ';
    f3 = ' ';
    f4 = ' ';
    f5 = ' ';
    f6 = ' ';
    f7 = ' ';
    f8 = ' ';
    f9 = ' ';
    b1 = 0;
    b2 = 0;
    b3 = 0;
    b4 = 0;
    b5 = 0;
    b6 = 0;
    b7 = 0;
    b8 = 0;
    b9 = 0;
    x  = 1;
    p  = 1;
    if(x==100){
        Serial.println(b1);
        Serial.println(b2);
        Serial.println(b3);
        Serial.println(b4);
        Serial.println(b5);
        Serial.println(b6);
        Serial.println(b7);
        Serial.println(b8);
        Serial.println(b9);
    }
}
void(* resetFunc) (void) = 0;//declare reset function at address 0
void loop() {
    // put your main code here, to run repeatedly:
    i =digitalRead(13);
    j =digitalRead(12);
    k =digitalRead(11);
    l =digitalRead(11);
    if(i<=0){
        x= x + 1;
        if(x<=0){
            x = 9;
        }
        if(x>=10){
            x = 1;
        }
        Serial.println(x);
        delay(300);
    }
    if(j<=0){
        x= x - 1;
        if(x<=0){
            x = 9;
        }
        if(x>=10){
            x = 1;
        }
        Serial.println(x);
        delay(300);
    }
    if(p==1){
        if(k<=0){
            if(x==1){
                if(b1==0){
                    f1 = 'x';
                    b1 = 1;
                    p = 2;
                } else {Serial.println("Already taken1");
                }
            } else {
                if(x==2){
                    if(b2==0){
                        f2 = 'x';
                        b2 = 1;
                        p = 2;
                    } else {Serial.println("Already taken2");
                    }
                } else {
                    if(x==3){
                        if(b3==0){
                            f3 = 'x';
                            b3 = 1;
                            p = 2;
                        } else {Serial.println("Already taken3");
                        }
                    } else {
                        if(x==4){
                            if(b4==0){
                                f4 = 'x';
                                b4 = 1;
                                p = 2;
                            } else {Serial.println("Already taken4");
                            }
                        } else {
                            if(x==5){
                                if(b5==0){
                                    f5 = 'x';
                                    b5 = 1;
                                    p = 2;
                                } else {Serial.println("Already taken5");
                                }
                            } else {
                                if(x==6){
                                    if(b6==0){
                                        f6 = 'x';
                                        b6 = 1;
                                        p = 2;
                                    } else {Serial.println("Already taken6");
                                    }
                                } else {
                                    if(x==7){
                                        if(b7==0){
                                            f7 = 'x';
                                            b7 = 1;
                                            p = 2;
                                        } else {Serial.println("Already taken7");
                                        }
                                    } else {
                                        if(x==8){
                                            if(b8==0){
                                                f8 = 'x';
                                                b8 = 1;
                                                p = 2;
                                            } else {Serial.println("Already taken8");
                                            }
                                        } else {
                                            if(x==9){
                                                if(b9==0){
                                                    f9 = 'x';
                                                    b9 = 1;
                                                    p = 2;
                                                } else {Serial.println("Already taken9");
                                                }
                                            } else {Serial.println("err");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            delay(10);
            Serial.print("|");
            Serial.print(f1);
            Serial.print("|");
            Serial.print(f2);
            Serial.print("|");
            Serial.print(f3);
            Serial.println("|");
            Serial.println("|-|-|-|");
            Serial.print("|");
            Serial.print(f4);
            Serial.print("|");
            Serial.print(f5);
            Serial.print("|");
            Serial.print(f6);
            Serial.println("|");
            Serial.println("|-|-|-|");
            Serial.print("|");
            Serial.print(f7);
            Serial.print("|");
            Serial.print(f8);
            Serial.print("|");
            Serial.print(f9);
            Serial.println("|");
            delay(300);
        }
    }
    if(p==2){
        if(k<=0){
            if(x==1){
                if(b1==0){
                    f1 = 'O';
                    b1 = 1;
                } else {Serial.println("Already taken1");
                }
            } else {
                if(x==2){
                    if(b2==0){
                        f2 = 'O';
                        b2 = 1;
                    } else {Serial.println("Already taken2");
                    }
                } else {
                    if(x==3){
                        if(b3==0){
                            f3 = 'O';
                            b3 = 1;
                            p = 1;
                        } else {Serial.println("Already taken3");
                        }
                    } else {
                        if(x==4){
                            if(b4==0){
                                f4 = 'O';
                                b4 = 1;
                                p = 1;
                            } else {Serial.println("Already taken4");
                            }
                        } else {
                            if(x==5){
                                if(b5==0){
                                    f5 = 'O';
                                    b5 = 1;
                                    p = 1;
                                } else {Serial.println("Already taken5");
                                }
                            } else {
                                if(x==6){
                                    if(b6==0){
                                        f6 = 'O';
                                        b6 = 1;
                                        p = 1;
                                    } else {Serial.println("Already taken6");
                                    }
                                } else {
                                    if(x==7){
                                        if(b7==0){
                                            f7 = 'O';
                                            b7 = 1;
                                            p = 1;
                                        } else {Serial.println("Already taken7");
                                        }
                                    } else {
                                        if(x==8){
                                            if(b8==0){
                                                f8 = 'O';
                                                b8 = 1;
                                                p = 1;
                                            } else {Serial.println("Already taken8");
                                            }
                                        } else {
                                            if(x==9){
                                                if(b9==0){
                                                    f9 = 'O';
                                                    b9 = 1;
                                                    p = 1;
                                                } else {Serial.println("Already taken9");
                                                }
                                            } else {Serial.println("err");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            delay(10);
            Serial.print("|");
            Serial.print(f1);
            Serial.print("|");
            Serial.print(f2);
            Serial.print("|");
            Serial.print(f3);
            Serial.println("|");
            Serial.println("|-|-|-|");
            Serial.print("|");
            Serial.print(f4);
            Serial.print("|");
            Serial.print(f5);
            Serial.print("|");
            Serial.print(f6);
            Serial.println("|");
            Serial.println("|-|-|-|");
            Serial.print("|");
            Serial.print(f7);
            Serial.print("|");
            Serial.print(f8);
            Serial.print("|");
            Serial.print(f9);
            Serial.println("|");
            delay(270);
            Serial.println(p);
        }
    }
    if(f1=='x' || f1=='O'){
        if(f1==f2 && f1==f3){
            Serial.print(f1);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call reset
        }
    }
    if(f1=='x' || f1=='O'){
        if(f1==f5 && f1==f9){
            Serial.print(f1);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f1=='x' || f1=='O'){
        if(f1==f4 && f1==f7){
            Serial.print(f1);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f5=='x' || f5=='O'){
        if(f5==f2 && f5==f8){
            Serial.print(f5);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f5=='x' || f5=='O'){
        if(f5==f4 && f5==f6){
            Serial.print(f5);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f5=='x' || f5=='O'){
        if(f5==f1 && f5==f9){
            Serial.print(f5);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f5=='x' || f5=='O'){
        if(f5==f3 && f5==f7){
            Serial.print(f5);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f3=='x' || f3=='O'){
        if(f3==f6 && f3==f9){
            Serial.print(f3);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f7=='x' || f7=='O'){
        if(f7==f8 && f7==f9){
            Serial.print(f7);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f3=='x' || f3=='O'){
        if(f3==f6 && f3==f9){
            Serial.print(f3);
            Serial.println("wins");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }
    if(f1=='x' || f1=='O'){
        if(b1==b2 && b1==b3 && b1== b4 && b1== b5 && b1== b6 && b1== b7 && b1== b8 && b1== b9){
            Serial.println("draw");
            delay(500);
            Serial.println("resetting");
            delay(100);
            resetFunc(); //call rese
        }
    }

Yes, seems correct a “}” was missing at the end but other than that yea

those if statements are really nested that deep ??

have never seen code like that before

I’m not sure if that’s a compliment or not so Imma just gonna take it as one.

As I said, I am new and this seemed like the best way to reach my goal

Take a look at arrays. It’ll help a lot I suspect.

it is very difficult to understand code with that much nesting

all i know is that the code is some sort of game and it displays something twice … and that something “Already selected” doesn’t appear in the posted code

Yea, I know. Pretty much everyone I have shown this to said the same.

And the already selected part is my bad, It’s “Already taken(Number of the field)”

You’re right, that would help clear up my ints but I added them along the way as needed and didn’t think of it. Noted for the next time tho

so which one appeared in your output? obviously start looking there

Always the selected number. My suspicion is that the code is running twice but I have no idea why

I just tested somethig and it turns out that when I run the code for X, the code for O runs right after. Why this is, I have no idea though

What is this supposed to do?

I refuse to believe that we can’t find a way that’s easier to follow than the if statement soup.

Start Over - with a flow chart - and then, when you recompose your sketch, come up with something better than single-letter variable names (they can be hard to search out, for one thing, and don’t much aid understanding).

There is probably an easier way. There always is. I just couldn’t come up with anything better

Explain what the code is supposed to do, then we might be able to help.

I wasn’t planning on sharing this code, just started the project out of boredom, and I thought I know what what variable does but yea, that 's a habit I should probably lay off.

And I had a flow chart, without it I wouldn’t have been able to come up with any of this in the first place

It’s a game of tic tac toe. Two players can play it. The first two buttons on pins 13 and 12 select the Field you can place your character in. 1-9. If the number gets below 1 or over 9, it circles around so if x>9 x=1 and vice versa.
The whole if entanglement is the placement mechanism. It takes the x value, which defines what square you’re in and prints the game board after pressing the third button on pin 11 (j). It also checks if the field already has a character inside. If something is occupying the field or not is stored in variables b1-9. For the printing of the field, I use the character variables f1-9 and make them an X or an O. Those are the 2 big if loops. Which player is playing is defined by variable p. If p=1 player 1 (X) plays, if p=2 it’s player 2’s turn (O).

The many small if loops at the End of the sketch are there to check if any winning conditions are met or if the board is full and the game is a draw. If either one is the case, it will print the Winner or say “Draw” and restart the Game and the sketch.

The Problem is now that whenever I set an X and the if loop is triggered, although the condition p=2 isn’t met yet ( or shouldn’t be), Player 2 tries to place an O. Strangest thing about this is that the O if loop doesn’t work properly or else it would set the Variable back to 1 and you 'd place another X but after the gameboard shows twice, you can place an O as usual.