# 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 < 8){
if(board[position.y][position.x + 1].canEnpas === true && 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" && board[position.y - 1][position.x] == "vacant"){
moves.push({x: position.x, y: position.y - 2});
}
} else if(position.y - 1 >= 0){
if(board[position.y - 1][position.x] == "vacant"){
moves.push({x: position.x, y: position.y - 1});
}
}
if(position.x + 1 < 8 && position.y - 1 >= 0){
if(getPieceType({x: position.x + 1, y: position.y - 1}, this.board) != pieceType && board[position.y - 1][position.x + 1] != "vacant"){
moves.push({x: position.x + 1, y: position.y - 1});
}
}
if(position.x - 1 >= 0 && position.y - 1 >= 0){
if(getPieceType({x: position.x - 1, y: position.y - 1}, this.board) != pieceType && board[position.y - 1][position.x - 1] != "vacant"){
moves.push({x: position.x - 1, y: position.y - 1});
}
}
} else {
if(position.x + 1 < 8){
if(board[position.y][position.x + 1].canEnpas === true && 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" && board[position.y + 1][position.x] == "vacant"){
moves.push({x: position.x, y: position.y + 2});
}
} else if(position.y + 1 < 8){
if(board[position.y + 1][position.x] == "vacant"){
moves.push({x: position.x, y: position.y + 1});
}
}
if(position.x + 1 < 8 && position.y + 1 < 8){
if(getPieceType({x: position.x + 1, y: position.y + 1}, this.board) != pieceType && board[position.y + 1][position.x + 1] != "vacant"){
moves.push({x: position.x + 1, y: position.y + 1});
}
}
if(position.x - 1 >= 0 && position.y + 1 < 8){
if(getPieceType({x: position.x - 1, y: position.y + 1}, this.board) != pieceType && board[position.y + 1][position.x - 1] != "vacant"){
moves.push({x: position.x - 1, y: position.y + 1});
}
}
}


let blocked = (board[position.y - 1][position.x] !== "vacant")

You can also define some short functions. E.g. isEnemy(x,y) would return true if there is an enemy piece at that position.