// File: tlaloc1313[P]chess-project/draw.cpp
// Function: draw(Board*, bool)
int draw(Board* gameBoard, bool isWhiteTurn) {

  int currentSquare;

  //Clears the screen
  for (int n=0; n<100; n++) {
    cout<<std::endl;
  }

  //Game board is displayed from White's POV
  if (isWhiteTurn == 1) {

    //Iterating through rows
    for (int row=7; row>=0; row--) {

      //Row numbering is displayed alongside the board
      cout<<row+1<<SPACINGH;

      //Iterating through columns
      for (int column=0; column<8; column++) {
        currentSquare = (column*8) + row;

        //Where the square is occupied, print that piece
        if (gameBoard->spaceOccupied(currentSquare) == 1) {
          cout<<gameBoard->getPiece(currentSquare)<<SPACINGH;
        } else { //Where the square is unoccupied, print either a black or white square
          if ((column+row)%2 == 0) {
            cout<<u8"\u25A0"<<SPACINGH;
          } else {
            cout<<u8"\u25A1"<<SPACINGH;
          }
        }
      }
      //Spacing between rows:
      cout<<SPACINGV;
    }
    // Column numbers are displayed below the board
    cout<<" "<<SPACINGH<<"a"<<SPACINGH<<"b"<<SPACINGH<<"c"<<SPACINGH<<"d"<<SPACINGH<<"e"<<SPACINGH<<"f"<<SPACINGH<<"g"<<SPACINGH<<"h \n\n";

  } else { //Game board is displayed from Black's POV

    //Iterating through rows
    for (int row=0; row<8; row++){

      //Row numbering is displayed alongside the board
      cout<<row+1<<SPACINGH;

      //Iterating through columns
      for (int column=7; column>=0; column--){
        currentSquare = (column*8) + row;

        //Where the square is occupied, print that piece
        if (gameBoard->spaceOccupied(currentSquare) == 1){
          cout<<gameBoard->getPiece(currentSquare)<<SPACINGH;
        } else { //Where the square is unoccupied, print either a black or white square
          if ((column+row)%2 == 0){
            cout<<u8"\u25A0"<<SPACINGH;
          } else {
            cout<<u8"\u25A1"<<SPACINGH;
          }
        }
      }
      //Spacing between rows:
      cout<<SPACINGV;
    }
    // Column numbers are displayed below the board
    cout<<" "<<SPACINGH<<"h"<<SPACINGH<<"g"<<SPACINGH<<"f"<<SPACINGH<<"e"<<SPACINGH<<"d"<<SPACINGH<<"c"<<SPACINGH<<"b"<<SPACINGH<<"a \n\n";
  }

  drawMoves(gameBoard);

return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x64, -0x14(%rbp)
jge 0x364f
movq 0xb998(%rip), %rdi      # 0xefd0
movq 0xb981(%rip), %rsi      # 0xefc0
callq 0x2160
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x362b
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x3885
movl $0x7, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x377d
movl -0x18(%rbp), %esi
addl $0x1, %esi
movq 0xb952(%rip), %rdi      # 0xefd0
callq 0x2260
movq %rax, %rdi
leaq 0x6c31(%rip), %rsi      # 0xa2be
callq 0x2140
movl $0x0, -0x1c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jge 0x375c
movl -0x1c(%rbp), %eax
shll $0x3, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x4d70
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x36f1
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x5210
movq %rax, %rsi
movq 0xb8f5(%rip), %rdi      # 0xefd0
callq 0x2140
movq %rax, %rdi
leaq 0x6bd4(%rip), %rsi      # 0xa2be
callq 0x2140
jmp 0x374c
movl -0x1c(%rbp), %eax
addl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x3728
movq 0xb8c5(%rip), %rdi      # 0xefd0
leaq 0x6bae(%rip), %rsi      # 0xa2c0
callq 0x2140
movq %rax, %rdi
leaq 0x6b9d(%rip), %rsi      # 0xa2be
callq 0x2140
jmp 0x374a
movq 0xb8a1(%rip), %rdi      # 0xefd0
leaq 0x6b8e(%rip), %rsi      # 0xa2c4
callq 0x2140
movq %rax, %rdi
leaq 0x6b79(%rip), %rsi      # 0xa2be
callq 0x2140
jmp 0x374c
jmp 0x374e
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3699
movq 0xb86d(%rip), %rdi      # 0xefd0
leaq 0x6943(%rip), %rsi      # 0xa0ad
callq 0x2140
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3667
movq 0xb84c(%rip), %rdi      # 0xefd0
leaq 0x6b33(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6b24(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6b1f(%rip), %rsi      # 0xa2c8
callq 0x2140
movq %rax, %rdi
leaq 0x6b06(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6b03(%rip), %rsi      # 0xa2ca
callq 0x2140
movq %rax, %rdi
leaq 0x6ae8(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6ae7(%rip), %rsi      # 0xa2cc
callq 0x2140
movq %rax, %rdi
leaq 0x6aca(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6bb3(%rip), %rsi      # 0xa3b6
callq 0x2140
movq %rax, %rdi
leaq 0x6aac(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6aad(%rip), %rsi      # 0xa2ce
callq 0x2140
movq %rax, %rdi
leaq 0x6a8e(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6a91(%rip), %rsi      # 0xa2d0
callq 0x2140
movq %rax, %rdi
leaq 0x6a70(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6a75(%rip), %rsi      # 0xa2d2
callq 0x2140
movq %rax, %rdi
leaq 0x6a52(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6a59(%rip), %rsi      # 0xa2d4
callq 0x2140
jmp 0x3aa5
movl $0x0, -0x20(%rbp)
cmpl $0x8, -0x20(%rbp)
jge 0x39a2
movl -0x20(%rbp), %esi
addl $0x1, %esi
movq 0xb72d(%rip), %rdi      # 0xefd0
callq 0x2260
movq %rax, %rdi
leaq 0x6a0c(%rip), %rsi      # 0xa2be
callq 0x2140
movl $0x7, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x3981
movl -0x24(%rbp), %eax
shll $0x3, %eax
addl -0x20(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x4d70
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x3916
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x5210
movq %rax, %rsi
movq 0xb6d0(%rip), %rdi      # 0xefd0
callq 0x2140
movq %rax, %rdi
leaq 0x69af(%rip), %rsi      # 0xa2be
callq 0x2140
jmp 0x3971
movl -0x24(%rbp), %eax
addl -0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x394d
movq 0xb6a0(%rip), %rdi      # 0xefd0
leaq 0x6989(%rip), %rsi      # 0xa2c0
callq 0x2140
movq %rax, %rdi
leaq 0x6978(%rip), %rsi      # 0xa2be
callq 0x2140
jmp 0x396f
movq 0xb67c(%rip), %rdi      # 0xefd0
leaq 0x6969(%rip), %rsi      # 0xa2c4
callq 0x2140
movq %rax, %rdi
leaq 0x6954(%rip), %rsi      # 0xa2be
callq 0x2140
jmp 0x3971
jmp 0x3973
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x38be
movq 0xb648(%rip), %rdi      # 0xefd0
leaq 0x671e(%rip), %rsi      # 0xa0ad
callq 0x2140
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x388c
movq 0xb627(%rip), %rdi      # 0xefd0
leaq 0x690e(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x68ff(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x690b(%rip), %rsi      # 0xa2d9
callq 0x2140
movq %rax, %rdi
leaq 0x68e1(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x68e6(%rip), %rsi      # 0xa2d2
callq 0x2140
movq %rax, %rdi
leaq 0x68c3(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x68c6(%rip), %rsi      # 0xa2d0
callq 0x2140
movq %rax, %rdi
leaq 0x68a5(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x68a6(%rip), %rsi      # 0xa2ce
callq 0x2140
movq %rax, %rdi
leaq 0x6887(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6970(%rip), %rsi      # 0xa3b6
callq 0x2140
movq %rax, %rdi
leaq 0x6869(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6868(%rip), %rsi      # 0xa2cc
callq 0x2140
movq %rax, %rdi
leaq 0x684b(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x6848(%rip), %rsi      # 0xa2ca
callq 0x2140
movq %rax, %rdi
leaq 0x682d(%rip), %rsi      # 0xa2be
callq 0x2140
movq %rax, %rdi
leaq 0x683b(%rip), %rsi      # 0xa2db
callq 0x2140
movq -0x8(%rbp), %rdi
callq 0x34d0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)