// File: /workspace/github_cpp_makefile_star2_O1/Thomas1995[P]Rentz/src/table.cpp
// Function: Table::Start()
void Table::Start() {

  std::cout << "\n\nA new game has started!\n\n";

  for(size_t i = 0; i < players.size(); ++i)
    players[i].sendIndex(i);

  // choose players in play

  Card::lowestCard = 15 - players.size() * 2;

  score.resize(TABLE_SIZE, 0);

  // true if a game was already played but a certain connection, false otherwise
  std::vector<std::vector<bool>> gamesPlayed(players.size(), std::vector<bool>(gamesNumber + 1, false));

  for(size_t i=0;i<players.size();++i)
    for(int j=0;j<gamesNumber+1;++j)
      gamesPlayed[i][j] = false;

  // assign the first connection
  firstPlayer = players.begin();

  for(int gameChoice = 1; gameChoice <= gamesNumber; ++gameChoice) {

    for(size_t i=0;i<players.size();++i) {
      // set the first player
      firstPlayer = players.begin() + i;

      std::cout << "Pre-round:\n";
      std::cout << "First player is " << firstPlayer->getName() << '\n';

      // check if connection wants to play NV mode and enforce it for the last choice
      if(gameChoice < gamesNumber) {
        modeNV = players[i].getNVChoice();
      } else {
        modeNV = true;
      }

      // check if modeNV was chosed
      if(modeNV) {
        std::cout << "NV Mode chosen!\n";
      } else {
        std::cout << "NV Mode not chosen!\n";
      }

      // if NV mode not chosen, give cards before game choice
      if(modeNV == false) {
        GiveHands();
        gameType = players[i].getGameChoice();
      } else {
        gameType = players[i].getGameChoice();
        GiveHands();
      }

      // check if connection can play that game
      require(gameType >= 1 && gameType <= gamesNumber,
          players[i].getName() + " has chosen a game index out of bounds\n");

      std::cout << players[i].getName() << " chose to play: " << GameName[gameType] << '\n';

      require(gamesPlayed[i][gameType] == false,
          players[i].getName() + " had already chosen that game\n");

      gamesPlayed[i][gameType] = true;

      // let the other players know the game type
      for(auto &connection : players)
        connection.sendGameChoice(static_cast<uint8_t>(gameType));

      // start the round
      PlayRound();
    }
  }
  std::cout << "Game is over!\n";
  printScores();

  for(auto &connection: players)
    connection.gameEnd();

  GAME_END = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movq 0x8019(%rip), %rdi      # 0xdfc8
leaq 0x35ca(%rip), %rsi      # 0x9580
movl $0x1b, %edx
callq 0x2290
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rax
movabsq $-0x34307aae9fc8985d, %r12 # imm = 0xCBCF8551603767A3
subq %rdi, %rax
je 0x600c
xorl %r15d, %r15d
xorl %r14d, %r14d
addq %r15, %rdi
movq %r14, %rsi
callq 0x5174
incq %r14
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rax
subq %rdi, %rax
sarq $0x3, %rax
imulq %r12, %rax
addq $0x2058, %r15           # imm = 0x2058
cmpq %rax, %r14
jb 0x5fdd
jmp 0x6014
sarq $0x3, %rax
imulq %r12, %rax
addl %eax, %eax
movl $0xf, %ecx
subl %eax, %ecx
leaq 0x8214(%rip), %rax      # 0xe238
movl %ecx, (%rax)
leaq 0x40(%rbx), %rdi
movl 0x82d8(%rip), %esi      # 0xe308
leaq 0x8(%rsp), %rdx
movl $0x0, (%rdx)
callq 0x6e56
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %r14
leaq 0x7(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x8(%rsp), %rdi
leaq 0x37(%rsp), %rcx
movl $0x8, %esi
callq 0x6e8a
subq %r15, %r14
sarq $0x3, %r14
imulq %r12, %r14
leaq 0x80(%rsp), %rdi
leaq 0x8(%rsp), %rdx
leaq 0x36(%rsp), %rcx
movq %r14, %rsi
callq 0x6ef2
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x60b9
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
je 0x6106
sarq $0x3, %rcx
imulq %r12, %rcx
movq 0x80(%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %esi, %esi
leaq (%rsi,%rsi,4), %rdi
movq (%rdx,%rdi,8), %rdi
movq (%rdi), %r8
xorl %r9d, %r9d
btrq %r9, %r8
incq %r9
cmpq $0x8, %r9
jne 0x60ee
movq %r8, (%rdi)
incq %rsi
cmpq %rcx, %rsi
jne 0x60e0
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movq %rax, 0x20(%rbx)
leaq 0x50(%rsp), %r15
movl $0x1, 0x30(%rsp)
movq 0x7ea0(%rip), %rbp      # 0xdfc8
leaq 0x8(%rsp), %r14
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x6548
xorl %edx, %edx
movq %rdx, 0x38(%rsp)
imulq $0x2058, %rdx, %r12     # imm = 0x2058
addq %r12, %rax
movq %rax, 0x20(%rbx)
movl $0xb, %edx
movq %rbp, %rdi
leaq 0x343d(%rip), %rsi      # 0x959c
callq 0x2290
movl $0x10, %edx
movq %rbp, %rdi
leaq 0x3435(%rip), %rsi      # 0x95a8
callq 0x2290
movq 0x20(%rbx), %rsi
movq %r14, %rdi
callq 0x4e84
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbp, %rdi
callq 0x2290
movb $0xa, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
callq 0x2290
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x61c9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
cmpl $0x7, 0x30(%rsp)
jne 0x61d6
movb $0x1, 0x5c(%rbx)
jmp 0x61e5
movq 0x8(%rbx), %rdi
addq %r12, %rdi
callq 0x4ff0
movb %al, 0x5c(%rbx)
movzbl 0x5c(%rbx), %eax
testl %eax, %eax
leaq 0x33d8(%rip), %rsi      # 0x95ca
leaq 0x33c0(%rip), %rcx      # 0x95b9
cmovneq %rcx, %rsi
xorl $0x1, %eax
leaq 0x10(,%rax,4), %rdx
movq %rbp, %rdi
callq 0x2290
cmpb $0x0, 0x5c(%rbx)
je 0x6232
movq 0x8(%rbx), %rdi
addq %r12, %rdi
callq 0x4ec4
movzbl %al, %eax
movl %eax, 0x58(%rbx)
movq %rbx, %rdi
callq 0x665a
jmp 0x624c
movq %rbx, %rdi
callq 0x665a
movq 0x8(%rbx), %rdi
addq %r12, %rdi
callq 0x4ec4
movzbl %al, %eax
movl %eax, 0x58(%rbx)
movq %r13, %rbp
movq %r12, %rax
movl 0x58(%rbx), %r12d
movq 0x8(%rbx), %rsi
movq %rax, %r13
addq %rax, %rsi
movq %r14, %rdi
callq 0x4e84
movq %r14, %rdi
leaq 0x336d(%rip), %rsi      # 0x95df
callq 0x2410
movq %r15, 0x40(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x629a
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x62a1
movups (%rcx), %xmm0
movups %xmm0, (%r15)
decl %r12d
xorl %edi, %edi
cmpl $0x7, %r12d
setb %dil
movq 0x8(%rax), %rdx
movq %rdx, 0x48(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40(%rsp), %rsi
callq 0x7cfc
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x62e7
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
leaq 0x8(%rsp), %r14
movq %r13, %r12
je 0x630b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x8(%rbx), %rsi
addq %r12, %rsi
movq %r14, %rdi
callq 0x4e84
movq %rbp, %r13
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x7c9a(%rip), %rdi      # 0xdfc8
callq 0x2290
movq %rax, %r15
movl $0x10, %edx
movq %rax, %rdi
leaq 0x32c2(%rip), %rsi      # 0x9607
callq 0x2290
movslq 0x58(%rbx), %rax
movq 0x7f9b(%rip), %rcx      # 0xe2f0
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq %r15, %rdi
callq 0x2290
movb $0xa, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
callq 0x2290
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x639d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x80(%rsp), %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rcx,4), %r15
movslq 0x58(%rbx), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq (%rax,%r15,8), %rdx
leaq 0x3f(%r13), %r14
movq %rcx, %rax
andq %r14, %rax
xorl %esi, %esi
movq %r13, %rbp
cmpq %r13, %rax
setbe %sil
movl $0x1, %r13d
shlq %cl, %r13
andq -0x8(%rdx,%rsi,8), %r13
addq 0x8(%rbx), %r12
movq %r12, %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x4e84
movq %r12, %rdi
leaq 0x320d(%rip), %rsi      # 0x9618
callq 0x2410
leaq 0x70(%rsp), %r12
movq %r12, 0x60(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6438
movq %rdx, 0x60(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x70(%rsp)
jmp 0x6440
movups (%rcx), %xmm0
movups %xmm0, (%r12)
xorl %edi, %edi
testq %r13, %r13
sete %dil
movq 0x8(%rax), %rdx
movq %rdx, 0x68(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x60(%rsp), %rsi
callq 0x7cfc
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x6482
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
movabsq $-0x34307aae9fc8985d, %r12 # imm = 0xCBCF8551603767A3
movq %rbp, %r13
je 0x64ab
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x80(%rsp), %rax
movslq 0x58(%rbx), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq (%rax,%r15,8), %rdx
andq %rcx, %r14
xorl %eax, %eax
cmpq %r13, %r14
setbe %al
movl $0x1, %esi
shlq %cl, %rsi
orq %rsi, -0x8(%rdx,%rax,8)
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %r14
cmpq %r14, %r15
movq 0x7ad0(%rip), %rbp      # 0xdfc8
je 0x6512
movzbl 0x58(%rbx), %esi
movq %r15, %rdi
callq 0x4f66
addq $0x2058, %r15           # imm = 0x2058
cmpq %r14, %r15
jne 0x64fa
movq %rbx, %rdi
callq 0x67ac
leaq 0x50(%rsp), %r15
leaq 0x8(%rsp), %r14
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
cmpq %rcx, %rdx
jb 0x613d
movl 0x30(%rsp), %eax
incl %eax
movl %eax, 0x30(%rsp)
cmpl $0x8, %eax
jne 0x612d
movq 0x7a66(%rip), %rdi      # 0xdfc8
leaq 0x30ce(%rip), %rsi      # 0x9637
movl $0xe, %edx
callq 0x2290
movq %rbx, %rdi
callq 0x6962
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %r15
cmpq %r15, %r14
je 0x6599
movq %r14, %rdi
callq 0x4e08
addq $0x2058, %r14           # imm = 0x2058
jmp 0x6583
movb $0x1, (%rbx)
leaq 0x80(%rsp), %rdi
callq 0x6f8a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x6652
leaq 0x8(%rsp), %rdi
callq 0x271e
jmp 0x6652
movq %rax, %rbx
jmp 0x6652
jmp 0x6642
jmp 0x6642
jmp 0x6642
jmp 0x661f
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x6622
movq 0x70(%rsp), %rsi
jmp 0x660f
jmp 0x6642
jmp 0x6642
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x6622
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x6622
jmp 0x661f
jmp 0x6642
jmp 0x661f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6645
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x6645
jmp 0x6642
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x6f8a
movq %rbx, %rdi
callq 0x23c0