Cleaning up complex if statements for Chess game Shown below is a function I wrote for pawn move generation, I find it difficult to understand what the code does in a glance due to the cumbersome if statements, so any changes I make are done unnecessarily slowly. Is there a way to avoid these complex if statements so that the code is more maintainable?

  if(standardPawn.indexOf(this.board[position.y][position.x]) != -1){
          if(position.x + 1 &lt; 8){
            if(board[position.y][position.x + 1].canEnpas === true &amp;&amp; standardPawn.indexOf(board[position.y][position.x + 1]) == -1){
              moves.push({x: position.x + 1, y: position.y - 1});
            }
          }
          if(position.y == 6){
            if(board[position.y - 1][position.x] == "vacant"){
              moves.push({x: position.x, y: position.y - 1});
            }
            if(board[position.y - 2][position.x] == "vacant" &amp;&amp; board[position.y - 1][position.x] == "vacant"){
              moves.push({x: position.x, y: position.y - 2});
            }
          } else if(position.y - 1 &gt;= 0){
            if(board[position.y - 1][position.x] == "vacant"){
              moves.push({x: position.x, y: position.y - 1});
            }
          }
          if(position.x + 1 &lt; 8 &amp;&amp; position.y - 1 &gt;= 0){
            if(getPieceType({x: position.x + 1, y: position.y - 1}, this.board) != pieceType &amp;&amp; board[position.y - 1][position.x + 1] != "vacant"){
              moves.push({x: position.x + 1, y: position.y - 1});
            }
          }
          if(position.x - 1 &gt;= 0 &amp;&amp; position.y - 1 &gt;= 0){
            if(getPieceType({x: position.x - 1, y: position.y - 1}, this.board) != pieceType &amp;&amp; board[position.y - 1][position.x - 1] != "vacant"){
              moves.push({x: position.x - 1, y: position.y - 1});
            }
          }
        } else {
          if(position.x + 1 &lt; 8){
            if(board[position.y][position.x + 1].canEnpas === true &amp;&amp; standardPawn.indexOf(board[position.y][position.x + 1]) != -1){
              moves.push({x: position.x + 1, y: position.y + 1});
            }
          }
          if(position.y == 1){
            if(board[position.y + 1][position.x] == "vacant"){
              moves.push({x: position.x, y: position.y + 1});
            }
            if(board[position.y + 2][position.x] == "vacant" &amp;&amp; board[position.y + 1][position.x] == "vacant"){
              moves.push({x: position.x, y: position.y + 2});
            }
          } else if(position.y + 1 &lt; 8){
            if(board[position.y + 1][position.x] == "vacant"){
              moves.push({x: position.x, y: position.y + 1});
            }
          }
          if(position.x + 1 &lt; 8 &amp;&amp; position.y + 1 &lt; 8){
            if(getPieceType({x: position.x + 1, y: position.y + 1}, this.board) != pieceType &amp;&amp; board[position.y + 1][position.x + 1] != "vacant"){
              moves.push({x: position.x + 1, y: position.y + 1});
            }
          }
          if(position.x - 1 &gt;= 0 &amp;&amp; position.y + 1 &lt; 8){
            if(getPieceType({x: position.x - 1, y: position.y + 1}, this.board) != pieceType &amp;&amp; board[position.y + 1][position.x - 1] != "vacant"){
              moves.push({x: position.x - 1, y: position.y + 1});
            }
          }
        }
You can enhance the readability by extracting the conditons of your ifs to functions without chanceing the performance. Plus you can remove your duplicate code like positon.x +1 &lt; 8