I Need help to make a Tic TacToe project

Hello I’m using the serial moniteur to make a tic tac toe project It is for two people to use. this is my code I don’t know how to make it work.

String motRecu;

const int NB_MAX = 20;
int uneListe[NB_MAX];
int longListe = 0;
int TTT = 0;

int randNombre = 0;

void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println(" “);
Serial.println(” “);
Serial.println(” ");

}

//Ceci génaire des numéro aux hazard
void creerListe(int lmax) {
for (int i = 0; i < lmax; i++) {
randNombre = random(0, 81);
uneListe = randNombre;

  • }*
    }
    //Ceci afiche la liste dans le Moniteur
    void afficherListe(int lmax) {
  • for (int i = 0; i < lmax; i++) {*
    _ Serial.print(uneListe*);_
    _
    Serial.print(" ");_
    _
    }_
    _
    Serial.println();_
    _
    } _
    void loop()
    _
    {_
    _
    while(Serial.available()) {_
    _
    motRecu = Serial.readString();*_

* if (motRecu.equals(“1O)”)){*
* Serial.println("---------");*
* Serial.println("[O] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* }*

* }*

* motRecu = Serial.readString();*

* if (motRecu.equals(“2O”)){*
* Serial.println("---------");*
* Serial.println("[] [O] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*

* }*
* motRecu = Serial.readString();*

* if (motRecu.equals(“3O”)){*
* Serial.println("---------");*
* Serial.println("[] [] [O]");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*

* }*
* motRecu = Serial.readString();*

* if (motRecu.equals(“4O”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[O] [] []");*
* Serial.println("[] [] []");*

* }*
* motRecu = Serial.readString();*

* if (motRecu.equals(“5O”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [O] []");*
* Serial.println("[] [] []");*

* }*
* motRecu = Serial.readString();*

* if (motRecu.equals(“6O”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] [O]");*
* Serial.println("[] [] []");*

* }*
* motRecu = Serial.readString();*

* if (motRecu.equals(“7O”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[O] [] []");*

* }*
* motRecu = Serial.readString();*

* if (motRecu.equals(“8O”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [O] []");*

* } else if (motRecu.equals(“9O”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [] [O]");*

* }*
* else if (motRecu.equals(“1X”)){*
* Serial.println("---------");*
* Serial.println("[X] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*

* } else if (motRecu.equals(“2X”)){*
* Serial.println("---------");*
* Serial.println("[] [X] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*

* } else if (motRecu.equals(“3X”)){*
* Serial.println("---------");*
* Serial.println("[] [] [X]");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*

* } else if (motRecu.equals(“4X”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[X] [] []");*
* Serial.println("[] [] []");*

* }else if (motRecu.equals(“5X”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [X] []");*
* Serial.println("[] [] []");*

* } else if (motRecu.equals(“6X”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] [X]");*
* Serial.println("[] [] []");*

* } else if (motRecu.equals(“7X”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[X] [] []");*

* }else if (motRecu.equals(“8X”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [X] []");*

* }else if (motRecu.equals(“9X”)){*
* Serial.println("---------");*
* Serial.println("[] [] []");*
* Serial.println("[] [] []");*
* Serial.println("[] [] [X]");*
* motRecu = Serial.readString();*

* }*
* motRecu = Serial.readString();*
* if(longListe > NB_MAX){
_
Serial.println(“Deja jouer”);*_

* }*
}

The code you improperly posted does something. You failed to tell us what it actually does.
You expect the code you improperly posted to do something. You failed to tell us what you expect it to do.

Read the stickies at the top of the forum, post your code correctly, explain what it actually does, and explain what you expect it to do. Then, maybe we can help you.

ok How do not know how to explain it really but It is tic tac toe using serial moniteur. You have to write in the serial moniteur 1O and then it will diplay this
[O]

But it doesn'T display it.

    motRecu = Serial.readString();

readString() is the worst possible method to use. readStringUntil(), and setting the Serial Monitor line ending value to whatever you want to read until is marginally better.

What DO you have the line ending value set to? The String that you get may actually have a carriage return, a line feed, or both in it. You are not using trim() to get rid of them, so you need to include them in the string you are trying to match.

HOMEWORK.
Read up on not using Strings.
Read up on functions.
Read up on arrays.

Read up on HOW to post code.

You might want to look at this library [GitHub - MajicDesigns/MD_TicTacToe: TicTacToe Decision Engine Library] and the example code. There is a TTT game using serial monitor in the example (one player is the computer, however).

first of all, check to make sure the baud rate at the bottom of your serial monitor window matches the number you have inside the brackets of Serial.begin(9600);

your life will be so much simpler if you use a 2d array or array of arrays to store your values. then you can use x and y coordinates to assign values.

String boxes[3][3];

void setup() {
Serial.begin(9600);

erase();//< set all the squares to blank

boxes[0][0]="X";boxes[2][2]="X";boxes[1][2]="O";//<assign squares like this
show();//prints board

}

void loop() {

}
void erase(){
    byte x = 0;while(x<3){
     byte y = 0; while(y<3){
    boxes[x][y]=" ";
    y++;}x++; }
  }
void show(){ 
 byte x = 0;  while(x<3){ byte y = 0; while(y<3){
    Serial.print("["+boxes[x][y]+"]  ");
    y++;} Serial.println("");  x++;}
    Serial.println("_____________________________");
  }

it’s very good habit to learn arrays for stuff like this. then you can scan things with loops. in 2d its actually a loop inside a loop. but you should definatly learn. it make many things practical that would otherwise be not. then you can move on to do much more amazing things…like connect 4. LOL

String boxes[7][6];

void setup() {

Serial.begin(9600);

erase();//< set all the squares to blank

//assign drops
drop(0,"X");drop(0,"X");drop(3,"X");drop(3,"O");drop(3,"O");drop(6,"X");
show();//prints board

}

void loop() {

}

void drop (byte x,String s){
  byte y = 0;
  while(boxes[x][y]!=" "){y++;}
  boxes[x][y]=s;
  
  }
void erase(){
    byte x = 0;while(x<7){
     byte y = 0; while(y<6){
    boxes[x][y]=" ";
    y++;}x++; }
  }
void show(){ 
 byte y = 6;  while(y>0){y--; byte x = 0; while(x<7){
  
    Serial.print("["+boxes[x][y]+"]  ");
    x++;} Serial.println(""); }
    Serial.println("_____________________________");
  }