// File: IncredibleHannes[P]QMUL-ChessGame/src/Model/Board.cpp
// Function: Board::applyPromotion(Move*, Chessman::FigureType)
void Board::applyPromotion(Move *move, Chessman::FigureType type) {
    Chessman *currentChessman = getChessman(move->getTarget());
    move->addType(Move::Promotion);
    int x = move->getTarget().getX();
    int y = move->getTarget().getY();
    switch(type) {
      case Chessman::Queen :
        board[x][y] = new Queen(currentChessman->getColour(), Position(x,y));
        break;
      case Chessman::Rook :
        board[x][y] = new Rook(currentChessman->getColour(), Position(x,y));
        break;
      case Chessman::Bishop :
        board[x][y] = new Bishop(currentChessman->getColour(), Position(x,y));
        break;
      case Chessman::Knight :
        board[x][y] = new Knight(currentChessman->getColour(), Position(x,y));
        break;
      default:
        break;
    }
    Move *m = previousMoves.back();
    previousMoves.pop_back();
    delete m;
    previousMoves.push_back(new Move(*move));
    capturedChessmen.push_back(currentChessman);
    delete move;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6a30
movq -0x90(%rbp), %rdi
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rsi
callq 0x7de0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x6a50
movq -0x10(%rbp), %rdi
callq 0x6a30
movq %rax, -0x34(%rbp)
leaq -0x34(%rbp), %rdi
callq 0x2ee0
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6a30
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2ef0
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x88(%rbp)
subl $0x4, %eax
ja 0x8c2d
movq -0x88(%rbp), %rax
leaq 0x3689(%rip), %rcx      # 0xc060
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x18, %edi
callq 0x2160
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5790
movb %al, -0x91(%rbp)
jmp 0x8a02
movl -0x2c(%rbp), %esi
movl -0x38(%rbp), %edx
leaq -0x54(%rbp), %rdi
callq 0x2e50
jmp 0x8a13
movq -0xa0(%rbp), %rdi
movb -0x91(%rbp), %al
movq -0x54(%rbp), %rdx
movzbl %al, %esi
andl $0x1, %esi
callq 0x6560
jmp 0x8a31
movq -0xa0(%rbp), %rdx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x8c2f
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2140
jmp 0x8d2c
movl $0x18, %edi
callq 0x2160
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5790
movb %al, -0xa1(%rbp)
jmp 0x8a96
movl -0x2c(%rbp), %esi
movl -0x38(%rbp), %edx
leaq -0x5c(%rbp), %rdi
callq 0x2e50
jmp 0x8aa7
movq -0xb0(%rbp), %rdi
movb -0xa1(%rbp), %al
movq -0x5c(%rbp), %rdx
movzbl %al, %esi
andl $0x1, %esi
callq 0x54b0
jmp 0x8ac5
movq -0xb0(%rbp), %rdx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x8c2f
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2140
jmp 0x8d2c
movl $0x18, %edi
callq 0x2160
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5790
movb %al, -0xb1(%rbp)
jmp 0x8b2a
movl -0x2c(%rbp), %esi
movl -0x38(%rbp), %edx
leaq -0x64(%rbp), %rdi
callq 0x2e50
jmp 0x8b3b
movq -0xc0(%rbp), %rdi
movb -0xb1(%rbp), %al
movq -0x64(%rbp), %rdx
movzbl %al, %esi
andl $0x1, %esi
callq 0x2fd0
jmp 0x8b59
movq -0xc0(%rbp), %rdx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x8c2f
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2140
jmp 0x8d2c
movl $0x18, %edi
callq 0x2160
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5790
movb %al, -0xc1(%rbp)
jmp 0x8bbe
movl -0x2c(%rbp), %esi
movl -0x38(%rbp), %edx
leaq -0x6c(%rbp), %rdi
callq 0x2e50
jmp 0x8bcf
movq -0xd0(%rbp), %rdi
movb -0xc1(%rbp), %al
movq -0x6c(%rbp), %rdx
movzbl %al, %esi
andl $0x1, %esi
callq 0x36a0
jmp 0x8bed
movq -0xd0(%rbp), %rdx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x8c2f
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2140
jmp 0x8d2c
jmp 0x8c2f
movq -0x90(%rbp), %rdi
addq $0x28, %rdi
callq 0x97a0
movq -0x90(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x78(%rbp)
addq $0x28, %rdi
callq 0x9820
movq -0x78(%rbp), %rax
movq %rax, -0xd8(%rbp)
cmpq $0x0, %rax
je 0x8c7f
movq -0xd8(%rbp), %rdi
callq 0x69d0
movq -0xd8(%rbp), %rdi
callq 0x2140
movq -0x90(%rbp), %rax
addq $0x28, %rax
movq %rax, -0xe8(%rbp)
movl $0x20, %edi
callq 0x2160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rsi
callq 0x6930
jmp 0x8cb3
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x9400
movq -0x90(%rbp), %rdi
addq $0x10, %rdi
leaq -0x20(%rbp), %rsi
callq 0x97e0
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, %rax
je 0x8d0b
movq -0xf0(%rbp), %rdi
callq 0x69d0
movq -0xf0(%rbp), %rdi
callq 0x2140
addq $0xf0, %rsp
popq %rbp
retq
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2140
movq -0x48(%rbp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)