My code prints on the serial monitor unexpectedly.

I tried changing the baud rate and all but no success.
I am building a checkers game.I have implemented the library and tested it without using arduino and it works fine.
So I don’t think there is any problem with the library.
Basically I want to get input from the serial monitor and draw the board with text and similarly after the computer plays i want to display the output.
The significant code is somewhat like

void loop() {
  
  Serial.print("x");
  while(!Serial){
  }
  drawb();
  player();
  if(whitewin==1)
  {
    while(true)
    {
    }
  }
  if(draw==1)
  {
    while(true)
    {
    }
  }
 computer();
 if(blackwin==1)
  {
    while(true)
    {
    }
  } 
  if(draw==1)
  {
    while(true)
    {
    }
  }
}
void drawb()
{
  for(int j=0;j<10;j++)
  {
    for(int i=0;i<10;i++)
    {
      if(b->myallpieces[i][j]==NULL)
      {
        Serial.print(". ");

      }
      if(b->myallpieces[i][j]!=NULL)
      {
        if(b->myallpieces[i][j]->pieceval==0)
        {
          Serial.print("W ");
        }
        if(b->myallpieces[i][j]->pieceval==1)
        {
          Serial.print("B ");
        }
        if(b->myallpieces[i][j]->pieceval==2)
        {
          Serial.print("w ");
        }
        if(b->myallpieces[i][j]->pieceval==3)
        {
          Serial.print("b ");
        }
      }
    }
    Serial.println("");
  }
  return;
}

void player()
{
  if(Serial.available()>0)
  {
    int x;
    inx=(int) Serial.read();
    iny=(int) Serial.read();
    fix=(int) Serial.read();
    fiy=(int) Serial.read();
    x=b->playedbytheplayer(inx,iny,fix,fiy);
    Serial.println(x);
    drawb();
    if(x==0)
    {
      player();
    }
    if(x==1)
    {
      return;
    }
    if(x==2)
    {
      player();//move played was wrong
    }
    if(x==3)
    {
      Serial.println("COmputer LOST");
      whitewin=1;
      return;
    }
    if(x==4)
    {
      Serial.println("Draw");
      draw=1;
      return;
    }
  }
  player();
}

void computer()
{
  int x;
  x=b->getnextmove(inx,iny,fix,fiy);
  Serial.println(x);
  drawb();
  if(x==0)
  {
    computer();
  }
  if(x==1)
  {
    return;
  }
  if(x==3)
  {
    Serial.println("Player LOST");
    blackwin=1;
    return;
  }
  if(x==4)
  {
    Serial.println("Draw");
    draw=1;
    return;
  }
}

I have initialized all the variable in setup.My output is somewhat like this.

b W W W W W W W . . . . . . . . . . . . . . . . . . . . W B W W W W W W W W . W . . . . . . . . . . . . . . . . . . . . . . . . . . . . W W W W . W W W W W W . . . . . . . . . . . . . . . . . . . . W W W W W W . W W . b . . W W W W W W . . .

And it goes on and on…
Its the same always.

if(Serial.available()>0)
  {
    int x;
    inx=(int) Serial.read();
    iny=(int) Serial.read();
    fix=(int) Serial.read();
    fiy=(int) Serial.read();

Do you see a problem here?

Please post your code.

I tried changing the baud rate and all but no success.

Nor I did. Pls, post if you solve it.

(Who plays, the arduino?)

And what on earth is this:

  while(!Serial){