// File: /workspace/github_cpp_makefile_star2_O3/AngelPn[P]L5R-card_game/src/GameBoard.cpp
// Function: GameBoard::gameplay()
void GameBoard::gameplay(){
	int winner= -1;

	while(1){ //Rounds until winner is found
		cout<< "\033[1;35mSTARTING PHASE\033[0m"<< endl;

		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->startingPhase();
		}

		cout<< "\033[1;35mEQUIPMENT PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->equipPhase();
		}

		cout<< "\033[1;35mBATTLE PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;

				cout << "Player: " << players[i]->name << " is playing " << endl;
				cout << "Battle Phase ..." << endl << endl;
				if (!players[i]->hasArmy()){
					cout << "No army found, phase is skipped :(" << endl << endl;
					continue;
				}

			char c;
			cout<< "Defense or Battle? [Type D/B]: ";
			cin>> c;

			if(c== 'D')
				players[i]->battlePhase(NULL);
			else{
				cout<< "\nWhich Player do you want to battle?"<< endl<< "Suggested list:"<< endl;
				for(int j=0; j< players.size(); j++){
					if(i!= j)
						cout<< j+1<< ") "<< players[j]->name<< endl;
				}
				cout<< "Type a number from suggested list: ";
				int n= 0;
				while(n< 1 || n> players.size() || n-1== i){
					cin>> n;
					cout<< endl;
				}
				players[i]->battlePhase(players[n-1]);
			}
		}
		winner= checkWinningCondition();
		if(winner!= -1){
			cout<< "PLAYER "<< players[winner]->name<< " IS THE WINNER!"<< endl;
			break;
		}

		cout<< "\033[1;35mECONOMY PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
			if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->economyPhase();
		}

		cout<< "\033[1;35mFINAL PHASE\033[0m"<< endl;
		for(int i=0; i< players.size(); i++){
				if(players[i]->give_no_provinces()== 0)
				continue;
			players[i]->endingPhase();
		}

	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xafc7(%rip), %r14      # 0x11fd0
leaq 0x5863(%rip), %rbp      # 0xc873
movq 0xafc9(%rip), %r13      # 0x11fe0
movl $0x19, %edx
movq %r14, %rdi
leaq 0x5800(%rip), %rsi      # 0xc826
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x708d
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x82aa
testl %eax, %eax
je 0x7077
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x83c2
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x705e
movl $0x1a, %edx
movq %r14, %rdi
leaq 0x57a4(%rip), %rsi      # 0xc840
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x7103
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x82aa
testl %eax, %eax
je 0x70ed
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x896c
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x70d4
movl $0x17, %edx
movq %r14, %rdi
leaq 0x5749(%rip), %rsi      # 0xc85b
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x74a5
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x82aa
testl %eax, %eax
je 0x748b
movl $0x8, %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x31a0
movq (%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0xa8(%rax), %rsi
movq 0xb0(%rax), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0xc, %edx
movq %rax, %rdi
leaq 0x56de(%rip), %rsi      # 0xc87c
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl $0x10, %edx
movq %r14, %rdi
leaq 0x56af(%rip), %rsi      # 0xc889
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x9522
testb %al, %al
je 0x7276
movl $0x1f, %edx
movq %r14, %rdi
leaq 0x566e(%rip), %rsi      # 0xc8bd
callq 0x31a0
movq %r13, %rdi
leaq 0x3(%rsp), %rsi
callq 0x31c0
cmpb $0x44, 0x3(%rsp)
jne 0x72e0
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
xorl %esi, %esi
jmp 0x7486
movl $0x22, %edx
movq %r14, %rdi
leaq 0x5615(%rip), %rsi      # 0xc89a
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
jmp 0x748b
movl $0x24, %edx
movq %r14, %rdi
leaq 0x55ee(%rip), %rsi      # 0xc8dd
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movl $0xf, %edx
movq %rax, %rdi
leaq 0x55d5(%rip), %rsi      # 0xc902
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rax, %rcx
leaq 0x4(%rsp), %r12
je 0x7401
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x73eb
leal 0x1(%rbp), %esi
movq %r14, %rdi
callq 0x3200
movq %rax, %r12
movl $0x2, %edx
movq %rax, %rdi
leaq 0x557f(%rip), %rsi      # 0xc912
callq 0x31a0
movq (%rbx), %rax
movq (%rax,%rbp,8), %rax
movq 0xa8(%rax), %rsi
movq 0xb0(%rax), %rdx
movq %r12, %rdi
callq 0x31a0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
leaq 0x4(%rsp), %r12
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
incq %rbp
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
ja 0x7371
movl $0x23, %edx
movq %r14, %rdi
leaq 0x5505(%rip), %rsi      # 0xc915
callq 0x31a0
movl $0x0, 0x4(%rsp)
xorl %eax, %eax
leaq 0x544d(%rip), %rbp      # 0xc873
testl %eax, %eax
jle 0x7446
movl %eax, %edx
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
cmpq %rdx, %rsi
jb 0x7446
decl %eax
cmpq %rax, %r15
jne 0x747e
movq %r13, %rdi
movq %r12, %rsi
callq 0x30d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl 0x4(%rsp), %eax
jmp 0x7426
movq (%rcx,%r15,8), %rdi
movq (%rcx,%rax,8), %rsi
callq 0x9550
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x714e
movq %rbx, %rdi
callq 0x6f8e
cmpl $-0x1, %eax
jne 0x75ab
movl $0x18, %edx
movq %r14, %rdi
leaq 0x5484(%rip), %rsi      # 0xc949
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x752c
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x82aa
testl %eax, %eax
je 0x7516
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0xa9ac
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x74fd
movl $0x16, %edx
movq %r14, %rdi
leaq 0x5427(%rip), %rsi      # 0xc962
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x7017
xorl %r15d, %r15d
movq (%rax,%r15,8), %rdi
callq 0x82aa
testl %eax, %eax
je 0x7590
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0xb376
incq %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x7577
jmp 0x7017
movl %eax, %r12d
movq 0xaa1b(%rip), %r14      # 0x11fd0
leaq 0x525c(%rip), %rsi      # 0xc818
movl $0x7, %edx
movq %r14, %rdi
callq 0x31a0
movslq %r12d, %rax
movq (%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq 0xa8(%rax), %rsi
movq 0xb0(%rax), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %rbx
leaq 0x5346(%rip), %rsi      # 0xc939
movl $0xf, %edx
movq %rax, %rdi
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq