// File: Thomas1995[P]Rentz/src/table.cpp
// Function: Table::PlayRound()
void Table::PlayRound() {
  std::cout << "\nStarting new round!\n\n";

  // For each of the 8 turns
  for(int roundstep = 1; roundstep <= 8; ++roundstep) {
    cardStack.clear();

    // Play the turn
    PlayTurn(firstPlayer);

    // Trigger EndTurn to all players
    for(size_t i=0;i<players.size();++i) {
      players[i].sendCards(cardStack);
      players[i].turnEnd();
    }

    // check for winner
    int winnerIndex = 0;
    Card winnerCard = cardStack[winnerIndex];

    for(size_t i=1;i<cardStack.size();++i) {
      if(winnerCard.isBeatenBy(cardStack[i])) {
        winnerCard = cardStack[i];
        winnerIndex = i;
      }
    }

    // change the first connection to go
    while(winnerIndex--) {
      ++firstPlayer;
      if(firstPlayer == players.end())
        firstPlayer = players.begin();
    }

    // change score
    ChangeScore();
  }

  std::cout << "Round over!\n\n";

  // print the final scores
  printScores();
  std::cout << "\n--------------------------\n";

  std::cout << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x115bd(%rip), %rdi     # 0x20fc8
leaq 0x6c79(%rip), %rsi      # 0x1668b
callq 0x32d0
movl $0x1, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jg 0xfbe5
movq -0x50(%rbp), %rdi
addq $0x28, %rdi
callq 0x10980
movq -0x50(%rbp), %rdi
movq 0x20(%rdi), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rsi
callq 0x10030
movq $0x0, -0x20(%rbp)
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x8, %rdi
callq 0x7d10
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0xfabb
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
movq -0x20(%rbp), %rsi
callq 0x101c0
movq -0x50(%rbp), %rsi
movq %rax, %rdi
addq $0x28, %rsi
callq 0xb4a0
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
movq -0x20(%rbp), %rsi
callq 0x101c0
movq %rax, %rdi
callq 0xb580
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xfa52
movq -0x50(%rbp), %rdi
movl $0x0, -0x24(%rbp)
addq $0x28, %rdi
movslq -0x24(%rbp), %rsi
callq 0x109a0
movq %rax, %rsi
leaq -0x2c(%rbp), %rdi
callq 0xdd80
movq $0x1, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0x28, %rdi
callq 0x8e10
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0xfb5e
movq -0x50(%rbp), %rdi
addq $0x28, %rdi
movq -0x38(%rbp), %rsi
callq 0x109a0
movq %rax, %rsi
leaq -0x2c(%rbp), %rdi
callq 0xdfb0
testb $0x1, %al
jne 0xfb2b
jmp 0xfb4e
movq -0x50(%rbp), %rdi
addq $0x28, %rdi
movq -0x38(%rbp), %rsi
callq 0x109a0
movl (%rax), %ecx
movl %ecx, -0x2c(%rbp)
movb 0x4(%rax), %al
movb %al, -0x28(%rbp)
movq -0x38(%rbp), %rax
movl %eax, -0x24(%rbp)
jmp 0xfb50
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xfae7
jmp 0xfb60
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x24(%rbp)
cmpl $0x0, %eax
je 0xfbce
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
callq 0x9870
movq -0x50(%rbp), %rdi
movq %rdi, %rax
addq $0x20, %rax
movq %rax, -0x68(%rbp)
addq $0x8, %rdi
callq 0x7fd0
movq -0x68(%rbp), %rdi
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x109c0
testb $0x1, %al
jne 0xfbac
jmp 0xfbcc
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
callq 0x5860
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0xfb60
movq -0x50(%rbp), %rdi
callq 0x5230
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xfa1e
movq 0x113dc(%rip), %rdi     # 0x20fc8
leaq 0x6aaf(%rip), %rsi      # 0x166a2
callq 0x32d0
movq -0x50(%rbp), %rdi
callq 0xfc30
movq 0x113c0(%rip), %rdi     # 0x20fc8
leaq 0x6aa1(%rip), %rsi      # 0x166b0
callq 0x32d0
movq 0x113ad(%rip), %rdi     # 0x20fc8
movq 0x11396(%rip), %rsi     # 0x20fb8
callq 0x3300
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)